def set_heat_clients(cls): super().set_keystone_clients() cls.undercloud_heatclient = Client( '1', session=cls.undercloud_keystone_session) cls.overcloud_heatclient = Client( '1', session=cls.overcloud_keystone_session)
def __init__(self, hot_url, auth_token, tenant_id): self._hot_url = hot_url self._auth_token = auth_token self._tenant_id = tenant_id self._heat_client = Client('1', endpoint=self._hot_url, token=self._auth_token)
def main(): #Get credentials. kwargs = {'username':os.environ['OS_USERNAME'], 'password': os.environ['OS_PASSWORD'], 'tenant_name': os.environ['OS_TENANT_NAME'], 'auth_url': os.environ['OS_AUTH_URL']} conn = swiftclient.Connection( authurl=os.environ['OS_AUTH_URL'], user=os.environ['OS_USERNAME'], key=os.environ['OS_PASSWORD'], tenant_name=os.environ['OS_TENANT_NAME'], auth_version='2' ) # Parse Arg: stack_name = 'overcloud' # Undercloud upgrade # use cli ? identity_cli = IdentityClient('orchestration', **kwargs) heat = Client('1', endpoint=identity_cli.endpoint, token=identity_cli.token) stack = heat.stacks.get(stack_name) client = nova_client.client.Client(api_version='2', username=kwargs.get('username'), password=kwargs.get('password'), project_name=kwargs.get('tenant_name'), auth_url=kwargs.get('auth_url')) client.authenticate() for s in client.servers.list(): pdb.set_trace()
def _get_heat_client(module, kwargs): _ksclient = _get_ksclient(module, kwargs) token = _ksclient.auth_token endpoint = _get_endpoint(module, _ksclient) try: heat = Client('1', endpoint=endpoint, token=token) except Exception, e: module.fail_json(msg=" Error in connecting to heat: %s" % e.message)
def get_heat(heat_url): try: auth_token = keystone.auth_token heat_client = Client('1', endpoint=heat_url, token=auth_token) except ValueError: print "Error in connecting to heat" global heat heat = heat_client return heat_client
def __init__(self): conf = config() OS_credential = conf.OS_credential k_client = Keystoneclient(**OS_credential) self.endpoint = k_client.get_endpoint("orchestration").publicurl self.client = Client("1", endpoint=self.endpoint, token=k_client.token, ca_file=OS_CACERT)
def _get_client(self, kwargs, endpoint_type='publicURL'): """ get heat client """ kclient = ksclient.Client(**kwargs) token = kclient.auth_token endpoint = kclient.service_catalog.url_for( service_type='orchestration', endpoint_type=endpoint_type) kwargs = { 'token': token, } return Client('1', endpoint=endpoint, token=token)
def autheticate(cip, username, password, tenant): auth_url = 'http://' + str(cip) + ':5000/v2.0' keystone = client.Client(username=username, password=password, tenant_name=tenant, auth_url=auth_url) auth_token = keystone.auth_ref['token']['id'] tenant_id = keystone.tenant_id heat_url = 'http://' + str(cip) + ':8004/v1/%s' % tenant_id heat = Client('1', endpoint=heat_url, token=auth_token) return heat
def heat_client(os_creds, session=None): """ Retrieves the Heat client :param os_creds: the OpenStack credentials :return: the client """ logger.debug('Retrieving Heat Client') if not session: session = keystone_utils.keystone_session(os_creds) return Client(os_creds.heat_api_version, session=session, region_name=os_creds.region_name)
def autheticate(cip, username, password, tenant): #function used to autheticate with keystone #print "authenticating with user "+str(username)+" tenant "+str(tenant)+" and pass "+str(password) auth_url = 'http://' + str(cip) + ':5000/v2.0' keystone = client.Client(username=username, password=password, tenant_name=tenant, auth_url=auth_url) auth_token = keystone.auth_ref['token']['id'] tenant_id = keystone.tenant_id heat_url = 'http://' + str(cip) + ':8004/v1/%s' % tenant_id heat = Client('1', endpoint=heat_url, token=auth_token) return heat
def get_health(time_elapsed, parameter=""): try: _stack = _heat.stacks.get(STACK_ID) except: auth_token = kc.auth_token ceilometer = c_client.Client(endpoint=CEILOMETER_ENDPOINT, token= lambda : auth_token ) _heat = Client('1', endpoint=heat_url, token=auth_token) _stack = _heat.stacks.get(STACK_ID) query = [dict(field='metadata.user_metadata.stack', op='eq', value=_stack.id)] result = ceilometer.statistics.list('cpu_util', q=query, period=100) if len(result) > 0: print 'PEGOU RESULTADO, AMIGO' print result[-1].avg return result[-1].avg
def execute(self): if self.args['ls']: if not login_lib.check_env(): print('you are not authorized.') else: login_lib.load_env_file() heat_url = 'https://heat.wjv-1.neo.id:8004/v1/%s' % os.environ.get( "OS_PROJECT_ID") heat = Client('1', endpoint=heat_url, token=os.environ.get("OS_TOKEN")) instances = [instance for instance in heat.stacks.list()] for instance in instances: print(" -> ({}) {}".format(instance.id, instance.name)) print(instance.to_dict()) if len(instances) == 0: print("There is no virtual machine;") if self.args['rm']: if not login_lib.check_env(): print('you are not authorized.') else: try: if self.args['<id_instance>'] == '-h': subprocess.check_output(['neo vm', '--help']) else: login_lib.load_env_file() heat_url = 'https://heat.wjv-1.neo.id:8004/v1/%s' % os.environ.get( "OS_PROJECT_ID") heat = Client('1', endpoint=heat_url, token=os.environ.get("OS_TOKEN")) stack_id = self.args['<id_instance>'] heat.stacks.delete(stack_id) except Exception as e: print(e) else: pass finally: pass
def create_client(): auth=v2.Password( auth_url=cfgutils.getval('heat','auth_url'), username=cfgutils.getval('heat','username'), password=cfgutils.getval('heat','password'), tenant_name=cfgutils.getval('heat','tenant_name') ) sess=session.Session(auth=auth) return Client( '1', endpoint=cfgutils.getval('heat','end_point')+'/'+sess.get_project_id(), token=sess.get_token() )
def get_heat(self): """ get_heat - return an instance of the heat client @requires - credentials.py @params: none @returns: instance of the heatclient.client.Client """ kscreds = get_keystone_creds() ks = ksclient(**kscreds) heat_url = ks.service_catalog.url_for(service_type='orchestration', endpoint_type='publicURL') auth_token = ks.auth_token heat = Client('1', endpoint=heat_url, token=auth_token) return heat
def main(): logging.basicConfig() LOG.setLevel(logging.INFO) args = parse_args() sudo_user = os.environ.get('SUDO_USER') if not args.working_dir: if sudo_user: user_home = '~{}'.format(sudo_user) else: user_home = '~' working_dir = os.path.join(os.path.expanduser(user_home), 'overcloud-deploy') else: working_dir = args.working_dir if not os.path.isdir(working_dir): os.makedirs(working_dir) try: conn = openstack.connection.from_config(cloud=args.cloud) heat = conn.orchestration _heatclient = Client('1', endpoint=conn.endpoint_for('orchestration'), token=conn.auth_token) except keystoneauth1.exceptions.catalog.EndpointNotFound: LOG.error("No Heat endpoint found, won't migrate any " "existing stack data.") raise try: stacks = args.stack or [s.name for s in heat.stacks()] except openstack.exceptions.HttpException: LOG.warning("No connection to Heat available, won't migrate any " "existing stack data.") stacks = [] # Make stack directories in the working directory if they don't not exist _make_stack_dirs(stacks, working_dir) for stack in stacks: stack_dir = os.path.join(working_dir, stack) export_networks(stack, stack_dir, args.cloud) export_network_virtual_ips(stack, stack_dir, args.cloud) export_provisioned_nodes(heat, stack, stack_dir, args.cloud) if database_exists(): backup_dir = os.path.join(working_dir, 'undercloud-upgrade-ephemeral-heat') db_tar_path = backup_db(backup_dir) else: LOG.warning("No database found to backup.") db_tar_path = None for stack in stacks: stack_dir = os.path.join(working_dir, stack) if db_tar_path: # Symlink to the existing db backup os.symlink(db_tar_path, os.path.join(stack_dir, os.path.basename(db_tar_path))) export_passwords(_heatclient, stack, stack_dir) if database_exists(): drop_db() # Chown all files to original user if running under sudo if sudo_user: subprocess.run( ['chown', '-R', '{}:{}'.format(sudo_user, sudo_user), working_dir], check=True)
tenant_id = '' heat_url = 'http://controller:8004/v1/%s' % tenant_id import ceilometerclient.v2 as c_client auth_token = kc.auth_token ceilometer = c_client.Client(endpoint=CEILOMETER_ENDPOINT, token= lambda : auth_token ) STACK_ID = '' import os os.system('export HEAT_INCLUDE_PASSWORD=1') from heatclient.client import Client from heatclient.v1.stacks import StackManager _heat = Client('1', endpoint=heat_url, token=auth_token) def get_health(time_elapsed, parameter=""): try: _stack = _heat.stacks.get(STACK_ID) except: auth_token = kc.auth_token ceilometer = c_client.Client(endpoint=CEILOMETER_ENDPOINT, token= lambda : auth_token ) _heat = Client('1', endpoint=heat_url, token=auth_token) _stack = _heat.stacks.get(STACK_ID) query = [dict(field='metadata.user_metadata.stack', op='eq', value=_stack.id)] result = ceilometer.statistics.list('cpu_util', q=query, period=100) if len(result) > 0: print 'PEGOU RESULTADO, AMIGO' print result[-1].avg return result[-1].avg
def credentials(domain, username, project_domain_name, project_name, password, ip, operator_name, operator_password): heat = Client('1', endpoint="http://" + ip + ":8004/v1/" + get_project_id(domain=domain, username=username, project_domain_name=project_domain_name, project_name=project_name, password=password, ip=ip, operator_name=operator_name), token=get_token(domain=domain, username=operator_name, project_domain_name=project_domain_name, project_name=operator_name, password=operator_password, ip=ip)) return heat
def heat_client(self): heat_url = self.keystone_client.service_catalog.url_for( service_type='orchestration', endpoint_type='publicURL') return Client('1', endpoint=heat_url, token=self.keystone_client.auth_token)