def create_nova_volume_client(context): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this PROXY_ADMIN_USER = CONFIG.get('reddwarf_proxy_admin_user', 'admin') PROXY_ADMIN_PASS = CONFIG.get('reddwarf_proxy_admin_pass', '3de4922d8b6ac5a1aad9') PROXY_ADMIN_TENANT_NAME = CONFIG.get('reddwarf_proxy_admin_tenant_name', 'admin') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') REGION_NAME = CONFIG.get('nova_region_name', 'RegionOne') SERVICE_TYPE = CONFIG.get('nova_volume_service_type', 'volume') SERVICE_NAME = CONFIG.get('nova_volume_service_name', 'Volume Service') #TODO(cp16net) need to fix this proxy_tenant_id client = Client(PROXY_ADMIN_USER, PROXY_ADMIN_PASS, PROXY_ADMIN_TENANT_NAME, PROXY_AUTH_URL, proxy_tenant_id=context.tenant, proxy_token=context.auth_tok, region_name=REGION_NAME, service_type=SERVICE_TYPE, service_name=SERVICE_NAME) client.authenticate() return client
def get_client(cls, credential, region=None): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this #PROXY_ADMIN_USER = CONFIG.get('reddwarf_proxy_admin_user', 'admin') #PROXY_ADMIN_PASS = CONFIG.get('reddwarf_proxy_admin_pass', # '3de4922d8b6ac5a1aad9') #PROXY_ADMIN_TENANT_NAME = CONFIG.get( # 'reddwarf_proxy_admin_tenant_name', # 'admin') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') # PROXY_AUTH_URL = 'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/' if region is None: region = 'az-2.region-a.geo-1' try: client = Client(credential['user_name'], credential['password'], credential['tenant_id'], PROXY_AUTH_URL, #proxy_tenant_id=context.tenant, #proxy_token=context.auth_tok, region_name=region, #service_type='compute', service_name="Compute") client.authenticate() except Exception: LOG.exception("Error authenticating with Novaclient") return client
def create_nova_client(user, service_type="nova_service_type"): """Creates a rich client for the Nova API using the test config.""" test_config.nova.ensure_started() openstack = Client(user.auth_user, user.auth_key, user.tenant, test_config.nova_auth_url, service_type=test_config.values[service_type]) openstack.authenticate() return TestClient(openstack)
def create_nova_client(user, service_type=None): """Creates a rich client for the Nova API using the test config.""" if test_config.nova_client is None: raise SkipTest("No nova_client info specified in the Test Config " "so this test will be skipped.") from novaclient.v1_1.client import Client if not service_type: service_type = test_config.nova_client['nova_service_type'] openstack = Client(user.auth_user, user.auth_key, user.tenant, test_config.nova_client['auth_url'], service_type=service_type, no_cache=True) openstack.authenticate() return TestClient(openstack)
def nova_client(context): client = Client(context.user, context.auth_token, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_token client.client.management_url = "%s/%s/" % (COMPUTE_URL, context.tenant) return client
def create_cinder_client(config): from cinderclient.client import Client return Client(1, username=config.os_username, api_key=config.os_password, project_id=config.os_tenant_name, auth_url=config.os_auth_url, region_name=config.os_region_name)
def get_admin_credentials(): keystone = {} keystone['os_username']=env['OS_USERNAME'] keystone['os_password']=env['OS_PASSWORD'] keystone['os_auth_url']=env['OS_AUTH_URL'] keystone['os_tenant_name']=env['OS_TENANT_NAME'] return Client(**keystone)
def get_client(): args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL] kwargs = {} kwargs['region_name'] = NOVA_REGION_NAME kwargs['service_type'] = 'compute' from novaclient.v1_1.client import Client client = Client(*args, **kwargs) return client
def create_nova_volume_client(context): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this client = Client(context.user, context.auth_token, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_token client.client.management_url = "%s/%s/" % (VOLUME_URL, context.tenant) return client
def create_nova_client(context): COMPUTE_URL = CONFIG.get('nova_compute_url', 'http://localhost:8774/v2') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') client = Client(context.user, context.auth_tok, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_tok client.client.management_url = "%s/%s/" % (COMPUTE_URL, context.tenant) return client
def get_client(cls, context): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this PROXY_ADMIN_USER = CONFIG.get('reddwarf_proxy_admin_user', 'admin') PROXY_ADMIN_PASS = CONFIG.get('reddwarf_proxy_admin_pass', '3de4922d8b6ac5a1aad9') PROXY_ADMIN_TENANT_NAME = CONFIG.get( 'reddwarf_proxy_admin_tenant_name', 'admin') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') client = Client(PROXY_ADMIN_USER, PROXY_ADMIN_PASS, PROXY_ADMIN_TENANT_NAME, PROXY_AUTH_URL, proxy_tenant_id=context.tenant, proxy_token=context.auth_tok, region_name='RegionOne', service_type='compute', service_name="'Compute Service'") client.authenticate() return client
def create_nova_volume_client(context): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this VOLUME_URL = CONFIG.get('nova_volume_url', 'http://localhost:8776/v2') PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0') client = Client(context.user, context.auth_tok, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_tok client.client.management_url = "%s/%s/" % (VOLUME_URL, context.tenant) return client
def get_client(): args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL] kwargs = {} kwargs['region_name'] = NOVA_REGION_NAME kwargs['service_type'] = 'compute' kwargs['service_name'] = NOVA_SERVICE_NAME if NOVACLIENT_INSECURE: kwargs['insecure'] = True from novaclient.v1_1.client import Client client = Client(*args, **kwargs) return client
def __init__(self): ''' Get nova client object by admin user. ''' try: self.nova_client = Client(FLAGS.novaclient_username, FLAGS.novaclient_password, FLAGS.novaclient_projectName, FLAGS.novaclient_keystoneUrl, service_type='compute') except Exception: LOG.exception( _("Error during get nova client exception. Maybe " "cause of error auth for keystone")) self.nova_client = None
def nova_client(context): if CONF.nova_compute_url: url = '%(nova_url)s%(tenant)s' % { 'nova_url': normalize_url(CONF.nova_compute_url), 'tenant': context.tenant} else: url = get_endpoint(context.service_catalog, service_type=CONF.nova_compute_service_type, endpoint_region=CONF.os_region_name, endpoint_type=CONF.nova_compute_endpoint_type) client = Client(context.user, context.auth_token, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_token client.client.management_url = url return client
def __init__(self, tenant=default_tenant): body = { "auth": { "passwordCredentials": { "username": osuser, "password": ospassword } } } body['auth']['tenantName'] = tenant body = json.dumps(body) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'client' } http = httplib2.Http() resp, body = http.request(token_uri, method="POST", body=body, headers=headers) if not resp.status == 200: print "Error status: %d" % resp.status sys.exit(1) data = json.loads(body) self.apitoken = data['access']['token']['id'] self.volumeurl = data['access']['serviceCatalog'][0]['endpoints'][0][ 'publicURL'] self.apiurl = data['access']['serviceCatalog'][2]['endpoints'][0][ 'publicURL'] self.tenant_id = data['access']['token']['tenant']['id'] self.headers = { 'X-Auth-Project-Id': tenant, 'User-Agent': 'python-novaclient', 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-Auth-Token': self.apitoken } self.key_uri = key_uri self.host_map = {} self.img_dict = {} self.ins_list = [] self.flavor_ls = [] self.host_len = wic_utils.get_hostmap(self.host_map) self.client = Client(osuser, ospassword, default_tenant, auth_uri)
def create_nova_client(config): '''Creates a nova Client from the environment variables.''' from novaclient import shell extensions = shell.OpenStackComputeShell()._discover_extensions("1.1") if not set([ 'gridcentric', 'cobalt', 'gridcentric_python_novaclient_ext', 'cobalt_python_novaclient_ext' ]) & set([e.name for e in extensions]): raise Exception("You don\'t have the gridcentric extension installed." \ "Try 'pip install gridcentric-python-novaclient-ext'.") from novaclient.v1_1.client import Client return Client(extensions=extensions, username=config.os_username, api_key=config.os_password, project_id=config.os_tenant_name, auth_url=config.os_auth_url, region_name=config.os_region_name, no_cache=os.environ.get('OS_NO_CACHE', 0) and True, http_log_debug=config.http_log_debug)
def get_client(self, req): proxy_token = req.headers["X-Auth-Token"] client = Client(self.proxy_admin_user, self.proxy_admin_pass, self.proxy_admin_tenant_name, self.auth_url, token=proxy_token) client.authenticate() return client
def network_name_to_id(network_name, username, password, tenant_name, auth_url): nt = Client(username, password, tenant_name, auth_url) return nt.networks.find(label=network_name).id
def flavor_name_to_id(flavor_name, username, password, tenant_name, auth_url): nt = Client(username, password, tenant_name, auth_url) return nt.flavors.find(name=flavor_name).id
def image_name_to_id(image_name, username, password, tenant_name, auth_url): nt = Client(username, password, tenant_name, auth_url) return nt.images.find(name=image_name).id
from novaclient.v1_1.client import Client c = Client(username='******', api_key = 'ENTER_KEY', project_id='ENTER_PROJECT_ID', auth_url='ENTER_AUTH_URL', region_name='ENTER_REGION_NAME', http_log_debug=True) clean_servers = [ 'webserver-host', 'postgres-host' ] for server in c.servers.list(): if server.name in clean_servers: print 'removing', server server.delete()
def get_client(conf): return Client(username=conf["OS_USERNAME"], api_key=conf["OS_PASSWORD"], project_id=conf["OS_TENANT_NAME"], auth_url=conf["OS_AUTH_URL"], insecure=True)
def __init__(self, prefix, num_workers, atomic, parallel, chef_repo, chef_repo_branch, sdn, ssh_keyfile, pool, user, image, chefserver_image, flavor, gateway_flavor, key_name, security_groups, src_dir, dst_dir, userdata, timeout, poll_interval): """ For doc on each param refer to orchestrator_opts """ ## check args if CONCAT_CHAR in prefix: raise ValueError('"%s" cannot exist in prefix=%r' % (CONCAT_CHAR, prefix)) ## args self.prefix = prefix self.num_workers = num_workers self.atomic = atomic self.parallel = parallel self.chef_repo = chef_repo self.chef_repo_branch = chef_repo_branch self.sdn = sdn self.ssh_keyfile = ssh_keyfile self.pool = pool self.user = user self.image = image self.chefserver_image = chefserver_image self.flavor = flavor self.gateway_flavor = gateway_flavor self.key_name = key_name self.security_groups = security_groups self.src_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), src_dir) self.dst_dir = os.path.abspath(dst_dir) with open(os.path.join(self.src_dir, userdata), 'r') as fin: self.userdata = fin.read() self.timeout = timeout self.poll_interval = poll_interval # Inject the extra ssh public key if any ssh_keycontent = '' if self.ssh_keyfile: with open(self.ssh_keyfile, 'r') as fin: ssh_keycontent = fin.read() self.userdata = self.userdata % (user, ssh_keycontent) # scripts to run on chefserver, execute one by one (sequence matters) self.chefserver_commands = [] self.chefserver_files = OrderedDict() for filename in ('install_chefserver.sh', 'configure_knife.sh', 'setup_chef_repo.sh'): src_file = os.path.join(self.src_dir, filename) dst_file = os.path.join(self.dst_dir, filename) if filename == 'setup_chef_repo.sh': # add two args to this command command = ("/bin/bash" + " " + dst_file + " " + self.chef_repo + " " + self.chef_repo_branch) else: command = "/bin/bash" + " " + dst_file self.chefserver_commands.append(command) with open(src_file, 'r') as fin: value = fin.read() key = dst_file self.chefserver_files[key] = value ## non-args self.client = Client(os.environ['OS_USERNAME'], os.environ['OS_PASSWORD'], os.environ['OS_TENANT_NAME'], os.environ['OS_AUTH_URL']) # If the password offered is actually a 32 byte hex digit string # then it's probably a token if re.match('\A[\da-fA-F]{32}\Z', os.environ['OS_PASSWORD']): self.client.client.auth_token = os.environ['OS_PASSWORD'] self._gateway_id = None self._gateway_ip = None self._gateway_name = None self._chefserver_id = None self._chefserver_ip = None self._chefserver_name = None self._controller_id = None self._controller_ip = None self._controller_name = None self._worker_ids = [] self._worker_ips = [] self._worker_names = [] self._gateway_floating_ip = None
def nova_client(context): client = Client(USER, PASSWORD, project_id=PROJECT, auth_url=ID_URL) return client