def create(context, conf, **kwargs): conf.register_opts(freezer_client_opts, group=CONFIG_GROUP) client_config = conf[CONFIG_GROUP] url = utils.get_url(SERVICE, context, client_config, append_project_fmt='%(url)s/%(project)s', **kwargs) if kwargs.get('session'): return freezer_client.Client(version=FREEZERCLIENT_VERSION, session=kwargs.get('session'), endpoint=url) args = { 'project_id': context.project_id, 'project_name': context.project_name, 'cacert': client_config.freezer_ca_cert_file, 'insecure': client_config.freezer_auth_insecure, 'endpoint': url, 'token': context.auth_token, 'version': FREEZERCLIENT_VERSION, 'auth_url': client_config.auth_uri } return freezer_client.Client(**args)
def test_client_new_with_kwargs_token(self, mock_ks_loader, mock_ks_session): session = mock_ks_session.return_value.load_from_options.return_value mock_ks_loader.return_value.load_from_options.return_value = 'auth' kwargs = { 'auth_url': 'one', 'project_id': 'two', 'tenant_name': 'three', 'project_name': 'four', 'user_domain_id': 'five', 'user_domain_name': 'six', 'project_domain_id': 'senven', 'project_domain_name': 'eight', 'token': 'nine' } c = client.Client(**kwargs) self.assertIsInstance(c, client.Client) self.assertEqual('one', c.opts.os_auth_url) self.assertEqual('two', c.opts.os_project_id) self.assertEqual('three', c.opts.os_tenant_name) self.assertEqual('four', c.opts.os_project_name) self.assertEqual('five', c.opts.os_user_domain_id) self.assertEqual('six', c.opts.os_user_domain_name) self.assertEqual('senven', c.opts.os_project_domain_id) self.assertEqual('eight', c.opts.os_project_domain_name) self.assertEqual('nine', c.opts.os_token) self.assertEqual(session, c.session)
def client(request): """Return a freezer client object""" api_url = _get_service_url(request) # get keystone version to connect to ks_version = getattr(settings, 'OPENSTACK_API_VERSIONS', {}).get('identity', 2.0) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) credentials = { 'token': request.user.token.id, 'auth_url': getattr(settings, 'OPENSTACK_KEYSTONE_URL'), 'endpoint': api_url, 'version': ks_version, 'cert': cacert } if ks_version == 3: credentials['project_name'] = request.user.project_name credentials['project_id'] = request.user.project_id credentials['project_domain_name'] = \ request.user.domain_name or 'Default' return freezer_client.Client(**credentials)
def main(): possible_actions = ['start', 'stop', 'status', 'reload'] arguments.parse_args(possible_actions) arguments.setup_logging() if CONF.action is None or CONF.action not in possible_actions: CONF.print_help() return 65 # os.EX_DATAERR apiclient = None if CONF.no_api is False: try: apiclient = client.Client(opts=CONF) if CONF.client_id: apiclient.client_id = CONF.client_id except Exception as e: LOG.error(e) print(e) sys.exit(1) else: if winutils.is_windows(): print("--no-api mode is not available on windows") return 69 # os.EX_UNAVAILABLE freezer_utils.create_dir(CONF.jobs_dir, do_log=False) freezer_scheduler = FreezerScheduler(apiclient=apiclient, interval=int(CONF.interval), job_path=CONF.jobs_dir, concurrent_jobs=CONF.concurrent_jobs) if CONF.no_daemon: print('Freezer Scheduler running in no-daemon mode') LOG.debug('Freezer Scheduler running in no-daemon mode') if winutils.is_windows(): daemon = win_daemon.NoDaemon(daemonizable=freezer_scheduler) else: daemon = linux_daemon.NoDaemon(daemonizable=freezer_scheduler) else: if winutils.is_windows(): daemon = win_daemon.Daemon(daemonizable=freezer_scheduler, interval=int(CONF.interval), job_path=CONF.jobs_dir, insecure=CONF.insecure, concurrent_jobs=CONF.concurrent_jobs) else: daemon = linux_daemon.Daemon(daemonizable=freezer_scheduler) if CONF.action == 'start': daemon.start() elif CONF.action == 'stop': daemon.stop() elif CONF.action == 'reload': daemon.reload() elif CONF.action == 'status': daemon.status() # os.RETURN_CODES are only available to posix like systems, on windows # we need to translate the code to an actual number which is the equivalent return 0 # os.EX_OK
def test_get_token(self, mock_get_auth_plugin, mock_ksa_session): mock_session = mock.Mock() mock_session.get_token.return_value = 'antaniX2' c = client.Client(session=mock_session, endpoint='justtest', auth_url='blabla') self.assertIsInstance(c, client.Client) self.assertEqual(c.auth_token, 'antaniX2')
def test_get_token(self, mock_ks_loader, mock_ks_session): mock_ks_loader.return_value.load_from_options.return_value = 'auth' mock_session = mock.Mock() mock_session.get_token.return_value = 'antaniX2' c = client.Client(session=mock_session, endpoint='justtest', auth_url='blabla') self.assertIsInstance(c, client.Client) self.assertEqual(c.auth_token, 'antaniX2')
def test_get_client_id(self, mock_ks_loader, mock_ks_session, mock_socket): mock_ks_loader.return_value.load_from_options.return_value = 'auth' mock_socket.gethostname.return_value = 'parmenide' mock_session = mock.Mock() mock_session.get_project_id.return_value = 'H2O' c = client.Client(session=mock_session, endpoint='justtest', auth_url='blabla') self.assertIsInstance(c, client.Client) self.assertEqual(c.client_id, 'H2O_parmenide')
def test_client_new_with_kwargs_session(self, mock_ks_loader, mock_ks_session): mock_ks_loader.return_value.load_from_options.return_value = 'auth' mock_session = mock.Mock() kwargs = {'token': 'alpha', 'username': '******', 'password': '******', 'project_name': 'delta', 'auth_url': 'echo', 'endpoint': 'golf', 'session': mock_session} c = client.Client(**kwargs) self.assertIsInstance(c, client.Client) self.assertEqual('alpha', c.opts.os_token) self.assertEqual('bravo', c.opts.os_username) self.assertEqual('charlie', c.opts.os_password) self.assertEqual('delta', c.opts.os_project_name) self.assertEqual('echo', c.opts.os_auth_url) self.assertEqual(mock_session, c._session) self.assertEqual(mock_session, c.session) self.assertEqual('golf', c.endpoint)
def test_client_new_with_kwargs(self, mock_get_auth_plugin, mock_ksa_session): kwargs = { 'token': 'alpha', 'username': '******', 'password': '******', 'tenant_name': 'delta', 'auth_url': 'echo', 'session': 'foxtrot', 'endpoint': 'golf', 'version': 'hotel' } c = client.Client(**kwargs) self.assertIsInstance(c, client.Client) self.assertEqual('alpha', c.opts.os_token) self.assertEqual('bravo', c.opts.os_username) self.assertEqual('charlie', c.opts.os_password) self.assertEqual('delta', c.opts.os_tenant_name) self.assertEqual('echo', c.opts.os_auth_url) self.assertEqual('foxtrot', c._session) self.assertEqual('foxtrot', c.session) self.assertEqual('golf', c.endpoint)
def client(self): """Build a client object to communicate with the API :return: freezerclient object """ opts = { 'token': self.options.os_token, 'version': self.options.os_identity_api_version, 'username': self.options.os_username, 'password': self.options.os_password, 'tenant_name': self.options.os_tenant_name, 'auth_url': self.options.os_auth_url, 'endpoint': self.options.os_backup_url, 'endpoint_type': self.options.os_endpoint_type, 'project_name': self.options.os_project_name, 'user_domain_name': self.options.os_user_domain_name, 'user_domain_id': self.options.os_user_domain_id, 'project_domain_name': self.options.os_project_domain_name, 'project_domain_id': self.options.os_project_domain_id, 'cert': self.options.os_cert, 'cacert': self.options.os_cacert, 'insecure': self.options.insecure } return client.Client(**opts)
def test_client_new(self, mock_ks_loader, mock_ks_session): session = mock_ks_session.return_value.load_from_options.return_value mock_ks_loader.return_value.load_from_options.return_value = 'auth' c = client.Client(endpoint='blabla', auth_url='blabla') self.assertIsInstance(c, client.Client) self.assertEqual(session, c.session)
""" from freezerclient.v1 import client from keystoneauth1 import loading,session from novaclient import client as nvclient import paramiko import json import time import MySQLdb keystone_url_180_11="http://10.121.137.50:5000/v2.0" keystone_url_180_12="http://10.121.137.80:5000/v2.0" keystone_url_136_132="https://10.121.136.132:5000/v2.0" loader=loading.get_plugin_loader('password') auth=loader.load_from_options(auth_url=keystone_url_180_12,username="******",password="******",project_name="admin") sess=session.Session(auth=auth) # print sess.auth freezer=client.Client(version="2.0",session=sess,endpoint_type="public") # print freezer.endpoint # print self.check_job("bf805cdd08f3449997e37a12bfcfc6af") # search={'match': [{u'description': u'ft-config-backup-222'},{ u'job_id': u'3c5092a6520e4fbd9cebc3fec04e978f'}]} # print freezer.jobs.list(search=search,client_id="node-8") # print freezer.jobs.get(job_id="3c5092a6520e4fbd9cebc3fec04e978f")[u'job_schedule'][u'result'] def create_job(): f=open("/home/mengph/rearch/test.json") file=json.load(f) # print file return freezer.jobs.create(doc=file) def start_job(job_id): freezer.jobs.start_job(job_id) def check_job(job_id):
def test_client_new(self, mock_get_auth_plugin, mock_ksa_session): c = client.Client(endpoint='blabla', auth_url='blabla') self.assertIsInstance(c, client.Client)