idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
245,300 | def write ( self , config_file ) : if config_file not in self . templates : log ( 'Config not registered: %s' % config_file , level = ERROR ) raise OSConfigException _out = self . render ( config_file ) if six . PY3 : _out = _out . encode ( 'UTF-8' ) with open ( config_file , 'wb' ) as out : out . write ( _out ) log ( ... | Write a single config file raises if config file is not registered . |
245,301 | def write_all ( self ) : [ self . write ( k ) for k in six . iterkeys ( self . templates ) ] | Write out all registered config files . |
245,302 | def set_release ( self , openstack_release ) : self . _tmpl_env = None self . openstack_release = openstack_release self . _get_tmpl_env ( ) | Resets the template environment and generates a new template loader based on a the new openstack release . |
245,303 | def complete_contexts ( self ) : interfaces = [ ] [ interfaces . extend ( i . complete_contexts ( ) ) for i in six . itervalues ( self . templates ) ] return interfaces | Returns a list of context interfaces that yield a complete context . |
245,304 | def is_elected_leader ( resource ) : try : return juju_is_leader ( ) except NotImplementedError : log ( 'Juju leadership election feature not enabled' ', using fallback support' , level = WARNING ) if is_clustered ( ) : if not is_crm_leader ( resource ) : log ( 'Deferring action to CRM leader.' , level = INFO ) return ... | Returns True if the charm executing this is the elected cluster leader . |
245,305 | def is_crm_dc ( ) : cmd = [ 'crm' , 'status' ] try : status = subprocess . check_output ( cmd , stderr = subprocess . STDOUT ) if not isinstance ( status , six . text_type ) : status = six . text_type ( status , "utf-8" ) except subprocess . CalledProcessError as ex : raise CRMDCNotFound ( str ( ex ) ) current_dc = '' ... | Determine leadership by querying the pacemaker Designated Controller |
245,306 | def is_crm_leader ( resource , retry = False ) : if resource == DC_RESOURCE_NAME : return is_crm_dc ( ) cmd = [ 'crm' , 'resource' , 'show' , resource ] try : status = subprocess . check_output ( cmd , stderr = subprocess . STDOUT ) if not isinstance ( status , six . text_type ) : status = six . text_type ( status , "u... | Returns True if the charm calling this is the elected corosync leader as returned by calling the external crm command . |
245,307 | def peer_ips ( peer_relation = 'cluster' , addr_key = 'private-address' ) : peers = { } for r_id in relation_ids ( peer_relation ) : for unit in relation_list ( r_id ) : peers [ unit ] = relation_get ( addr_key , rid = r_id , unit = unit ) return peers | Return a dict of peers and their private - address |
245,308 | def oldest_peer ( peers ) : local_unit_no = int ( os . getenv ( 'JUJU_UNIT_NAME' ) . split ( '/' ) [ 1 ] ) for peer in peers : remote_unit_no = int ( peer . split ( '/' ) [ 1 ] ) if remote_unit_no < local_unit_no : return False return True | Determines who the oldest peer is by comparing unit numbers . |
245,309 | def canonical_url ( configs , vip_setting = 'vip' ) : scheme = 'http' if 'https' in configs . complete_contexts ( ) : scheme = 'https' if is_clustered ( ) : addr = config_get ( vip_setting ) else : addr = unit_get ( 'private-address' ) return '%s://%s' % ( scheme , addr ) | Returns the correct HTTP URL to this host given the state of HTTPS configuration and hacluster . |
245,310 | def distributed_wait ( modulo = None , wait = None , operation_name = 'operation' ) : if modulo is None : modulo = config_get ( 'modulo-nodes' ) or 3 if wait is None : wait = config_get ( 'known-wait' ) or 30 if juju_is_leader ( ) : calculated_wait = 0 else : calculated_wait = modulo_distribution ( modulo = modulo , wa... | Distribute operations by waiting based on modulo_distribution |
245,311 | def update ( fatal = False ) : cmd = [ 'yum' , '--assumeyes' , 'update' ] log ( "Update with fatal: {}" . format ( fatal ) ) _run_yum_command ( cmd , fatal ) | Update local yum cache . |
245,312 | def yum_search ( packages ) : output = { } cmd = [ 'yum' , 'search' ] if isinstance ( packages , six . string_types ) : cmd . append ( packages ) else : cmd . extend ( packages ) log ( "Searching for {}" . format ( packages ) ) result = subprocess . check_output ( cmd ) for package in list ( packages ) : output [ packa... | Search for a package . |
245,313 | def _run_yum_command ( cmd , fatal = False ) : env = os . environ . copy ( ) if fatal : retry_count = 0 result = None while result is None or result == YUM_NO_LOCK : try : result = subprocess . check_call ( cmd , env = env ) except subprocess . CalledProcessError as e : retry_count = retry_count + 1 if retry_count > YU... | Run an YUM command . |
245,314 | def py ( self , output ) : import pprint pprint . pprint ( output , stream = self . outfile ) | Output data as a nicely - formatted python data structure |
245,315 | def csv ( self , output ) : import csv csvwriter = csv . writer ( self . outfile ) csvwriter . writerows ( output ) | Output data as excel - compatible CSV |
245,316 | def tab ( self , output ) : import csv csvwriter = csv . writer ( self . outfile , dialect = csv . excel_tab ) csvwriter . writerows ( output ) | Output data in excel - compatible tab - delimited format |
245,317 | def subcommand ( self , command_name = None ) : def wrapper ( decorated ) : cmd_name = command_name or decorated . __name__ subparser = self . subparsers . add_parser ( cmd_name , description = decorated . __doc__ ) for args , kwargs in describe_arguments ( decorated ) : subparser . add_argument ( * args , ** kwargs ) ... | Decorate a function as a subcommand . Use its arguments as the command - line arguments |
245,318 | def run ( self ) : "Run cli, processing arguments and executing subcommands." arguments = self . argument_parser . parse_args ( ) argspec = inspect . getargspec ( arguments . func ) vargs = [ ] for arg in argspec . args : vargs . append ( getattr ( arguments , arg ) ) if argspec . varargs : vargs . extend ( getattr ( a... | Run cli processing arguments and executing subcommands . |
245,319 | def ssh_authorized_peers ( peer_interface , user , group = None , ensure_local_user = False ) : if ensure_local_user : ensure_user ( user , group ) priv_key , pub_key = get_keypair ( user ) hook = hook_name ( ) if hook == '%s-relation-joined' % peer_interface : relation_set ( ssh_pub_key = pub_key ) elif hook == '%s-re... | Main setup function should be called from both peer - changed and - joined hooks with the same parameters . |
245,320 | def collect_authed_hosts ( peer_interface ) : hosts = [ ] for r_id in ( relation_ids ( peer_interface ) or [ ] ) : for unit in related_units ( r_id ) : private_addr = relation_get ( 'private-address' , rid = r_id , unit = unit ) authed_hosts = relation_get ( 'ssh_authorized_hosts' , rid = r_id , unit = unit ) if not au... | Iterate through the units on peer interface to find all that have the calling host in its authorized hosts list |
245,321 | def sync_path_to_host ( path , host , user , verbose = False , cmd = None , gid = None , fatal = False ) : cmd = cmd or copy ( BASE_CMD ) if not verbose : cmd . append ( '-silent' ) if path . endswith ( '/' ) : path = path [ : ( len ( path ) - 1 ) ] cmd = cmd + [ path , 'ssh://%s@%s/%s' % ( user , host , path ) ] try :... | Sync path to an specific peer host |
245,322 | def sync_to_peer ( host , user , paths = None , verbose = False , cmd = None , gid = None , fatal = False ) : if paths : for p in paths : sync_path_to_host ( p , host , user , verbose , cmd , gid , fatal ) | Sync paths to an specific peer host |
245,323 | def sync_to_peers ( peer_interface , user , paths = None , verbose = False , cmd = None , gid = None , fatal = False ) : if paths : for host in collect_authed_hosts ( peer_interface ) : sync_to_peer ( host , user , paths , verbose , cmd , gid , fatal ) | Sync all hosts to an specific path |
245,324 | def parse_options ( given , available ) : for key , value in sorted ( given . items ( ) ) : if not value : continue if key in available : yield "--{0}={1}" . format ( key , value ) | Given a set of options check if available |
245,325 | def pip_install_requirements ( requirements , constraints = None , ** options ) : command = [ "install" ] available_options = ( 'proxy' , 'src' , 'log' , ) for option in parse_options ( options , available_options ) : command . append ( option ) command . append ( "-r {0}" . format ( requirements ) ) if constraints : c... | Install a requirements file . |
245,326 | def pip_install ( package , fatal = False , upgrade = False , venv = None , constraints = None , ** options ) : if venv : venv_python = os . path . join ( venv , 'bin/pip' ) command = [ venv_python , "install" ] else : command = [ "install" ] available_options = ( 'proxy' , 'src' , 'log' , 'index-url' , ) for option in... | Install a python package |
245,327 | def pip_uninstall ( package , ** options ) : command = [ "uninstall" , "-q" , "-y" ] available_options = ( 'proxy' , 'log' , ) for option in parse_options ( options , available_options ) : command . append ( option ) if isinstance ( package , list ) : command . extend ( package ) else : command . append ( package ) log... | Uninstall a python package |
245,328 | def pip_create_virtualenv ( path = None ) : if six . PY2 : apt_install ( 'python-virtualenv' ) else : apt_install ( 'python3-virtualenv' ) if path : venv_path = path else : venv_path = os . path . join ( charm_dir ( ) , 'venv' ) if not os . path . exists ( venv_path ) : subprocess . check_call ( [ 'virtualenv' , venv_p... | Create an isolated Python environment . |
245,329 | def configure_sources ( update = False , sources_var = 'install_sources' , keys_var = 'install_keys' ) : sources = safe_load ( ( config ( sources_var ) or '' ) . strip ( ) ) or [ ] keys = safe_load ( ( config ( keys_var ) or '' ) . strip ( ) ) or None if isinstance ( sources , six . string_types ) : sources = [ sources... | Configure multiple sources from charm configuration . |
245,330 | def install_remote ( source , * args , ** kwargs ) : handlers = [ h for h in plugins ( ) if h . can_handle ( source ) is True ] for handler in handlers : try : return handler . install ( source , * args , ** kwargs ) except UnhandledSource as e : log ( 'Install source attempt unsuccessful: {}' . format ( e ) , level = ... | Install a file tree from a remote source . |
245,331 | def base_url ( self , url ) : parts = list ( self . parse_url ( url ) ) parts [ 4 : ] = [ '' for i in parts [ 4 : ] ] return urlunparse ( parts ) | Return url without querystring or fragment |
245,332 | def is_block_device ( path ) : if not os . path . exists ( path ) : return False return S_ISBLK ( os . stat ( path ) . st_mode ) | Confirm device at path is a valid block device node . |
245,333 | def zap_disk ( block_device ) : call ( [ 'sgdisk' , '--zap-all' , '--' , block_device ] ) call ( [ 'sgdisk' , '--clear' , '--mbrtogpt' , '--' , block_device ] ) dev_end = check_output ( [ 'blockdev' , '--getsz' , block_device ] ) . decode ( 'UTF-8' ) gpt_end = int ( dev_end . split ( ) [ 0 ] ) - 100 check_call ( [ 'dd'... | Clear a block device of partition table . Relies on sgdisk which is installed as pat of the gdisk package in Ubuntu . |
245,334 | def is_device_mounted ( device ) : try : out = check_output ( [ 'lsblk' , '-P' , device ] ) . decode ( 'UTF-8' ) except Exception : return False return bool ( re . search ( r'MOUNTPOINT=".+"' , out ) ) | Given a device path return True if that device is mounted and False if it isn t . |
245,335 | def mkfs_xfs ( device , force = False ) : cmd = [ 'mkfs.xfs' ] if force : cmd . append ( "-f" ) cmd += [ '-i' , 'size=1024' , device ] check_call ( cmd ) | Format device with XFS filesystem . |
245,336 | def wait_for_machine ( num_machines = 1 , timeout = 300 ) : if get_machine_data ( ) [ 0 ] [ 'dns-name' ] == 'localhost' : return 1 , 0 start_time = time . time ( ) while True : machine_data = get_machine_data ( ) non_zookeeper_machines = [ machine_data [ key ] for key in list ( machine_data . keys ( ) ) [ 1 : ] ] if le... | Wait timeout seconds for num_machines machines to come up . |
245,337 | def wait_for_unit ( service_name , timeout = 480 ) : wait_for_machine ( num_machines = 1 ) start_time = time . time ( ) while True : state = unit_info ( service_name , 'agent-state' ) if 'error' in state or state == 'started' : break if time . time ( ) - start_time >= timeout : raise RuntimeError ( 'timeout waiting for... | Wait timeout seconds for a given service name to come up . |
245,338 | def wait_for_relation ( service_name , relation_name , timeout = 120 ) : start_time = time . time ( ) while True : relation = unit_info ( service_name , 'relations' ) . get ( relation_name ) if relation is not None and relation [ 'state' ] == 'up' : break if time . time ( ) - start_time >= timeout : raise RuntimeError ... | Wait timeout seconds for a given relation to come up . |
245,339 | def service_available ( service_name ) : try : subprocess . check_output ( [ 'service' , service_name , 'status' ] , stderr = subprocess . STDOUT ) . decode ( 'UTF-8' ) except subprocess . CalledProcessError as e : return b'unrecognized service' not in e . output else : return True | Determine whether a system service is available |
245,340 | def install_salt_support ( from_ppa = True ) : if from_ppa : subprocess . check_call ( [ '/usr/bin/add-apt-repository' , '--yes' , 'ppa:saltstack/salt' , ] ) subprocess . check_call ( [ '/usr/bin/apt-get' , 'update' ] ) charmhelpers . fetch . apt_install ( 'salt-common' ) | Installs the salt - minion helper for machine state . |
245,341 | def update_machine_state ( state_path ) : charmhelpers . contrib . templating . contexts . juju_state_to_yaml ( salt_grains_path ) subprocess . check_call ( [ 'salt-call' , '--local' , 'state.template' , state_path , ] ) | Update the machine state using the provided state declaration . |
245,342 | def pool_exists ( service , name ) : try : out = check_output ( [ 'rados' , '--id' , service , 'lspools' ] ) if six . PY3 : out = out . decode ( 'UTF-8' ) except CalledProcessError : return False return name in out . split ( ) | Check to see if a RADOS pool already exists . |
245,343 | def install ( ) : ceph_dir = "/etc/ceph" if not os . path . exists ( ceph_dir ) : os . mkdir ( ceph_dir ) apt_install ( 'ceph-common' , fatal = True ) | Basic Ceph client installation . |
245,344 | def rbd_exists ( service , pool , rbd_img ) : try : out = check_output ( [ 'rbd' , 'list' , '--id' , service , '--pool' , pool ] ) if six . PY3 : out = out . decode ( 'UTF-8' ) except CalledProcessError : return False return rbd_img in out | Check to see if a RADOS block device exists . |
245,345 | def create_rbd_image ( service , pool , image , sizemb ) : cmd = [ 'rbd' , 'create' , image , '--size' , str ( sizemb ) , '--id' , service , '--pool' , pool ] check_call ( cmd ) | Create a new RADOS block device . |
245,346 | def set_app_name_for_pool ( client , pool , name ) : if cmp_pkgrevno ( 'ceph-common' , '12.0.0' ) >= 0 : cmd = [ 'ceph' , '--id' , client , 'osd' , 'pool' , 'application' , 'enable' , pool , name ] check_call ( cmd ) | Calls osd pool application enable for the specified pool name |
245,347 | def create_pool ( service , name , replicas = 3 , pg_num = None ) : if pool_exists ( service , name ) : log ( "Ceph pool {} already exists, skipping creation" . format ( name ) , level = WARNING ) return if not pg_num : osds = get_osds ( service ) if osds : pg_num = ( len ( osds ) * 100 // replicas ) else : pg_num = 20... | Create a new RADOS pool . |
245,348 | def add_key ( service , key ) : keyring = _keyring_path ( service ) if os . path . exists ( keyring ) : with open ( keyring , 'r' ) as ring : if key in ring . read ( ) : log ( 'Ceph keyring exists at %s and has not changed.' % keyring , level = DEBUG ) return log ( 'Updating existing keyring %s.' % keyring , level = DE... | Add a key to a keyring . |
245,349 | def delete_keyring ( service ) : keyring = _keyring_path ( service ) if not os . path . exists ( keyring ) : log ( 'Keyring does not exist at %s' % keyring , level = WARNING ) return os . remove ( keyring ) log ( 'Deleted ring at %s.' % keyring , level = INFO ) | Delete an existing Ceph keyring . |
245,350 | def create_key_file ( service , key ) : keyfile = _keyfile_path ( service ) if os . path . exists ( keyfile ) : log ( 'Keyfile exists at %s.' % keyfile , level = WARNING ) return with open ( keyfile , 'w' ) as fd : fd . write ( key ) log ( 'Created new keyfile at %s.' % keyfile , level = INFO ) | Create a file containing key . |
245,351 | def get_ceph_nodes ( relation = 'ceph' ) : hosts = [ ] for r_id in relation_ids ( relation ) : for unit in related_units ( r_id ) : hosts . append ( relation_get ( 'private-address' , unit = unit , rid = r_id ) ) return hosts | Query named relation to determine current nodes . |
245,352 | def configure ( service , key , auth , use_syslog ) : add_key ( service , key ) create_key_file ( service , key ) hosts = get_ceph_nodes ( ) with open ( '/etc/ceph/ceph.conf' , 'w' ) as ceph_conf : ceph_conf . write ( CEPH_CONF . format ( auth = auth , keyring = _keyring_path ( service ) , mon_hosts = "," . join ( map ... | Perform basic configuration of Ceph . |
245,353 | def image_mapped ( name ) : try : out = check_output ( [ 'rbd' , 'showmapped' ] ) if six . PY3 : out = out . decode ( 'UTF-8' ) except CalledProcessError : return False return name in out | Determine whether a RADOS block device is mapped locally . |
245,354 | def map_block_storage ( service , pool , image ) : cmd = [ 'rbd' , 'map' , '{}/{}' . format ( pool , image ) , '--user' , service , '--secret' , _keyfile_path ( service ) , ] check_call ( cmd ) | Map a RADOS block device for local use . |
245,355 | def make_filesystem ( blk_device , fstype = 'ext4' , timeout = 10 ) : count = 0 e_noent = os . errno . ENOENT while not os . path . exists ( blk_device ) : if count >= timeout : log ( 'Gave up waiting on block device %s' % blk_device , level = ERROR ) raise IOError ( e_noent , os . strerror ( e_noent ) , blk_device ) l... | Make a new filesystem on the specified block device . |
245,356 | def place_data_on_block_device ( blk_device , data_src_dst ) : mount ( blk_device , '/mnt' ) copy_files ( data_src_dst , '/mnt' ) umount ( '/mnt' ) _dir = os . stat ( data_src_dst ) uid = _dir . st_uid gid = _dir . st_gid mount ( blk_device , data_src_dst , persist = True ) os . chown ( data_src_dst , uid , gid ) | Migrate data in data_src_dst to blk_device and then remount . |
245,357 | def ensure_ceph_keyring ( service , user = None , group = None , relation = 'ceph' , key = None ) : if not key : for rid in relation_ids ( relation ) : for unit in related_units ( rid ) : key = relation_get ( 'key' , rid = rid , unit = unit ) if key : break if not key : return False add_key ( service = service , key = ... | Ensures a ceph keyring is created for a named service and optionally ensures user and group ownership . |
245,358 | def get_previous_request ( rid ) : request = None broker_req = relation_get ( attribute = 'broker_req' , rid = rid , unit = local_unit ( ) ) if broker_req : request_data = json . loads ( broker_req ) request = CephBrokerRq ( api_version = request_data [ 'api-version' ] , request_id = request_data [ 'request-id' ] ) req... | Return the last ceph broker request sent on a given relation |
245,359 | def get_request_states ( request , relation = 'ceph' ) : complete = [ ] requests = { } for rid in relation_ids ( relation ) : complete = False previous_request = get_previous_request ( rid ) if request == previous_request : sent = True complete = is_request_complete_for_rid ( previous_request , rid ) else : sent = Fals... | Return a dict of requests per relation id with their corresponding completion state . |
245,360 | def is_request_sent ( request , relation = 'ceph' ) : states = get_request_states ( request , relation = relation ) for rid in states . keys ( ) : if not states [ rid ] [ 'sent' ] : return False return True | Check to see if a functionally equivalent request has already been sent |
245,361 | def is_request_complete_for_rid ( request , rid ) : broker_key = get_broker_rsp_key ( ) for unit in related_units ( rid ) : rdata = relation_get ( rid = rid , unit = unit ) if rdata . get ( broker_key ) : rsp = CephBrokerRsp ( rdata . get ( broker_key ) ) if rsp . request_id == request . request_id : if not rsp . exit_... | Check if a given request has been completed on the given relation |
245,362 | def send_request_if_needed ( request , relation = 'ceph' ) : if is_request_sent ( request , relation = relation ) : log ( 'Request already sent but not complete, not sending new request' , level = DEBUG ) else : for rid in relation_ids ( relation ) : log ( 'Sending request {}' . format ( request . request_id ) , level ... | Send broker request if an equivalent request has not already been sent |
245,363 | def is_broker_action_done ( action , rid = None , unit = None ) : rdata = relation_get ( rid , unit ) or { } broker_rsp = rdata . get ( get_broker_rsp_key ( ) ) if not broker_rsp : return False rsp = CephBrokerRsp ( broker_rsp ) unit_name = local_unit ( ) . partition ( '/' ) [ 2 ] key = "unit_{}_ceph_broker_action.{}" ... | Check whether broker action has completed yet . |
245,364 | def mark_broker_action_done ( action , rid = None , unit = None ) : rdata = relation_get ( rid , unit ) or { } broker_rsp = rdata . get ( get_broker_rsp_key ( ) ) if not broker_rsp : return rsp = CephBrokerRsp ( broker_rsp ) unit_name = local_unit ( ) . partition ( '/' ) [ 2 ] key = "unit_{}_ceph_broker_action.{}" . fo... | Mark action as having been completed . |
245,365 | def get_pgs ( self , pool_size , percent_data = DEFAULT_POOL_WEIGHT , device_class = None ) : validator ( value = pool_size , valid_type = int ) if percent_data is None : percent_data = DEFAULT_POOL_WEIGHT osd_list = get_osds ( self . service , device_class ) expected = config ( 'expected-osd-count' ) or 0 if osd_list ... | Return the number of placement groups to use when creating the pool . |
245,366 | def add_op_create_replicated_pool ( self , name , replica_count = 3 , pg_num = None , weight = None , group = None , namespace = None , app_name = None , max_bytes = None , max_objects = None ) : if pg_num and weight : raise ValueError ( 'pg_num and weight are mutually exclusive' ) self . ops . append ( { 'op' : 'creat... | Adds an operation to create a replicated pool . |
245,367 | def add_op_create_erasure_pool ( self , name , erasure_profile = None , weight = None , group = None , app_name = None , max_bytes = None , max_objects = None ) : self . ops . append ( { 'op' : 'create-pool' , 'name' : name , 'pool-type' : 'erasure' , 'erasure-profile' : erasure_profile , 'weight' : weight , 'group' : ... | Adds an operation to create a erasure coded pool . |
245,368 | def get_nagios_unit_name ( relation_name = 'nrpe-external-master' ) : host_context = get_nagios_hostcontext ( relation_name ) if host_context : unit = "%s:%s" % ( host_context , local_unit ( ) ) else : unit = local_unit ( ) return unit | Return the nagios unit name prepended with host_context if needed |
245,369 | def copy_nrpe_checks ( nrpe_files_dir = None ) : NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins' if nrpe_files_dir is None : for segment in [ '.' , 'hooks' ] : nrpe_files_dir = os . path . abspath ( os . path . join ( os . getenv ( 'CHARM_DIR' ) , segment , 'charmhelpers' , 'contrib' , 'openstack' , 'files' ) ) if os ... | Copy the nrpe checks into place |
245,370 | def write_vaultlocker_conf ( context , priority = 100 ) : charm_vl_path = "/var/lib/charm/{}/vaultlocker.conf" . format ( hookenv . service_name ( ) ) host . mkdir ( os . path . dirname ( charm_vl_path ) , perms = 0o700 ) templating . render ( source = 'vaultlocker.conf.j2' , target = charm_vl_path , context = context ... | Write vaultlocker configuration to disk and install alternative |
245,371 | def vault_relation_complete ( backend = None ) : vault_kv = VaultKVContext ( secret_backend = backend or VAULTLOCKER_BACKEND ) vault_kv ( ) return vault_kv . complete | Determine whether vault relation is complete |
245,372 | def retrieve_secret_id ( url , token ) : import hvac client = hvac . Client ( url = url , token = token ) response = client . _post ( '/v1/sys/wrapping/unwrap' ) if response . status_code == 200 : data = response . json ( ) return data [ 'data' ] [ 'secret_id' ] | Retrieve a response - wrapped secret_id from Vault |
245,373 | def retry_on_exception ( num_retries , base_delay = 0 , exc_type = Exception ) : def _retry_on_exception_inner_1 ( f ) : def _retry_on_exception_inner_2 ( * args , ** kwargs ) : retries = num_retries multiplier = 1 while True : try : return f ( * args , ** kwargs ) except exc_type : if not retries : raise delay = base_... | If the decorated function raises exception exc_type allow num_retries retry attempts before raise the exception . |
245,374 | def _snap_exec ( commands ) : assert type ( commands ) == list retry_count = 0 return_code = None while return_code is None or return_code == SNAP_NO_LOCK : try : return_code = subprocess . check_call ( [ 'snap' ] + commands , env = os . environ ) except subprocess . CalledProcessError as e : retry_count += + 1 if retr... | Execute snap commands . |
245,375 | def snap_remove ( packages , * flags ) : if type ( packages ) is not list : packages = [ packages ] flags = list ( flags ) message = 'Removing snap(s) "%s"' % ', ' . join ( packages ) if flags : message += ' with options "%s"' % ', ' . join ( flags ) log ( message , level = 'INFO' ) return _snap_exec ( [ 'remove' ] + f... | Remove a snap package . |
245,376 | def validate_v2_endpoint_data ( self , endpoints , admin_port , internal_port , public_port , expected ) : self . log . debug ( 'Validating endpoint data...' ) self . log . debug ( 'actual: {}' . format ( repr ( endpoints ) ) ) found = False for ep in endpoints : self . log . debug ( 'endpoint: {}' . format ( repr ( ep... | Validate endpoint data . |
245,377 | def validate_v3_endpoint_data ( self , endpoints , admin_port , internal_port , public_port , expected , expected_num_eps = 3 ) : self . log . debug ( 'Validating v3 endpoint data...' ) self . log . debug ( 'actual: {}' . format ( repr ( endpoints ) ) ) found = [ ] for ep in endpoints : self . log . debug ( 'endpoint: ... | Validate keystone v3 endpoint data . |
245,378 | def convert_svc_catalog_endpoint_data_to_v3 ( self , ep_data ) : self . log . warn ( "Endpoint ID and Region ID validation is limited to not " "null checks after v2 to v3 conversion" ) for svc in ep_data . keys ( ) : assert len ( ep_data [ svc ] ) == 1 , "Unknown data format" svc_ep_data = ep_data [ svc ] [ 0 ] ep_data... | Convert v2 endpoint data into v3 . |
245,379 | def validate_v2_svc_catalog_endpoint_data ( self , expected , actual ) : self . log . debug ( 'Validating service catalog endpoint data...' ) self . log . debug ( 'actual: {}' . format ( repr ( actual ) ) ) for k , v in six . iteritems ( expected ) : if k in actual : ret = self . _validate_dict_data ( expected [ k ] [ ... | Validate service catalog endpoint data . |
245,380 | def validate_v3_svc_catalog_endpoint_data ( self , expected , actual ) : self . log . debug ( 'Validating v3 service catalog endpoint data...' ) self . log . debug ( 'actual: {}' . format ( repr ( actual ) ) ) for k , v in six . iteritems ( expected ) : if k in actual : l_expected = sorted ( v , key = lambda x : x [ 'i... | Validate the keystone v3 catalog endpoint data . |
245,381 | def validate_tenant_data ( self , expected , actual ) : self . log . debug ( 'Validating tenant data...' ) self . log . debug ( 'actual: {}' . format ( repr ( actual ) ) ) for e in expected : found = False for act in actual : a = { 'enabled' : act . enabled , 'description' : act . description , 'name' : act . name , 'i... | Validate tenant data . |
245,382 | def validate_user_data ( self , expected , actual , api_version = None ) : self . log . debug ( 'Validating user data...' ) self . log . debug ( 'actual: {}' . format ( repr ( actual ) ) ) for e in expected : found = False for act in actual : if e [ 'name' ] == act . name : a = { 'enabled' : act . enabled , 'name' : ac... | Validate user data . |
245,383 | def validate_flavor_data ( self , expected , actual ) : self . log . debug ( 'Validating flavor data...' ) self . log . debug ( 'actual: {}' . format ( repr ( actual ) ) ) act = [ a . name for a in actual ] return self . _validate_list_data ( expected , act ) | Validate flavor data . |
245,384 | def tenant_exists ( self , keystone , tenant ) : self . log . debug ( 'Checking if tenant exists ({})...' . format ( tenant ) ) return tenant in [ t . name for t in keystone . tenants . list ( ) ] | Return True if tenant exists . |
245,385 | def keystone_wait_for_propagation ( self , sentry_relation_pairs , api_version ) : for ( sentry , relation_name ) in sentry_relation_pairs : rel = sentry . relation ( 'identity-service' , relation_name ) self . log . debug ( 'keystone relation data: {}' . format ( rel ) ) if rel . get ( 'api_version' ) != str ( api_ver... | Iterate over list of sentry and relation tuples and verify that api_version has the expected value . |
245,386 | def keystone_configure_api_version ( self , sentry_relation_pairs , deployment , api_version ) : self . log . debug ( "Setting keystone preferred-api-version: '{}'" "" . format ( api_version ) ) config = { 'preferred-api-version' : api_version } deployment . d . configure ( 'keystone' , config ) deployment . _auto_wait... | Configure preferred - api - version of keystone in deployment and monitor provided list of relation objects for propagation before returning to caller . |
245,387 | def authenticate_cinder_admin ( self , keystone , api_version = 2 ) : self . log . debug ( 'Authenticating cinder admin...' ) _clients = { 1 : cinder_client . Client , 2 : cinder_clientv2 . Client } return _clients [ api_version ] ( session = keystone . session ) | Authenticates admin user with cinder . |
245,388 | def authenticate_keystone ( self , keystone_ip , username , password , api_version = False , admin_port = False , user_domain_name = None , domain_name = None , project_domain_name = None , project_name = None ) : self . log . debug ( 'Authenticating with keystone...' ) if not api_version : api_version = 2 sess , auth ... | Authenticate with Keystone |
245,389 | def get_keystone_session ( self , keystone_ip , username , password , api_version = False , admin_port = False , user_domain_name = None , domain_name = None , project_domain_name = None , project_name = None ) : ep = self . get_keystone_endpoint ( keystone_ip , api_version = api_version , admin_port = admin_port ) if ... | Return a keystone session object |
245,390 | def get_keystone_endpoint ( self , keystone_ip , api_version = None , admin_port = False ) : port = 5000 if admin_port : port = 35357 base_ep = "http://{}:{}" . format ( keystone_ip . strip ( ) . decode ( 'utf-8' ) , port ) if api_version == 2 : ep = base_ep + "/v2.0" else : ep = base_ep + "/v3" return ep | Return keystone endpoint |
245,391 | def get_default_keystone_session ( self , keystone_sentry , openstack_release = None , api_version = 2 ) : self . log . debug ( 'Authenticating keystone admin...' ) if api_version == 3 or ( openstack_release and openstack_release >= 11 ) : client_class = keystone_client_v3 . Client api_version = 3 else : client_class =... | Return a keystone session object and client object assuming standard default settings |
245,392 | def authenticate_keystone_admin ( self , keystone_sentry , user , password , tenant = None , api_version = None , keystone_ip = None , user_domain_name = None , project_domain_name = None , project_name = None ) : self . log . debug ( 'Authenticating keystone admin...' ) if not keystone_ip : keystone_ip = keystone_sent... | Authenticates admin user with the keystone admin endpoint . |
245,393 | def authenticate_keystone_user ( self , keystone , user , password , tenant ) : self . log . debug ( 'Authenticating keystone user ({})...' . format ( user ) ) ep = keystone . service_catalog . url_for ( service_type = 'identity' , interface = 'publicURL' ) keystone_ip = urlparse . urlparse ( ep ) . hostname return sel... | Authenticates a regular user with the keystone public endpoint . |
245,394 | def authenticate_glance_admin ( self , keystone , force_v1_client = False ) : self . log . debug ( 'Authenticating glance admin...' ) ep = keystone . service_catalog . url_for ( service_type = 'image' , interface = 'adminURL' ) if not force_v1_client and keystone . session : return glance_clientv2 . Client ( "2" , sess... | Authenticates admin user with glance . |
245,395 | def authenticate_heat_admin ( self , keystone ) : self . log . debug ( 'Authenticating heat admin...' ) ep = keystone . service_catalog . url_for ( service_type = 'orchestration' , interface = 'publicURL' ) if keystone . session : return heat_client . Client ( endpoint = ep , session = keystone . session ) else : retur... | Authenticates the admin user with heat . |
245,396 | def authenticate_nova_user ( self , keystone , user , password , tenant ) : self . log . debug ( 'Authenticating nova user ({})...' . format ( user ) ) ep = keystone . service_catalog . url_for ( service_type = 'identity' , interface = 'publicURL' ) if keystone . session : return nova_client . Client ( NOVA_CLIENT_VERS... | Authenticates a regular user with nova - api . |
245,397 | def authenticate_swift_user ( self , keystone , user , password , tenant ) : self . log . debug ( 'Authenticating swift user ({})...' . format ( user ) ) ep = keystone . service_catalog . url_for ( service_type = 'identity' , interface = 'publicURL' ) if keystone . session : return swiftclient . Connection ( session = ... | Authenticates a regular user with swift api . |
245,398 | def create_flavor ( self , nova , name , ram , vcpus , disk , flavorid = "auto" , ephemeral = 0 , swap = 0 , rxtx_factor = 1.0 , is_public = True ) : try : nova . flavors . find ( name = name ) except ( exceptions . NotFound , exceptions . NoUniqueMatch ) : self . log . debug ( 'Creating flavor ({})' . format ( name ) ... | Create the specified flavor . |
245,399 | def glance_create_image ( self , glance , image_name , image_url , download_dir = 'tests' , hypervisor_type = None , disk_format = 'qcow2' , architecture = 'x86_64' , container_format = 'bare' ) : self . log . debug ( 'Creating glance image ({}) from ' '{}...' . format ( image_name , image_url ) ) http_proxy = os . get... | Download an image and upload it to glance validate its status and return an image object pointer . KVM defaults can override for LXD . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.