idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
25,200
def upgrade_juju ( self , dry_run = False , reset_previous_upgrade = False , upload_tools = False , version = None ) : raise NotImplementedError ( )
Upgrade Juju on all machines in a model .
25,201
async def get_metrics ( self , * tags ) : log . debug ( "Retrieving metrics for %s" , ', ' . join ( tags ) if tags else "all units" ) metrics_facade = client . MetricsDebugFacade . from_connection ( self . connection ( ) ) entities = [ client . Entity ( tag ) for tag in tags ] metrics_result = await metrics_facade . Ge...
Retrieve metrics .
25,202
async def scale ( self , application , scale ) : application = self . resolve ( application ) return await self . model . applications [ application ] . scale ( scale = scale )
Handle a change of scale to a k8s application .
25,203
def make_archive ( self , path ) : zf = zipfile . ZipFile ( path , 'w' , zipfile . ZIP_DEFLATED ) for dirpath , dirnames , filenames in os . walk ( self . path ) : relative_path = dirpath [ len ( self . path ) + 1 : ] if relative_path and not self . _ignore ( relative_path ) : zf . write ( dirpath , relative_path ) for...
Create archive of directory and write to path .
25,204
def _check_type ( self , path ) : s = os . stat ( path ) if stat . S_ISDIR ( s . st_mode ) or stat . S_ISREG ( s . st_mode ) : return path raise ValueError ( "Invalid Charm at % %s" % ( path , "Invalid file type for a charm" ) )
Check the path
25,205
def _write_symlink ( self , zf , link_target , link_path ) : info = zipfile . ZipInfo ( ) info . filename = link_path info . create_system = 3 info . external_attr = 2716663808 zf . writestr ( info , link_target )
Package symlinks with appropriate zipfile metadata .
25,206
async def set_password ( self , password ) : await self . controller . change_user_password ( self . username , password ) self . _user_info . password = password
Update this user s password .
25,207
async def grant ( self , acl = 'login' ) : if await self . controller . grant ( self . username , acl ) : self . _user_info . access = acl
Set access level of this user on the controller .
25,208
async def revoke ( self ) : await self . controller . revoke ( self . username ) self . _user_info . access = ''
Removes all access rights for this user from the controller .
25,209
async def disable ( self ) : await self . controller . disable_user ( self . username ) self . _user_info . disabled = True
Disable this user .
25,210
async def enable ( self ) : await self . controller . enable_user ( self . username ) self . _user_info . disabled = False
Re - enable this user .
25,211
async def destroy ( self , force = False ) : facade = client . ClientFacade . from_connection ( self . connection ) log . debug ( 'Destroying machine %s' , self . id ) await facade . DestroyMachines ( force , [ self . id ] ) return await self . model . _wait ( 'machine' , self . id , 'remove' )
Remove this machine from the model .
25,212
async def scp_to ( self , source , destination , user = 'ubuntu' , proxy = False , scp_opts = '' ) : if proxy : raise NotImplementedError ( 'proxy option is not implemented' ) address = self . dns_name destination = '%s@%s:%s' % ( user , address , destination ) await self . _scp ( source , destination , scp_opts )
Transfer files to this machine .
25,213
async def _scp ( self , source , destination , scp_opts ) : cmd = [ 'scp' , '-i' , os . path . expanduser ( '~/.local/share/juju/ssh/juju_id_rsa' ) , '-o' , 'StrictHostKeyChecking=no' , '-q' , '-B' ] cmd . extend ( scp_opts . split ( ) if isinstance ( scp_opts , str ) else scp_opts ) cmd . extend ( [ source , destinati...
Execute an scp command . Requires a fully qualified source and destination .
25,214
def agent_version ( self ) : version = self . safe_data [ 'agent-status' ] [ 'version' ] if version : return client . Number . from_json ( version ) else : return None
Get the version of the Juju machine agent .
25,215
def dns_name ( self ) : for scope in [ 'public' , 'local-cloud' ] : addresses = self . safe_data [ 'addresses' ] or [ ] addresses = [ address for address in addresses if address [ 'scope' ] == scope ] if addresses : return addresses [ 0 ] [ 'value' ] return None
Get the DNS name for this machine . This is a best guess based on the addresses available in current data .
25,216
def from_connection ( cls , connection ) : facade_name = cls . __name__ if not facade_name . endswith ( 'Facade' ) : raise TypeError ( 'Unexpected class name: {}' . format ( facade_name ) ) facade_name = facade_name [ : - len ( 'Facade' ) ] version = connection . facades . get ( facade_name ) if version is None : raise...
Given a connected Connection object return an initialized and connected instance of an API Interface matching the name of this class .
25,217
async def execute_process ( * cmd , log = None , loop = None ) : p = await asyncio . create_subprocess_exec ( * cmd , stdin = asyncio . subprocess . PIPE , stdout = asyncio . subprocess . PIPE , stderr = asyncio . subprocess . PIPE , loop = loop ) stdout , stderr = await p . communicate ( ) if log : log . debug ( "Exec...
Wrapper around asyncio . create_subprocess_exec .
25,218
def _read_ssh_key ( ) : default_data_dir = Path ( Path . home ( ) , ".local" , "share" , "juju" ) juju_data = os . environ . get ( "JUJU_DATA" , default_data_dir ) ssh_key_path = Path ( juju_data , 'ssh' , 'juju_id_rsa.pub' ) with ssh_key_path . open ( 'r' ) as ssh_key_file : ssh_key = ssh_key_file . readlines ( ) [ 0 ...
Inner function for read_ssh_key suitable for passing to our Executor .
25,219
async def run_with_interrupt ( task , * events , loop = None ) : loop = loop or asyncio . get_event_loop ( ) task = asyncio . ensure_future ( task , loop = loop ) event_tasks = [ loop . create_task ( event . wait ( ) ) for event in events ] done , pending = await asyncio . wait ( [ task ] + event_tasks , loop = loop , ...
Awaits a task while allowing it to be interrupted by one or more asyncio . Event s .
25,220
def go_to_py_cookie ( go_cookie ) : expires = None if go_cookie . get ( 'Expires' ) is not None : t = pyrfc3339 . parse ( go_cookie [ 'Expires' ] ) expires = t . timestamp ( ) return cookiejar . Cookie ( version = 0 , name = go_cookie [ 'Name' ] , value = go_cookie [ 'Value' ] , port = None , port_specified = False , d...
Convert a Go - style JSON - unmarshaled cookie into a Python cookie
25,221
def py_to_go_cookie ( py_cookie ) : go_cookie = { 'Name' : py_cookie . name , 'Value' : py_cookie . value , 'Domain' : py_cookie . domain , 'HostOnly' : not py_cookie . domain_specified , 'Persistent' : not py_cookie . discard , 'Secure' : py_cookie . secure , 'CanonicalHost' : py_cookie . domain , } if py_cookie . pat...
Convert a python cookie to the JSON - marshalable Go - style cookie form .
25,222
def _really_load ( self , f , filename , ignore_discard , ignore_expires ) : data = json . load ( f ) or [ ] now = time . time ( ) for cookie in map ( go_to_py_cookie , data ) : if not ignore_expires and cookie . is_expired ( now ) : continue self . set_cookie ( cookie )
Implement the _really_load method called by FileCookieJar to implement the actual cookie loading
25,223
def save ( self , filename = None , ignore_discard = False , ignore_expires = False ) : if filename is None : if self . filename is not None : filename = self . filename else : raise ValueError ( cookiejar . MISSING_FILENAME_TEXT ) go_cookies = [ ] now = time . time ( ) for cookie in self : if not ignore_discard and co...
Implement the FileCookieJar abstract method .
25,224
async def connect ( self , * args , ** kwargs ) : await self . disconnect ( ) if 'endpoint' not in kwargs and len ( args ) < 2 : if args and 'model_name' in kwargs : raise TypeError ( 'connect() got multiple values for ' 'controller_name' ) elif args : controller_name = args [ 0 ] else : controller_name = kwargs . pop ...
Connect to a Juju controller .
25,225
async def add_credential ( self , name = None , credential = None , cloud = None , owner = None , force = False ) : if not cloud : cloud = await self . get_cloud ( ) if not owner : owner = self . connection ( ) . info [ 'user-info' ] [ 'identity' ] if credential and not name : raise errors . JujuError ( 'Name must be p...
Add or update a credential to the controller .
25,226
async def add_model ( self , model_name , cloud_name = None , credential_name = None , owner = None , config = None , region = None ) : model_facade = client . ModelManagerFacade . from_connection ( self . connection ( ) ) owner = owner or self . connection ( ) . info [ 'user-info' ] [ 'identity' ] cloud_name = cloud_n...
Add a model to this controller .
25,227
async def destroy_models ( self , * models , destroy_storage = False ) : uuids = await self . model_uuids ( ) models = [ uuids [ model ] if model in uuids else model for model in models ] model_facade = client . ModelManagerFacade . from_connection ( self . connection ( ) ) log . debug ( 'Destroying model%s %s' , '' if...
Destroy one or more models .
25,228
async def add_user ( self , username , password = None , display_name = None ) : if not display_name : display_name = username user_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) users = [ client . AddUser ( display_name = display_name , username = username , password = password ) ] res...
Add a user to this controller .
25,229
async def remove_user ( self , username ) : client_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) user = tag . user ( username ) await client_facade . RemoveUser ( [ client . Entity ( user ) ] )
Remove a user from this controller .
25,230
async def change_user_password ( self , username , password ) : user_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) entity = client . EntityPassword ( password , tag . user ( username ) ) return await user_facade . SetPassword ( [ entity ] )
Change the password for a user in this controller .
25,231
async def reset_user_password ( self , username ) : user_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) entity = client . Entity ( tag . user ( username ) ) results = await user_facade . ResetPassword ( [ entity ] ) secret_key = results . results [ 0 ] . secret_key return await self . g...
Reset user password .
25,232
async def destroy ( self , destroy_all_models = False ) : controller_facade = client . ControllerFacade . from_connection ( self . connection ( ) ) return await controller_facade . DestroyController ( destroy_all_models )
Destroy this controller .
25,233
async def disable_user ( self , username ) : user_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) entity = client . Entity ( tag . user ( username ) ) return await user_facade . DisableUser ( [ entity ] )
Disable a user .
25,234
async def enable_user ( self , username ) : user_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) entity = client . Entity ( tag . user ( username ) ) return await user_facade . EnableUser ( [ entity ] )
Re - enable a previously disabled user .
25,235
async def get_cloud ( self ) : cloud_facade = client . CloudFacade . from_connection ( self . connection ( ) ) result = await cloud_facade . Clouds ( ) cloud = list ( result . clouds . keys ( ) ) [ 0 ] return tag . untag ( 'cloud-' , cloud )
Get the name of the cloud that this controller lives on .
25,236
async def model_uuids ( self ) : controller_facade = client . ControllerFacade . from_connection ( self . connection ( ) ) for attempt in ( 1 , 2 , 3 ) : try : response = await controller_facade . AllModels ( ) return { um . model . name : um . model . uuid for um in response . user_models } except errors . JujuAPIErro...
Return a mapping of model names to UUIDs .
25,237
async def get_model ( self , model ) : uuids = await self . model_uuids ( ) if model in uuids : uuid = uuids [ model ] else : uuid = model from juju . model import Model model = Model ( ) kwargs = self . connection ( ) . connect_params ( ) kwargs [ 'uuid' ] = uuid await model . _connect_direct ( ** kwargs ) return mode...
Get a model by name or UUID .
25,238
async def get_user ( self , username , secret_key = None ) : client_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) user = tag . user ( username ) args = [ client . Entity ( user ) ] try : response = await client_facade . UserInfo ( args , True ) except errors . JujuError as e : if 'perm...
Get a user by name .
25,239
async def get_users ( self , include_disabled = False ) : client_facade = client . UserManagerFacade . from_connection ( self . connection ( ) ) response = await client_facade . UserInfo ( None , include_disabled ) return [ User ( self , r . result ) for r in response . results ]
Return list of users that can connect to this controller .
25,240
async def revoke ( self , username , acl = 'login' ) : controller_facade = client . ControllerFacade . from_connection ( self . connection ( ) ) user = tag . user ( username ) changes = client . ModifyControllerAccess ( 'login' , 'revoke' , user ) return await controller_facade . ModifyControllerAccess ( [ changes ] )
Removes some or all access of a user to from a controller If login access is revoked the user will no longer have any permissions on the controller . Revoking a higher privilege from a user without that privilege will have no effect .
25,241
def current_model ( self , controller_name = None , model_only = False ) : if not controller_name : controller_name = self . current_controller ( ) if not controller_name : raise JujuError ( 'No current controller' ) models = self . models ( ) [ controller_name ] if 'current-model' not in models : return None if model_...
Return the current model qualified by its controller name . If controller_name is specified the current model for that controller will be returned .
25,242
def load_credential ( self , cloud , name = None ) : try : cloud = tag . untag ( 'cloud-' , cloud ) creds_data = self . credentials ( ) [ cloud ] if not name : default_credential = creds_data . pop ( 'default-credential' , None ) default_region = creds_data . pop ( 'default-region' , None ) if default_credential : name...
Load a local credential .
25,243
def _macaroons_for_domain ( cookies , domain ) : req = urllib . request . Request ( 'https://' + domain + '/' ) cookies . add_cookie_header ( req ) return httpbakery . extract_macaroons ( req )
Return any macaroons from the given cookie jar that apply to the given domain name .
25,244
def status ( self ) : connection = self . connection ( ) if not connection : return self . DISCONNECTED if not connection . ws : return self . DISCONNECTED if self . close_called . is_set ( ) : return self . DISCONNECTING stopped = connection . _receiver_task . stopped . is_set ( ) if stopped or not connection . ws . o...
Determine the status of the connection and receiver and return ERROR CONNECTED or DISCONNECTED as appropriate .
25,245
async def _pinger ( self ) : async def _do_ping ( ) : try : await pinger_facade . Ping ( ) await asyncio . sleep ( 10 , loop = self . loop ) except CancelledError : pass pinger_facade = client . PingerFacade . from_connection ( self ) try : while True : await utils . run_with_interrupt ( _do_ping ( ) , self . monitor ....
A Controller can time us out if we are silent for too long . This is especially true in JaaS which has a fairly strict timeout .
25,246
def _http_headers ( self ) : if not self . usertag : return { } creds = u'{}:{}' . format ( self . usertag , self . password or '' ) token = base64 . b64encode ( creds . encode ( ) ) return { 'Authorization' : 'Basic {}' . format ( token . decode ( ) ) }
Return dictionary of http headers necessary for making an http connection to the endpoint of this Connection .
25,247
def https_connection ( self ) : endpoint = self . endpoint host , remainder = endpoint . split ( ':' , 1 ) port = remainder if '/' in remainder : port , _ = remainder . split ( '/' , 1 ) conn = HTTPSConnection ( host , int ( port ) , context = self . _get_ssl ( self . cacert ) , ) path = ( "/model/{}" . format ( self ....
Return an https connection to this Connection s endpoint .
25,248
def connect_params ( self ) : return { 'endpoint' : self . endpoint , 'uuid' : self . uuid , 'username' : self . username , 'password' : self . password , 'cacert' : self . cacert , 'bakery_client' : self . bakery_client , 'loop' : self . loop , 'max_frame_size' : self . max_frame_size , }
Return a tuple of parameters suitable for passing to Connection . connect that can be used to make a new connection to the same controller ( and model if specified . The first element in the returned tuple holds the endpoint argument ; the other holds a dict of the keyword args .
25,249
async def controller ( self ) : return await Connection . connect ( self . endpoint , username = self . username , password = self . password , cacert = self . cacert , bakery_client = self . bakery_client , loop = self . loop , max_frame_size = self . max_frame_size , )
Return a Connection to the controller at self . endpoint
25,250
async def reconnect ( self ) : monitor = self . monitor if monitor . reconnecting . locked ( ) or monitor . close_called . is_set ( ) : return async with monitor . reconnecting : await self . close ( ) await self . _connect_with_login ( [ ( self . endpoint , self . cacert ) ] )
Force a reconnection .
25,251
async def connect ( self , ** kwargs ) : kwargs . setdefault ( 'loop' , self . loop ) kwargs . setdefault ( 'max_frame_size' , self . max_frame_size ) kwargs . setdefault ( 'bakery_client' , self . bakery_client ) if 'macaroons' in kwargs : if not kwargs [ 'bakery_client' ] : kwargs [ 'bakery_client' ] = httpbakery . C...
Connect to an arbitrary Juju model .
25,252
async def connect_controller ( self , controller_name = None ) : if not controller_name : controller_name = self . jujudata . current_controller ( ) if not controller_name : raise JujuConnectionError ( 'No current controller' ) controller = self . jujudata . controllers ( ) [ controller_name ] endpoint = controller [ '...
Connect to a controller by name . If the name is empty it connect to the current controller .
25,253
def bakery_client_for_controller ( self , controller_name ) : bakery_client = self . bakery_client if bakery_client : bakery_client = copy . copy ( bakery_client ) else : bakery_client = httpbakery . Client ( ) bakery_client . cookies = self . jujudata . cookies_for_controller ( controller_name ) return bakery_client
Make a copy of the bakery client with a the appropriate controller s cookiejar in it .
25,254
def _get_ssh_client ( self , host , user , key ) : ssh = paramiko . SSHClient ( ) ssh . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) pkey = None if os . path . exists ( key ) : with open ( key , 'r' ) as f : pkey = paramiko . RSAKey . from_private_key ( f ) try : ssh . connect ( host , port = 22 , usern...
Return a connected Paramiko ssh object .
25,255
def _run_command ( self , ssh , cmd , pty = True ) : if isinstance ( cmd , str ) : cmd = shlex . split ( cmd ) if type ( cmd ) is not list : cmd = [ cmd ] cmds = ' ' . join ( cmd ) stdin , stdout , stderr = ssh . exec_command ( cmds , get_pty = pty ) retcode = stdout . channel . recv_exit_status ( ) if retcode > 0 : ou...
Run a command remotely via SSH .
25,256
def _init_ubuntu_user ( self ) : auth_user = self . user ssh = None try : ssh = self . _get_ssh_client ( self . host , "ubuntu" , self . private_key_path , ) stdout , stderr = self . _run_command ( ssh , "sudo -n true" , pty = False ) except paramiko . ssh_exception . AuthenticationException as e : raise e else : auth_...
Initialize the ubuntu user .
25,257
def _detect_hardware_and_os ( self , ssh ) : info = { 'series' : '' , 'arch' : '' , 'cpu-cores' : '' , 'mem' : '' , } stdout , stderr = self . _run_command ( ssh , [ "sudo" , "/bin/bash -c " + shlex . quote ( DETECTION_SCRIPT ) ] , pty = True , ) lines = stdout . split ( "\n" ) info [ 'series' ] = lines [ 0 ] . strip (...
Detect the target hardware capabilities and OS series .
25,258
def provision_machine ( self ) : params = client . AddMachineParams ( ) if self . _init_ubuntu_user ( ) : try : ssh = self . _get_ssh_client ( self . host , self . user , self . private_key_path ) hw = self . _detect_hardware_and_os ( ssh ) params . series = hw [ 'series' ] params . instance_id = "manual:{}" . format (...
Perform the initial provisioning of the target machine .
25,259
def _run_configure_script ( self , script ) : _ , tmpFile = tempfile . mkstemp ( ) with open ( tmpFile , 'w' ) as f : f . write ( script ) try : ssh = self . _get_ssh_client ( self . host , "ubuntu" , self . private_key_path , ) sftp = paramiko . SFTPClient . from_transport ( ssh . get_transport ( ) ) sftp . put ( tmpF...
Run the script to install the Juju agent on the target machine .
25,260
async def _get_annotations ( entity_tag , connection ) : facade = client . AnnotationsFacade . from_connection ( connection ) result = ( await facade . Get ( [ { "tag" : entity_tag } ] ) ) . results [ 0 ] if result . error is not None : raise JujuError ( result . error ) return result . annotations
Get annotations for the specified entity
25,261
async def _set_annotations ( entity_tag , annotations , connection ) : log . debug ( 'Updating annotations on %s' , entity_tag ) facade = client . AnnotationsFacade . from_connection ( connection ) args = client . EntityAnnotations ( entity = entity_tag , annotations = annotations , ) return await facade . Set ( [ args...
Set annotations on the specified entity .
25,262
def matches ( self , * specs ) : for spec in specs : if ':' in spec : app_name , endpoint_name = spec . split ( ':' ) else : app_name , endpoint_name = spec , None for endpoint in self . endpoints : if app_name == endpoint . application . name and endpoint_name in ( endpoint . name , None ) : break else : return False ...
Check if this relation matches relationship specs .
25,263
async def AddPendingResources ( self , application_tag , charm_url , resources ) : _params = dict ( ) msg = dict ( type = 'Resources' , request = 'AddPendingResources' , version = 1 , params = _params ) _params [ 'tag' ] = application_tag _params [ 'url' ] = charm_url _params [ 'resources' ] = resources reply = await s...
Fix the calling signature of AddPendingResources .
25,264
def bootstrap ( self , controller_name , region = None , agent_version = None , auto_upgrade = False , bootstrap_constraints = None , bootstrap_series = None , config = None , constraints = None , credential = None , default_model = None , keep_broken = False , metadata_source = None , no_gui = False , to = None , uplo...
Initialize a cloud environment .
25,265
def machine ( self ) : machine_id = self . safe_data [ 'machine-id' ] if machine_id : return self . model . machines . get ( machine_id , None ) else : return None
Get the machine object for this unit .
25,266
async def run ( self , command , timeout = None ) : action = client . ActionFacade . from_connection ( self . connection ) log . debug ( 'Running `%s` on %s' , command , self . name ) if timeout : timeout = int ( timeout * 1000000000 ) res = await action . Run ( [ ] , command , [ ] , timeout , [ self . name ] , ) retur...
Run command on this unit .
25,267
async def run_action ( self , action_name , ** params ) : action_facade = client . ActionFacade . from_connection ( self . connection ) log . debug ( 'Starting action `%s` on %s' , action_name , self . name ) res = await action_facade . Enqueue ( [ client . Action ( name = action_name , parameters = params , receiver =...
Run an action on this unit .
25,268
async def scp_to ( self , source , destination , user = 'ubuntu' , proxy = False , scp_opts = '' ) : await self . machine . scp_to ( source , destination , user = user , proxy = proxy , scp_opts = scp_opts )
Transfer files to this unit .
25,269
async def get_metrics ( self ) : metrics = await self . model . get_metrics ( self . tag ) return metrics [ self . name ]
Get metrics for the unit .
25,270
def parse ( constraints ) : if not constraints : return None if type ( constraints ) is dict : return constraints constraints = { normalize_key ( k ) : ( normalize_list_value ( v ) if k in LIST_KEYS else normalize_value ( v ) ) for k , v in [ s . split ( "=" ) for s in constraints . split ( " " ) ] } return constraints
Constraints must be expressed as a string containing only spaces and key value pairs joined by an = .
25,271
async def add_relation ( self , local_relation , remote_relation ) : if ':' not in local_relation : local_relation = '{}:{}' . format ( self . name , local_relation ) return await self . model . add_relation ( local_relation , remote_relation )
Add a relation to another application .
25,272
async def add_unit ( self , count = 1 , to = None ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Adding %s unit%s to %s' , count , '' if count == 1 else 's' , self . name ) result = await app_facade . AddUnits ( application = self . name , placement = parse_placement ...
Add one or more units to this application .
25,273
async def destroy_relation ( self , local_relation , remote_relation ) : if ':' not in local_relation : local_relation = '{}:{}' . format ( self . name , local_relation ) app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Destroying relation %s <-> %s' , local_relation , remo...
Remove a relation to another application .
25,274
async def destroy ( self ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Destroying %s' , self . name ) return await app_facade . Destroy ( self . name )
Remove this application from the model .
25,275
async def expose ( self ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Exposing %s' , self . name ) return await app_facade . Expose ( self . name )
Make this application publicly available over the network .
25,276
async def get_config ( self ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Getting config for %s' , self . name ) return ( await app_facade . Get ( self . name ) ) . config
Return the configuration settings dict for this application .
25,277
async def get_constraints ( self ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Getting constraints for %s' , self . name ) result = ( await app_facade . Get ( self . name ) ) . constraints return vars ( result ) if result else result
Return the machine constraints dict for this application .
25,278
async def get_actions ( self , schema = False ) : actions = { } entity = [ { "tag" : self . tag } ] action_facade = client . ActionFacade . from_connection ( self . connection ) results = ( await action_facade . ApplicationsCharmsActions ( entity ) ) . results for result in results : if result . application_tag == self...
Get actions defined for this application .
25,279
async def get_resources ( self ) : facade = client . ResourcesFacade . from_connection ( self . connection ) response = await facade . ListResources ( [ client . Entity ( self . tag ) ] ) resources = dict ( ) for result in response . results : for resource in result . charm_store_resources or [ ] : resources [ resource...
Return resources for this application .
25,280
async def run ( self , command , timeout = None ) : action = client . ActionFacade . from_connection ( self . connection ) log . debug ( 'Running `%s` on all units of %s' , command , self . name ) return await action . Run ( [ self . name ] , command , [ ] , timeout , [ ] , )
Run command on all units for this application .
25,281
async def set_config ( self , config ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Setting config for %s: %s' , self . name , config ) return await app_facade . Set ( self . name , config )
Set configuration options for this application .
25,282
async def reset_config ( self , to_default ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Restoring default config for %s: %s' , self . name , to_default ) return await app_facade . Unset ( self . name , to_default )
Restore application config to default values .
25,283
async def set_constraints ( self , constraints ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Setting constraints for %s: %s' , self . name , constraints ) return await app_facade . SetConstraints ( self . name , constraints )
Set machine constraints for this application .
25,284
async def unexpose ( self ) : app_facade = client . ApplicationFacade . from_connection ( self . connection ) log . debug ( 'Unexposing %s' , self . name ) return await app_facade . Unexpose ( self . name )
Remove public availability over the network for this application .
25,285
def write_client ( captures , options ) : with open ( "{}/_client.py" . format ( options . output_dir ) , "w" ) as f : f . write ( HEADER ) f . write ( "from juju.client._definitions import *\n\n" ) clients = ", " . join ( "_client{}" . format ( v ) for v in captures ) f . write ( "from juju.client import " + clients +...
Write the TypeFactory classes to _client . py along with some imports and tables so that we can look up versioned Facades .
25,286
def lookup ( self , name , version = None ) : versions = self . get ( name ) if not versions : return None if version : return versions [ version ] return versions [ max ( versions ) ]
If version is omitted max version is used
25,287
def install_package ( package , wheels_path , venv = None , requirement_files = None , upgrade = False , install_args = None ) : requirement_files = requirement_files or [ ] logger . info ( 'Installing %s...' , package ) if venv and not os . path . isdir ( venv ) : raise WagonError ( 'virtualenv {0} does not exist' . f...
Install a Python package .
25,288
def _get_platform_for_set_of_wheels ( wheels_path ) : real_platform = '' for wheel in _get_downloaded_wheels ( wheels_path ) : platform = _get_platform_from_wheel_name ( os . path . join ( wheels_path , wheel ) ) if 'linux' in platform and 'manylinux' not in platform : return platform elif platform != ALL_PLATFORMS_TAG...
For any set of wheel files extracts a single platform .
25,289
def _get_os_properties ( ) : if IS_DISTRO_INSTALLED : return distro . linux_distribution ( full_distribution_name = False ) return platform . linux_distribution ( full_distribution_name = False )
Retrieve distribution properties .
25,290
def _get_env_bin_path ( env_path ) : if IS_VIRTUALENV_INSTALLED : path = virtualenv . path_locations ( env_path ) [ 3 ] else : path = os . path . join ( env_path , 'Scripts' if IS_WIN else 'bin' ) return r'{0}' . format ( path )
Return the bin path for a virtualenv
25,291
def _generate_metadata_file ( workdir , archive_name , platform , python_versions , package_name , package_version , build_tag , package_source , wheels ) : logger . debug ( 'Generating Metadata...' ) metadata = { 'created_by_wagon_version' : _get_wagon_version ( ) , 'archive_name' : archive_name , 'supported_platform'...
Generate a metadata file for the package .
25,292
def _set_archive_name ( package_name , package_version , python_versions , platform , build_tag = '' ) : package_name = package_name . replace ( '-' , '_' ) python_versions = '.' . join ( python_versions ) archive_name_tags = [ package_name , package_version , python_versions , 'none' , platform , ] if build_tag : arch...
Set the format of the output archive file .
25,293
def get_source_name_and_version ( source ) : if os . path . isfile ( os . path . join ( source , 'setup.py' ) ) : package_name , package_version = _get_name_and_version_from_setup ( source ) elif '==' in source : base_name , package_version = source . split ( '==' ) package_name = _get_package_info_from_pypi ( base_nam...
Retrieve the source package s name and version .
25,294
def get_source ( source ) : def extract_source ( source , destination ) : if tarfile . is_tarfile ( source ) : _untar ( source , destination ) elif zipfile . is_zipfile ( source ) : _unzip ( source , destination ) else : raise WagonError ( 'Failed to extract {0}. Please verify that the ' 'provided file is a valid zip o...
Return a pip - installable source
25,295
def create ( source , requirement_files = None , force = False , keep_wheels = False , archive_destination_dir = '.' , python_versions = None , validate_archive = False , wheel_args = '' , archive_format = 'zip' , build_tag = '' ) : if validate_archive : _assert_virtualenv_is_installed ( ) logger . info ( 'Creating arc...
Create a Wagon archive and returns its path .
25,296
def install ( source , venv = None , requirement_files = None , upgrade = False , ignore_platform = False , install_args = '' ) : requirement_files = requirement_files or [ ] logger . info ( 'Installing %s' , source ) processed_source = get_source ( source ) metadata = _get_metadata ( processed_source ) def raise_unsup...
Install a Wagon archive .
25,297
def validate ( source ) : _assert_virtualenv_is_installed ( ) logger . info ( 'Validating %s' , source ) processed_source = get_source ( source ) metadata = _get_metadata ( processed_source ) wheels_path = os . path . join ( processed_source , DEFAULT_WHEELS_PATH ) validation_errors = [ ] logger . debug ( 'Verifying th...
Validate a Wagon archive . Return True if succeeds False otherwise . It also prints a list of all validation errors .
25,298
def show ( source ) : if is_verbose ( ) : logger . info ( 'Retrieving Metadata for: %s' , source ) processed_source = get_source ( source ) metadata = _get_metadata ( processed_source ) shutil . rmtree ( processed_source ) return metadata
Merely returns the metadata for the provided archive .
25,299
def _convert_to_floats ( self , data ) : for key , value in data . items ( ) : data [ key ] = float ( value ) return data
Convert all values in a dict to floats