idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
55,000 | def usable_id ( cls , id ) : try : qry_id = cls . from_dc_code ( id ) if not qry_id : qry_id = cls . from_iso ( id ) if qry_id : cls . deprecated ( 'ISO code for datacenter filter use ' 'dc_code instead' ) if not qry_id : qry_id = cls . from_country ( id ) if not qry_id : qry_id = int ( id ) except Exception : qry_id = None if not qry_id : msg = 'unknown identifier %s' % id cls . error ( msg ) return qry_id | Retrieve id from input which can be ISO name country dc_code . |
55,001 | def find_port ( addr , user ) : import pwd home = pwd . getpwuid ( os . getuid ( ) ) . pw_dir for name in os . listdir ( '%s/.ssh/' % home ) : if name . startswith ( 'unixpipe_%s@%s_' % ( user , addr , ) ) : return int ( name . split ( '_' ) [ 2 ] ) | Find local port in existing tunnels |
55,002 | def new_port ( ) : s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM , socket . IPPROTO_TCP ) for i in range ( 12042 , 16042 ) : try : s . bind ( ( '127.0.0.1' , i ) ) s . close ( ) return i except socket . error : pass raise Exception ( 'No local port available' ) | Find a free local port and allocate it |
55,003 | def _ssh_master_cmd ( addr , user , command , local_key = None ) : ssh_call = [ 'ssh' , '-qNfL%d:127.0.0.1:12042' % find_port ( addr , user ) , '-o' , 'ControlPath=~/.ssh/unixpipe_%%r@%%h_%d' % find_port ( addr , user ) , '-O' , command , '%s@%s' % ( user , addr , ) ] if local_key : ssh_call . insert ( 1 , local_key ) ssh_call . insert ( 1 , '-i' ) return subprocess . call ( ssh_call ) | Exit or check ssh mux |
55,004 | def setup ( addr , user , remote_path , local_key = None ) : port = find_port ( addr , user ) if not port or not is_alive ( addr , user ) : port = new_port ( ) scp ( addr , user , __file__ , '~/unixpipe' , local_key ) ssh_call = [ 'ssh' , '-fL%d:127.0.0.1:12042' % port , '-o' , 'ExitOnForwardFailure=yes' , '-o' , 'ControlPath=~/.ssh/unixpipe_%%r@%%h_%d' % port , '-o' , 'ControlMaster=auto' , '%s@%s' % ( user , addr , ) , 'python' , '~/unixpipe' , 'server' , remote_path ] if local_key : ssh_call . insert ( 1 , local_key ) ssh_call . insert ( 1 , '-i' ) subprocess . call ( ssh_call ) time . sleep ( 1 ) return port | Setup the tunnel |
55,005 | def list ( gandi , limit , step ) : output_keys = [ 'id' , 'type' , 'step' ] options = { 'step' : step , 'items_per_page' : limit , 'sort_by' : 'date_created DESC' } result = gandi . oper . list ( options ) for num , oper in enumerate ( reversed ( result ) ) : if num : gandi . separator_line ( ) output_generic ( gandi , oper , output_keys ) return result | List operations . |
55,006 | def info ( gandi , id ) : output_keys = [ 'id' , 'type' , 'step' , 'last_error' ] oper = gandi . oper . info ( id ) output_generic ( gandi , oper , output_keys ) return oper | Display information about an operation . |
55,007 | def create ( gandi , resource , flags , algorithm , public_key ) : result = gandi . dnssec . create ( resource , flags , algorithm , public_key ) return result | Create DNSSEC key . |
55,008 | def list ( gandi , resource ) : keys = gandi . dnssec . list ( resource ) gandi . pretty_echo ( keys ) return keys | List DNSSEC keys . |
55,009 | def delete ( gandi , resource ) : result = gandi . dnssec . delete ( resource ) gandi . echo ( 'Delete successful.' ) return result | Delete DNSSEC key . |
55,010 | def load_config ( cls ) : config_file = os . path . expanduser ( cls . home_config ) global_conf = cls . load ( config_file , 'global' ) cls . load ( cls . local_config , 'local' ) cls . update_config ( config_file , global_conf ) | Load global and local configuration files and update if needed . |
55,011 | def update_config ( cls , config_file , config ) : need_save = False if 'api' in config and 'env' in config [ 'api' ] : del config [ 'api' ] [ 'env' ] need_save = True ssh_key = config . get ( 'ssh_key' ) sshkeys = config . get ( 'sshkey' ) if ssh_key and not sshkeys : config . update ( { 'sshkey' : [ ssh_key ] } ) need_save = True elif ssh_key and sshkeys : config . update ( { 'sshkey' : sshkeys . append ( ssh_key ) } ) need_save = True if ssh_key : del config [ 'ssh_key' ] need_save = True if need_save : cls . save ( config_file , config ) | Update configuration if needed . |
55,012 | def load ( cls , filename , name = None ) : if not os . path . exists ( filename ) : return { } name = name or filename if name not in cls . _conffiles : with open ( filename ) as fdesc : content = yaml . load ( fdesc , YAMLLoader ) if content is None : content = { } cls . _conffiles [ name ] = content return cls . _conffiles [ name ] | Load yaml configuration from filename . |
55,013 | def save ( cls , filename , config ) : mode = os . O_WRONLY | os . O_TRUNC | os . O_CREAT with os . fdopen ( os . open ( filename , mode , 0o600 ) , 'w' ) as fname : yaml . safe_dump ( config , fname , indent = 4 , default_flow_style = False ) | Save configuration to yaml file . |
55,014 | def get ( cls , key , default = None , separator = '.' , global_ = False ) : if not global_ : ret = os . environ . get ( key . upper ( ) . replace ( '.' , '_' ) ) if ret is not None : return ret scopes = [ 'global' ] if global_ else [ 'local' , 'global' ] for scope in scopes : ret = cls . _get ( scope , key , default , separator ) if ret is not None and ret != default : return ret if ret is None or ret == default : return default | Retrieve a key value from loaded configuration . |
55,015 | def configure ( cls , global_ , key , val ) : scope = 'global' if global_ else 'local' if scope not in cls . _conffiles : cls . _conffiles [ scope ] = { } config = cls . _conffiles . get ( scope , { } ) cls . _set ( scope , key , val ) conf_file = cls . home_config if global_ else cls . local_config cls . save ( os . path . expanduser ( conf_file ) , config ) | Update and save configuration value to file . |
55,016 | def info ( gandi ) : output_keys = [ 'handle' , 'credit' , 'prepaid' ] account = gandi . account . all ( ) account [ 'prepaid_info' ] = gandi . contact . balance ( ) . get ( 'prepaid' , { } ) output_account ( gandi , account , output_keys ) return account | Display information about hosting account . |
55,017 | def create ( cls , ip_version , datacenter , bandwidth , vm = None , vlan = None , ip = None , background = False ) : return Iface . create ( ip_version , datacenter , bandwidth , vlan , vm , ip , background ) | Create a public ip and attach it if vm is given . |
55,018 | def update ( cls , resource , params , background = False ) : cls . echo ( 'Updating your IP' ) result = cls . call ( 'hosting.ip.update' , cls . usable_id ( resource ) , params ) if not background : cls . display_progress ( result ) return result | Update this IP |
55,019 | def delete ( cls , resources , background = False , force = False ) : if not isinstance ( resources , ( list , tuple ) ) : resources = [ resources ] ifaces = [ ] for item in resources : try : ip_ = cls . info ( item ) except UsageError : cls . error ( "Can't find this ip %s" % item ) iface = Iface . info ( ip_ [ 'iface_id' ] ) ifaces . append ( iface [ 'id' ] ) return Iface . delete ( ifaces , background ) | Delete an ip by deleting the iface |
55,020 | def from_ip ( cls , ip ) : ips = dict ( [ ( ip_ [ 'ip' ] , ip_ [ 'id' ] ) for ip_ in cls . list ( { 'items_per_page' : 500 } ) ] ) return ips . get ( ip ) | Retrieve ip id associated to an ip . |
55,021 | def list ( cls , datacenter = None ) : options = { } if datacenter : datacenter_id = int ( Datacenter . usable_id ( datacenter ) ) options [ 'datacenter_id' ] = datacenter_id return cls . call ( 'hosting.vlan.list' , options ) | List virtual machine vlan |
55,022 | def ifaces ( cls , name ) : ifaces = Iface . list ( { 'vlan_id' : cls . usable_id ( name ) } ) ret = [ ] for iface in ifaces : ret . append ( Iface . info ( iface [ 'id' ] ) ) return ret | Get vlan attached ifaces . |
55,023 | def delete ( cls , resources , background = False ) : if not isinstance ( resources , ( list , tuple ) ) : resources = [ resources ] opers = [ ] for item in resources : oper = cls . call ( 'hosting.vlan.delete' , cls . usable_id ( item ) ) if not oper : continue if isinstance ( oper , list ) : opers . extend ( oper ) else : opers . append ( oper ) if background : return opers cls . echo ( 'Deleting your vlan.' ) if opers : cls . display_progress ( opers ) | Delete a vlan . |
55,024 | def create ( cls , name , datacenter , subnet = None , gateway = None , background = False ) : if not background and not cls . intty ( ) : background = True datacenter_id_ = int ( Datacenter . usable_id ( datacenter ) ) vlan_params = { 'name' : name , 'datacenter_id' : datacenter_id_ , } if subnet : vlan_params [ 'subnet' ] = subnet if gateway : vlan_params [ 'gateway' ] = gateway result = cls . call ( 'hosting.vlan.create' , vlan_params ) if not background : cls . echo ( 'Creating your vlan.' ) cls . display_progress ( result ) cls . echo ( 'Your vlan %s has been created.' % name ) return result | Create a new vlan . |
55,025 | def update ( cls , id , params ) : cls . echo ( 'Updating your vlan.' ) result = cls . call ( 'hosting.vlan.update' , cls . usable_id ( id ) , params ) return result | Update an existing vlan . |
55,026 | def from_name ( cls , name ) : result = cls . list ( ) vlans = { } for vlan in result : vlans [ vlan [ 'name' ] ] = vlan [ 'id' ] return vlans . get ( name ) | Retrieve vlan id associated to a name . |
55,027 | def usable_id ( cls , id ) : try : qry_id = int ( id ) except Exception : qry_id = None if not qry_id : msg = 'unknown identifier %s' % id cls . error ( msg ) return qry_id | Retrieve id from input which can be num or id . |
55,028 | def _attach ( cls , iface_id , vm_id ) : oper = cls . call ( 'hosting.vm.iface_attach' , vm_id , iface_id ) return oper | Attach an iface to a vm . |
55,029 | def create ( cls , ip_version , datacenter , bandwidth , vlan , vm , ip , background ) : if not background and not cls . intty ( ) : background = True datacenter_id_ = int ( Datacenter . usable_id ( datacenter ) ) iface_params = { 'ip_version' : ip_version , 'datacenter_id' : datacenter_id_ , 'bandwidth' : bandwidth , } if vlan : iface_params [ 'vlan' ] = Vlan . usable_id ( vlan ) if ip : iface_params [ 'ip' ] = ip result = cls . call ( 'hosting.iface.create' , iface_params ) if background and not vm : return result cls . echo ( 'Creating your iface.' ) cls . display_progress ( result ) iface_info = cls . _info ( result [ 'iface_id' ] ) cls . echo ( 'Your iface has been created with the following IP ' 'addresses:' ) for _ip in iface_info [ 'ips' ] : cls . echo ( 'ip%d:\t%s' % ( _ip [ 'version' ] , _ip [ 'ip' ] ) ) if not vm : return result vm_id = Iaas . usable_id ( vm ) result = cls . _attach ( result [ 'iface_id' ] , vm_id ) if background : return result cls . echo ( 'Attaching your iface.' ) cls . display_progress ( result ) return result | Create a new iface |
55,030 | def _detach ( cls , iface_id ) : iface = cls . _info ( iface_id ) opers = [ ] vm_id = iface . get ( 'vm_id' ) if vm_id : cls . echo ( 'The iface is still attached to the vm %s.' % vm_id ) cls . echo ( 'Will detach it.' ) opers . append ( cls . call ( 'hosting.vm.iface_detach' , vm_id , iface_id ) ) return opers | Detach an iface from a vm . |
55,031 | def update ( cls , id , bandwidth , vm , background ) : if not background and not cls . intty ( ) : background = True iface_params = { } iface_id = cls . usable_id ( id ) if bandwidth : iface_params [ 'bandwidth' ] = bandwidth if iface_params : result = cls . call ( 'hosting.iface.update' , iface_id , iface_params ) if background : return result cls . echo ( 'Updating your iface %s.' % id ) cls . display_progress ( result ) if not vm : return vm_id = Iaas . usable_id ( vm ) opers = cls . _detach ( iface_id ) if opers : cls . echo ( 'Detaching iface.' ) cls . display_progress ( opers ) result = cls . _attach ( iface_id , vm_id ) if background : return result cls . echo ( 'Attaching your iface.' ) cls . display_progress ( result ) | Update this iface . |
55,032 | def get_destinations ( cls , domain , source ) : forwards = cls . list ( domain , { 'items_per_page' : 500 } ) for fwd in forwards : if fwd [ 'source' ] == source : return fwd [ 'destinations' ] return [ ] | Retrieve forward information . |
55,033 | def update ( cls , domain , source , dest_add , dest_del ) : result = None if dest_add or dest_del : current_destinations = cls . get_destinations ( domain , source ) fwds = current_destinations [ : ] if dest_add : for dest in dest_add : if dest not in fwds : fwds . append ( dest ) if dest_del : for dest in dest_del : if dest in fwds : fwds . remove ( dest ) if ( ( len ( current_destinations ) != len ( fwds ) ) or ( current_destinations != fwds ) ) : cls . echo ( 'Updating mail forward %s@%s' % ( source , domain ) ) options = { 'destinations' : fwds } result = cls . call ( 'domain.forward.update' , domain , source , options ) return result | Update a domain mail forward destinations . |
55,034 | def list ( gandi , domain , limit ) : options = { 'items_per_page' : limit } mailboxes = gandi . mail . list ( domain , options ) output_list ( gandi , [ mbox [ 'login' ] for mbox in mailboxes ] ) return mailboxes | List mailboxes created on a domain . |
55,035 | def info ( gandi , email ) : login , domain = email output_keys = [ 'login' , 'aliases' , 'fallback' , 'quota' , 'responder' ] mailbox = gandi . mail . info ( domain , login ) output_mailbox ( gandi , mailbox , output_keys ) return mailbox | Display information about a mailbox . |
55,036 | def delete ( gandi , email , force ) : login , domain = email if not force : proceed = click . confirm ( 'Are you sure to delete the ' 'mailbox %s@%s ?' % ( login , domain ) ) if not proceed : return result = gandi . mail . delete ( domain , login ) return result | Delete a mailbox . |
55,037 | def from_name ( cls , name ) : disks = cls . list ( { 'name' : name } ) if len ( disks ) == 1 : return disks [ 0 ] [ 'id' ] elif not disks : return raise DuplicateResults ( 'disk name %s is ambiguous.' % name ) | Retrieve a disk id associated to a name . |
55,038 | def list_create ( cls , datacenter = None , label = None ) : options = { 'items_per_page' : DISK_MAXLIST } if datacenter : datacenter_id = int ( Datacenter . usable_id ( datacenter ) ) options [ 'datacenter_id' ] = datacenter_id images = cls . safe_call ( 'hosting.disk.list' , options ) if not label : return images return [ img for img in images if label . lower ( ) in img [ 'name' ] . lower ( ) ] | List available disks for vm creation . |
55,039 | def disk_param ( name , size , snapshot_profile , cmdline = None , kernel = None ) : disk_params = { } if cmdline : disk_params [ 'cmdline' ] = cmdline if kernel : disk_params [ 'kernel' ] = kernel if name : disk_params [ 'name' ] = name if snapshot_profile is not None : disk_params [ 'snapshot_profile' ] = snapshot_profile if size : disk_params [ 'size' ] = size return disk_params | Return disk parameter structure . |
55,040 | def update ( cls , resource , name , size , snapshot_profile , background , cmdline = None , kernel = None ) : if isinstance ( size , tuple ) : prefix , size = size if prefix == '+' : disk_info = cls . info ( resource ) current_size = disk_info [ 'size' ] size = current_size + size disk_params = cls . disk_param ( name , size , snapshot_profile , cmdline , kernel ) result = cls . call ( 'hosting.disk.update' , cls . usable_id ( resource ) , disk_params ) if background : return result cls . echo ( 'Updating your disk.' ) cls . display_progress ( result ) | Update this disk . |
55,041 | def _detach ( cls , disk_id ) : disk = cls . _info ( disk_id ) opers = [ ] if disk . get ( 'vms_id' ) : for vm_id in disk [ 'vms_id' ] : cls . echo ( 'The disk is still attached to the vm %s.' % vm_id ) cls . echo ( 'Will detach it.' ) opers . append ( cls . call ( 'hosting.vm.disk_detach' , vm_id , disk_id ) ) return opers | Detach a disk from a vm . |
55,042 | def delete ( cls , resources , background = False ) : if not isinstance ( resources , ( list , tuple ) ) : resources = [ resources ] resources = [ cls . usable_id ( item ) for item in resources ] opers = [ ] for disk_id in resources : opers . extend ( cls . _detach ( disk_id ) ) if opers : cls . echo ( 'Detaching your disk(s).' ) cls . display_progress ( opers ) opers = [ ] for disk_id in resources : oper = cls . call ( 'hosting.disk.delete' , disk_id ) opers . append ( oper ) if background : return opers cls . echo ( 'Deleting your disk.' ) cls . display_progress ( opers ) return opers | Delete this disk . |
55,043 | def _attach ( cls , disk_id , vm_id , options = None ) : options = options or { } oper = cls . call ( 'hosting.vm.disk_attach' , vm_id , disk_id , options ) return oper | Attach a disk to a vm . |
55,044 | def create ( cls , name , vm , size , snapshotprofile , datacenter , source , disk_type = 'data' , background = False ) : if isinstance ( size , tuple ) : prefix , size = size if source : size = None disk_params = cls . disk_param ( name , size , snapshotprofile ) disk_params [ 'datacenter_id' ] = int ( Datacenter . usable_id ( datacenter ) ) disk_params [ 'type' ] = disk_type if source : disk_id = int ( Image . usable_id ( source , disk_params [ 'datacenter_id' ] ) ) result = cls . call ( 'hosting.disk.create_from' , disk_params , disk_id ) else : result = cls . call ( 'hosting.disk.create' , disk_params ) if background and not vm : return result cls . echo ( 'Creating your disk.' ) cls . display_progress ( result ) if not vm : return vm_id = Iaas . usable_id ( vm ) result = cls . _attach ( result [ 'disk_id' ] , vm_id ) if background : return result cls . echo ( 'Attaching your disk.' ) cls . display_progress ( result ) | Create a disk and attach it to a vm . |
55,045 | def compatcallback ( f ) : if getattr ( click , '__version__' , '0.0' ) >= '2.0' : return f return update_wrapper ( lambda ctx , value : f ( ctx , None , value ) , f ) | Compatibility callback decorator for older click version . |
55,046 | def list_sub_commmands ( self , cmd_name , cmd ) : ret = { } if isinstance ( cmd , click . core . Group ) : for sub_cmd_name in cmd . commands : sub_cmd = cmd . commands [ sub_cmd_name ] sub = self . list_sub_commmands ( sub_cmd_name , sub_cmd ) if sub : if isinstance ( sub , dict ) : for n , c in sub . items ( ) : ret [ '%s %s' % ( cmd_name , n ) ] = c else : ret [ '%s %s' % ( cmd_name , sub [ 0 ] ) ] = sub [ 1 ] elif isinstance ( cmd , click . core . Command ) : return ( cmd . name , cmd ) return ret | Return all commands for a group |
55,047 | def load_commands ( self ) : command_folder = os . path . join ( os . path . dirname ( __file__ ) , '..' , 'commands' ) command_dirs = { 'gandi.cli' : command_folder } if 'GANDICLI_PATH' in os . environ : for _path in os . environ . get ( 'GANDICLI_PATH' ) . split ( ':' ) : path = _path . rstrip ( os . sep ) command_dirs [ os . path . basename ( path ) ] = os . path . join ( path , 'commands' ) for module_basename , dir in list ( command_dirs . items ( ) ) : for filename in sorted ( os . listdir ( dir ) ) : if filename . endswith ( '.py' ) and '__init__' not in filename : submod = filename [ : - 3 ] module_name = module_basename + '.commands.' + submod __import__ ( module_name , fromlist = [ module_name ] ) | Load cli commands from submodules . |
55,048 | def invoke ( self , ctx ) : ctx . obj = GandiContextHelper ( verbose = ctx . obj [ 'verbose' ] ) click . Group . invoke ( self , ctx ) | Invoke command in context . |
55,049 | def from_name ( cls , name ) : sshkeys = cls . list ( { 'name' : name } ) if len ( sshkeys ) == 1 : return sshkeys [ 0 ] [ 'id' ] elif not sshkeys : return raise DuplicateResults ( 'sshkey name %s is ambiguous.' % name ) | Retrieve a sshkey id associated to a name . |
55,050 | def usable_id ( cls , id ) : try : qry_id = cls . from_name ( id ) if not qry_id : qry_id = int ( id ) except DuplicateResults as exc : cls . error ( exc . errors ) except Exception : qry_id = None if not qry_id : msg = 'unknown identifier %s' % id cls . error ( msg ) return qry_id | Retrieve id from input which can be name or id . |
55,051 | def create ( cls , name , value ) : sshkey_params = { 'name' : name , 'value' : value , } result = cls . call ( 'hosting.ssh.create' , sshkey_params ) return result | Create a new ssh key . |
55,052 | def get_api_connector ( cls ) : if cls . _api is None : cls . load_config ( ) cls . debug ( 'initialize connection to remote server' ) apihost = cls . get ( 'api.host' ) if not apihost : raise MissingConfiguration ( ) apienv = cls . get ( 'api.env' ) if apienv and apienv in cls . apienvs : apihost = cls . apienvs [ apienv ] cls . _api = XMLRPCClient ( host = apihost , debug = cls . verbose ) return cls . _api | Initialize an api connector for future use . |
55,053 | def call ( cls , method , * args , ** kwargs ) : api = None empty_key = kwargs . pop ( 'empty_key' , False ) try : api = cls . get_api_connector ( ) apikey = cls . get ( 'api.key' ) if not apikey and not empty_key : cls . echo ( "No apikey found, please use 'gandi setup' " "command" ) sys . exit ( 1 ) except MissingConfiguration : if api and empty_key : apikey = '' elif not kwargs . get ( 'safe' ) : cls . echo ( "No configuration found, please use 'gandi setup' " "command" ) sys . exit ( 1 ) else : return [ ] cls . debug ( 'calling method: %s' % method ) for arg in args : cls . debug ( 'with params: %r' % arg ) try : resp = api . request ( method , apikey , * args , ** { 'dry_run' : kwargs . get ( 'dry_run' , False ) , 'return_dry_run' : kwargs . get ( 'return_dry_run' , False ) } ) cls . dump ( 'responded: %r' % resp ) return resp except APICallFailed as err : if kwargs . get ( 'safe' ) : return [ ] if err . code == 530040 : cls . echo ( "Error: It appears you haven't purchased any credits " "yet.\n" "Please visit https://www.gandi.net/credit/buy to " "learn more and buy credits." ) sys . exit ( 1 ) if err . code == 510150 : cls . echo ( "Invalid API key, please use 'gandi setup' command." ) sys . exit ( 1 ) if isinstance ( err , DryRunException ) : if kwargs . get ( 'return_dry_run' , False ) : return err . dry_run else : for msg in err . dry_run : cls . echo ( msg [ 'reason' ] ) cls . echo ( '\t' + ' ' . join ( msg [ 'attr' ] ) ) sys . exit ( 1 ) error = UsageError ( err . errors ) setattr ( error , 'code' , err . code ) raise error | Call a remote api method and return the result . |
55,054 | def safe_call ( cls , method , * args ) : return cls . call ( method , * args , safe = True ) | Call a remote api method but don t raise if an error occurred . |
55,055 | def json_call ( cls , method , url , ** kwargs ) : empty_key = kwargs . pop ( 'empty_key' , False ) send_key = kwargs . pop ( 'send_key' , True ) return_header = kwargs . pop ( 'return_header' , False ) try : apikey = cls . get ( 'apirest.key' ) if not apikey and not empty_key : cls . echo ( "No apikey found for REST API, please use " "'gandi setup' command" ) sys . exit ( 1 ) if send_key : if 'headers' in kwargs : kwargs [ 'headers' ] . update ( { 'X-Api-Key' : apikey } ) else : kwargs [ 'headers' ] = { 'X-Api-Key' : apikey } except MissingConfiguration : if not empty_key : return [ ] cls . debug ( 'calling url: %s %s' % ( method , url ) ) cls . debug ( 'with params: %r' % kwargs ) try : resp , resp_headers = JsonClient . request ( method , url , ** kwargs ) cls . dump ( 'responded: %r' % resp ) if return_header : return resp , resp_headers return resp except APICallFailed as err : cls . echo ( 'An error occured during call: %s' % err . errors ) sys . exit ( 1 ) | Call a remote api using json format |
55,056 | def intty ( cls ) : return True if hasattr ( sys . stdout , 'isatty' ) and sys . stdout . isatty ( ) : return True return False | Check if we are in a tty . |
55,057 | def pretty_echo ( cls , message ) : if cls . intty ( ) : if message : from pprint import pprint pprint ( message ) | Display message using pretty print formatting . |
55,058 | def dump ( cls , message ) : if cls . verbose > 2 : msg = '[DUMP] %s' % message cls . echo ( msg ) | Display dump message if verbose level allows it . |
55,059 | def debug ( cls , message ) : if cls . verbose > 1 : msg = '[DEBUG] %s' % message cls . echo ( msg ) | Display debug message if verbose level allows it . |
55,060 | def log ( cls , message ) : if cls . verbose > 0 : msg = '[INFO] %s' % message cls . echo ( msg ) | Display info message if verbose level allows it . |
55,061 | def exec_output ( cls , command , shell = True , encoding = 'utf-8' ) : proc = Popen ( command , shell = shell , stdout = PIPE ) stdout , _stderr = proc . communicate ( ) if proc . returncode == 0 : return stdout . decode ( encoding ) return '' | Return execution output |
55,062 | def update_progress ( cls , progress , starttime ) : width , _height = click . get_terminal_size ( ) if not width : return duration = datetime . utcnow ( ) - starttime hours , remainder = divmod ( duration . seconds , 3600 ) minutes , seconds = divmod ( remainder , 60 ) size = int ( width * .6 ) status = "" if isinstance ( progress , int ) : progress = float ( progress ) if not isinstance ( progress , float ) : progress = 0 status = 'error: progress var must be float\n' cls . echo ( type ( progress ) ) if progress < 0 : progress = 0 status = 'Halt...\n' if progress >= 1 : progress = 1 block = int ( round ( size * progress ) ) text = ( '\rProgress: [{0}] {1:.2%} {2} {3:0>2}:{4:0>2}:{5:0>2} ' '' . format ( '#' * block + '-' * ( size - block ) , progress , status , hours , minutes , seconds ) ) sys . stdout . write ( text ) sys . stdout . flush ( ) | Display an ascii progress bar while processing operation . |
55,063 | def display_progress ( cls , operations ) : start_crea = datetime . utcnow ( ) if not isinstance ( operations , ( list , tuple ) ) : operations = [ operations ] count_operations = len ( operations ) * 3 updating_done = False while not updating_done : op_score = 0 for oper in operations : op_ret = cls . call ( 'operation.info' , oper [ 'id' ] ) op_step = op_ret [ 'step' ] if op_step in cls . _op_scores : op_score += cls . _op_scores [ op_step ] else : cls . echo ( '' ) msg = 'step %s unknown, exiting' % op_step if op_step == 'ERROR' : msg = ( 'An error has occured during operation ' 'processing: %s' % op_ret [ 'last_error' ] ) elif op_step == 'SUPPORT' : msg = ( 'An error has occured during operation ' 'processing, you must contact Gandi support.' ) cls . echo ( msg ) sys . exit ( 1 ) cls . update_progress ( float ( op_score ) / count_operations , start_crea ) if op_score == count_operations : updating_done = True time . sleep ( cls . _poll_freq ) cls . echo ( '\r' ) | Display progress of Gandi operations . |
55,064 | def load_modules ( self ) : module_folder = os . path . join ( os . path . dirname ( __file__ ) , '..' , 'modules' ) module_dirs = { 'gandi.cli' : module_folder } if 'GANDICLI_PATH' in os . environ : for _path in os . environ . get ( 'GANDICLI_PATH' ) . split ( ':' ) : path = _path . rstrip ( os . sep ) module_dirs [ os . path . basename ( path ) ] = os . path . join ( path , 'modules' ) for module_basename , dir in list ( module_dirs . items ( ) ) : for filename in sorted ( os . listdir ( dir ) ) : if filename . endswith ( '.py' ) and '__init__' not in filename : submod = filename [ : - 3 ] module_name = module_basename + '.modules.' + submod __import__ ( module_name , fromlist = [ module_name ] ) for subclass in GandiModule . __subclasses__ ( ) : self . _modules [ subclass . __name__ . lower ( ) ] = subclass | Import CLI commands modules . |
55,065 | def request ( self , method , apikey , * args , ** kwargs ) : dry_run = kwargs . get ( 'dry_run' , False ) return_dry_run = kwargs . get ( 'return_dry_run' , False ) if return_dry_run : args [ - 1 ] [ '--dry-run' ] = True try : func = getattr ( self . endpoint , method ) return func ( apikey , * args ) except ( socket . error , requests . exceptions . ConnectionError ) : msg = 'Gandi API service is unreachable' raise APICallFailed ( msg ) except xmlrpclib . Fault as err : msg = 'Gandi API has returned an error: %s' % err if dry_run : args [ - 1 ] [ '--dry-run' ] = True ret = func ( apikey , * args ) raise DryRunException ( msg , err . faultCode , ret ) raise APICallFailed ( msg , err . faultCode ) except TypeError as err : msg = 'An unknown error has occurred: %s' % err raise APICallFailed ( msg ) | Make a xml - rpc call to remote API . |
55,066 | def request ( cls , method , url , ** kwargs ) : user_agent = 'gandi.cli/%s' % __version__ headers = { 'User-Agent' : user_agent , 'Content-Type' : 'application/json; charset=utf-8' } if kwargs . get ( 'headers' ) : headers . update ( kwargs . pop ( 'headers' ) ) try : response = requests . request ( method , url , headers = headers , ** kwargs ) response . raise_for_status ( ) try : return response . json ( ) , response . headers except ValueError as err : return response . text , response . headers except ( socket . error , requests . exceptions . ConnectionError ) : msg = 'Remote API service is unreachable' raise APICallFailed ( msg ) except Exception as err : if isinstance ( err , requests . HTTPError ) : try : resp = response . json ( ) except Exception : msg = 'An unknown error has occurred: %s' % err raise APICallFailed ( msg ) if resp . get ( 'message' ) : error = resp . get ( 'message' ) if resp . get ( 'errors' ) : error = cls . format_errors ( resp . get ( 'errors' ) ) msg = '%s: %s' % ( err , error ) else : msg = 'An unknown error has occurred: %s' % err raise APICallFailed ( msg ) | Make a http call to a remote API and return a json response . |
55,067 | def docker ( gandi , vm , args ) : if not [ basedir for basedir in os . getenv ( 'PATH' , '.:/usr/bin' ) . split ( ':' ) if os . path . exists ( '%s/docker' % basedir ) ] : gandi . echo ( ) return if vm : gandi . configure ( True , 'dockervm' , vm ) else : vm = gandi . get ( 'dockervm' ) if not vm : gandi . echo ( ) return return gandi . docker . handle ( vm , args ) | Manage docker instance |
55,068 | def query ( cls , resources , time_range , query , resource_type , sampler ) : if not isinstance ( resources , ( list , tuple ) ) : resources = [ resources ] now = time . time ( ) start_utc = datetime . utcfromtimestamp ( now - time_range ) end_utc = datetime . utcfromtimestamp ( now ) date_format = '%Y-%m-%d %H:%M:%S' start = start_utc . strftime ( date_format ) end = end_utc . strftime ( date_format ) query = { 'start' : start , 'end' : end , 'query' : query , 'resource_id' : resources , 'resource_type' : resource_type , 'sampler' : sampler } return cls . call ( 'hosting.metric.query' , query ) | Query statistics for given resources . |
55,069 | def required_max_memory ( cls , id , memory ) : best = int ( max ( 2 ** math . ceil ( math . log ( memory , 2 ) ) , 2048 ) ) actual_vm = cls . info ( id ) if ( actual_vm [ 'state' ] == 'running' and actual_vm [ 'vm_max_memory' ] != best ) : return best | Recommend a max_memory setting for this vm given memory . If the VM already has a nice setting return None . The max_memory param cannot be fixed too high because page table allocation would cost too much for small memory profile . Use a range as below . |
55,070 | def need_finalize ( cls , resource ) : vm_id = cls . usable_id ( resource ) params = { 'type' : 'hosting_migration_vm' , 'step' : 'RUN' , 'vm_id' : vm_id } result = cls . call ( 'operation.list' , params ) if not result or len ( result ) > 1 : raise MigrationNotFinalized ( 'Cannot find VM %s ' 'migration operation.' % resource ) need_finalize = result [ 0 ] [ 'params' ] [ 'inner_step' ] == 'wait_finalize' if not need_finalize : raise MigrationNotFinalized ( 'VM %s migration does not need ' 'finalization.' % resource ) | Check if vm migration need to be finalized . |
55,071 | def check_can_migrate ( cls , resource ) : vm_id = cls . usable_id ( resource ) result = cls . call ( 'hosting.vm.can_migrate' , vm_id ) if not result [ 'can_migrate' ] : if result [ 'matched' ] : matched = result [ 'matched' ] [ 0 ] cls . echo ( 'Your VM %s cannot be migrated yet. Migration will ' 'be available when datacenter %s is opened.' % ( resource , matched ) ) else : cls . echo ( 'Your VM %s cannot be migrated.' % resource ) return False return True | Check if virtual machine can be migrated to another datacenter . |
55,072 | def from_hostname ( cls , hostname ) : result = cls . list ( { 'hostname' : str ( hostname ) } ) if result : return result [ 0 ] [ 'id' ] | Retrieve virtual machine id associated to a hostname . |
55,073 | def wait_for_sshd ( cls , vm_id ) : cls . echo ( 'Waiting for the vm to come online' ) version , ip_addr = cls . vm_ip ( vm_id ) give_up = time . time ( ) + 300 last_error = None while time . time ( ) < give_up : try : inet = socket . AF_INET if version == 6 : inet = socket . AF_INET6 sd = socket . socket ( inet , socket . SOCK_STREAM , socket . IPPROTO_TCP ) sd . settimeout ( 5 ) sd . connect ( ( ip_addr , 22 ) ) sd . recv ( 1024 ) return except socket . error as err : if err . errno == errno . EHOSTUNREACH and version == 6 : cls . error ( '%s is not reachable, you may be missing ' 'IPv6 connectivity' % ip_addr ) last_error = err time . sleep ( 1 ) except Exception as err : last_error = err time . sleep ( 1 ) cls . error ( 'VM did not spin up (last error: %s)' % last_error ) | Insist on having the vm booted and sshd listening |
55,074 | def ssh_keyscan ( cls , vm_id ) : cls . echo ( 'Wiping old key and learning the new one' ) _version , ip_addr = cls . vm_ip ( vm_id ) cls . execute ( 'ssh-keygen -R "%s"' % ip_addr ) for _ in range ( 5 ) : output = cls . exec_output ( 'ssh-keyscan "%s"' % ip_addr ) if output : with open ( os . path . expanduser ( '~/.ssh/known_hosts' ) , 'a' ) as f : f . write ( output ) return True time . sleep ( .5 ) | Wipe this old key and learn the new one from a freshly created vm . This is a security risk for this VM however we dont have another way to learn the key yet so do this for the user . |
55,075 | def scp ( cls , vm_id , login , identity , local_file , remote_file ) : cmd = [ 'scp' ] if identity : cmd . extend ( ( '-i' , identity , ) ) version , ip_addr = cls . vm_ip ( vm_id ) if version == 6 : ip_addr = '[%s]' % ip_addr cmd . extend ( ( local_file , '%s@%s:%s' % ( login , ip_addr , remote_file ) , ) ) cls . echo ( 'Running %s' % ' ' . join ( cmd ) ) for _ in range ( 5 ) : ret = cls . execute ( cmd , False ) if ret : break time . sleep ( .5 ) return ret | Copy file to remote VM . |
55,076 | def ssh ( cls , vm_id , login , identity , args = None ) : cmd = [ 'ssh' ] if identity : cmd . extend ( ( '-i' , identity , ) ) version , ip_addr = cls . vm_ip ( vm_id ) if version == 6 : cmd . append ( '-6' ) if not ip_addr : cls . echo ( 'No IP address found for vm %s, aborting.' % vm_id ) return cmd . append ( '%s@%s' % ( login , ip_addr , ) ) if args : cmd . extend ( args ) cls . echo ( 'Requesting access using: %s ...' % ' ' . join ( cmd ) ) return cls . execute ( cmd , False ) | Spawn an ssh session to virtual machine . |
55,077 | def is_deprecated ( cls , label , datacenter = None ) : images = cls . list ( datacenter , label ) images_visibility = dict ( [ ( image [ 'label' ] , image [ 'visibility' ] ) for image in images ] ) return images_visibility . get ( label , 'all' ) == 'deprecated' | Check if image if flagged as deprecated . |
55,078 | def from_label ( cls , label , datacenter = None ) : result = cls . list ( datacenter = datacenter ) image_labels = dict ( [ ( image [ 'label' ] , image [ 'disk_id' ] ) for image in result ] ) return image_labels . get ( label ) | Retrieve disk image id associated to a label . |
55,079 | def from_sysdisk ( cls , label ) : disks = cls . safe_call ( 'hosting.disk.list' , { 'name' : label } ) if len ( disks ) : return disks [ 0 ] [ 'id' ] | Retrieve disk id from available system disks |
55,080 | def usable_id ( cls , id , datacenter = None ) : try : qry_id = int ( id ) except Exception : qry_id = cls . from_sysdisk ( id ) or cls . from_label ( id , datacenter ) if not qry_id : msg = 'unknown identifier %s' % id cls . error ( msg ) return qry_id | Retrieve id from input which can be label or id . |
55,081 | def list ( cls , datacenter = None , flavor = None , match = '' , exact_match = False ) : if not datacenter : dc_ids = [ dc [ 'id' ] for dc in Datacenter . filtered_list ( ) ] kmap = { } for dc_id in dc_ids : vals = cls . safe_call ( 'hosting.disk.list_kernels' , dc_id ) for key in vals : kmap . setdefault ( key , [ ] ) . extend ( vals . get ( key , [ ] ) ) for key in kmap : kmap [ key ] = list ( set ( kmap [ key ] ) ) else : dc_id = Datacenter . usable_id ( datacenter ) kmap = cls . safe_call ( 'hosting.disk.list_kernels' , dc_id ) if match : for flav in kmap : if exact_match : kmap [ flav ] = [ x for x in kmap [ flav ] if match == x ] else : kmap [ flav ] = [ x for x in kmap [ flav ] if match in x ] if flavor : if flavor not in kmap : cls . error ( 'flavor %s not supported here' % flavor ) return dict ( [ ( flavor , kmap [ flavor ] ) ] ) return kmap | List available kernels for datacenter . |
55,082 | def is_available ( cls , disk , kernel ) : kmap = cls . list ( disk [ 'datacenter_id' ] , None , kernel , True ) for flavor in kmap : if kernel in kmap [ flavor ] : return True return False | Check if kernel is available for disk . |
55,083 | def clone ( cls , name , vhost , directory , origin ) : paas_info = cls . info ( name ) if 'php' in paas_info [ 'type' ] and not vhost : cls . error ( 'PHP instances require indicating the VHOST to clone ' 'with --vhost <vhost>' ) paas_access = '%s@%s' % ( paas_info [ 'user' ] , paas_info [ 'git_server' ] ) remote_url = 'ssh+git://%s/%s.git' % ( paas_access , vhost ) command = 'git clone %s %s --origin %s' % ( remote_url , directory , origin ) init_git = cls . execute ( command ) if init_git : cls . echo ( 'Use `git push %s master` to push your code to the ' 'instance.' % ( origin ) ) cls . echo ( 'Then `$ gandi deploy` to build and deploy your ' 'application.' ) | Clone a PaaS instance s vhost into a local git repository . |
55,084 | def attach ( cls , name , vhost , remote_name ) : paas_access = cls . get ( 'paas_access' ) if not paas_access : paas_info = cls . info ( name ) paas_access = '%s@%s' % ( paas_info [ 'user' ] , paas_info [ 'git_server' ] ) remote_url = 'ssh+git://%s/%s.git' % ( paas_access , vhost ) ret = cls . execute ( 'git remote add %s %s' % ( remote_name , remote_url , ) ) if ret : cls . echo ( 'Added remote `%s` to your local git repository.' % ( remote_name ) ) cls . echo ( 'Use `git push %s master` to push your code to the ' 'instance.' % ( remote_name ) ) cls . echo ( 'Then `$ gandi deploy` to build and deploy your ' 'application.' ) | Attach an instance s vhost to a remote from the local repository . |
55,085 | def cache ( cls , id ) : sampler = { 'unit' : 'days' , 'value' : 1 , 'function' : 'sum' } query = 'webacc.requests.cache.all' metrics = Metric . query ( id , 60 * 60 * 24 , query , 'paas' , sampler ) cache = { 'hit' : 0 , 'miss' : 0 , 'not' : 0 , 'pass' : 0 } for metric in metrics : what = metric [ 'cache' ] . pop ( ) for point in metric [ 'points' ] : value = point . get ( 'value' , 0 ) cache [ what ] += value return cache | return the number of query cache for the last 24H |
55,086 | def create ( cls , name , size , type , quantity , duration , datacenter , vhosts , password , snapshot_profile , background , sshkey ) : if not background and not cls . intty ( ) : background = True datacenter_id_ = int ( Datacenter . usable_id ( datacenter ) ) paas_params = { 'name' : name , 'size' : size , 'type' : type , 'duration' : duration , 'datacenter_id' : datacenter_id_ , } if password : paas_params [ 'password' ] = password if quantity : paas_params [ 'quantity' ] = quantity paas_params . update ( cls . convert_sshkey ( sshkey ) ) if snapshot_profile : paas_params [ 'snapshot_profile' ] = snapshot_profile result = cls . call ( 'paas.create' , paas_params ) if not background : cls . echo ( 'Creating your PaaS instance.' ) cls . display_progress ( result ) cls . echo ( 'Your PaaS instance %s has been created.' % name ) if vhosts : paas_info = cls . info ( name ) Vhost . create ( paas_info , vhosts , True , background ) return result | Create a new PaaS instance . |
55,087 | def console ( cls , id ) : oper = cls . call ( 'paas.update' , cls . usable_id ( id ) , { 'console' : 1 } ) cls . echo ( 'Activation of the console on your PaaS instance' ) cls . display_progress ( oper ) console_url = Paas . info ( cls . usable_id ( id ) ) [ 'console' ] access = 'ssh %s' % console_url cls . execute ( access ) | Open a console to a PaaS instance . |
55,088 | def from_vhost ( cls , vhost ) : result = Vhost ( ) . list ( ) paas_hosts = { } for host in result : paas_hosts [ host [ 'name' ] ] = host [ 'paas_id' ] return paas_hosts . get ( vhost ) | Retrieve paas instance id associated to a vhost . |
55,089 | def from_hostname ( cls , hostname ) : result = cls . list ( { 'items_per_page' : 500 } ) paas_hosts = { } for host in result : paas_hosts [ host [ 'name' ] ] = host [ 'id' ] return paas_hosts . get ( hostname ) | Retrieve paas instance id associated to a host . |
55,090 | def list_names ( cls ) : ret = dict ( [ ( item [ 'id' ] , item [ 'name' ] ) for item in cls . list ( { 'items_per_page' : 500 } ) ] ) return ret | Retrieve paas id and names . |
55,091 | def from_cn ( cls , common_name ) : result_cn = [ ( cert [ 'id' ] , [ cert [ 'cn' ] ] + cert [ 'altnames' ] ) for cert in cls . list ( { 'status' : [ 'pending' , 'valid' ] , 'items_per_page' : 500 , 'cn' : common_name } ) ] result_alt = [ ( cert [ 'id' ] , [ cert [ 'cn' ] ] + cert [ 'altnames' ] ) for cert in cls . list ( { 'status' : [ 'pending' , 'valid' ] , 'items_per_page' : 500 , 'altname' : common_name } ) ] result = result_cn + result_alt ret = { } for id_ , fqdns in result : for fqdn in fqdns : ret . setdefault ( fqdn , [ ] ) . append ( id_ ) cert_id = ret . get ( common_name ) if not cert_id : return return cert_id | Retrieve a certificate by its common name . |
55,092 | def usable_ids ( cls , id , accept_multi = True ) : try : qry_id = [ int ( id ) ] except ValueError : try : qry_id = cls . from_cn ( id ) except Exception : qry_id = None if not qry_id or not accept_multi and len ( qry_id ) != 1 : msg = 'unknown identifier %s' % id cls . error ( msg ) return qry_id if accept_multi else qry_id [ 0 ] | Retrieve id from input which can be an id or a cn . |
55,093 | def package_list ( cls , options = None ) : options = options or { } try : return cls . safe_call ( 'cert.package.list' , options ) except UsageError as err : if err . code == 150020 : return [ ] raise | List possible certificate packages . |
55,094 | def advice_dcv_method ( cls , csr , package , altnames , dcv_method , cert_id = None ) : params = { 'csr' : csr , 'package' : package , 'dcv_method' : dcv_method } if cert_id : params [ 'cert_id' ] = cert_id result = cls . call ( 'cert.get_dcv_params' , params ) if dcv_method == 'dns' : cls . echo ( 'You have to add these records in your domain zone :' ) cls . echo ( '\n' . join ( result [ 'message' ] ) ) | Display dcv_method information . |
55,095 | def create_csr ( cls , common_name , private_key = None , params = None ) : params = params or [ ] params = [ ( key , val ) for key , val in params if val ] subj = '/' + '/' . join ( [ '=' . join ( value ) for value in params ] ) cmd , private_key = cls . gen_pk ( common_name , private_key ) if private_key . endswith ( '.crt' ) or private_key . endswith ( '.key' ) : csr_file = re . sub ( r'\.(crt|key)$' , '.csr' , private_key ) else : csr_file = private_key + '.csr' cmd = cmd % { 'csr' : csr_file , 'key' : private_key , 'subj' : subj } result = cls . execute ( cmd ) if not result : cls . echo ( 'CSR creation failed' ) cls . echo ( cmd ) return return csr_file | Create CSR . |
55,096 | def get_common_name ( cls , csr ) : from tempfile import NamedTemporaryFile fhandle = NamedTemporaryFile ( ) fhandle . write ( csr . encode ( 'latin1' ) ) fhandle . flush ( ) output = cls . exec_output ( 'openssl req -noout -subject -in %s' % fhandle . name ) if not output : return common_name = output . split ( '=' ) [ - 1 ] . strip ( ) fhandle . close ( ) return common_name | Read information from CSR . |
55,097 | def process_csr ( cls , common_name , csr = None , private_key = None , country = None , state = None , city = None , organisation = None , branch = None ) : if csr : if branch or organisation or city or state or country : cls . echo ( 'Following options are only used to generate' ' the CSR.' ) else : params = ( ( 'CN' , common_name ) , ( 'OU' , branch ) , ( 'O' , organisation ) , ( 'L' , city ) , ( 'ST' , state ) , ( 'C' , country ) ) params = [ ( key , val ) for key , val in params if val ] csr = cls . create_csr ( common_name , private_key , params ) if csr and os . path . exists ( csr ) : with open ( csr ) as fcsr : csr = fcsr . read ( ) return csr | Create a PK and a CSR if needed . |
55,098 | def pretty_format_cert ( cls , cert ) : crt = cert . get ( 'cert' ) if crt : crt = ( '-----BEGIN CERTIFICATE-----\n' + '\n' . join ( [ crt [ index * 64 : ( index + 1 ) * 64 ] for index in range ( int ( len ( crt ) / 64 ) + 1 ) ] ) . rstrip ( '\n' ) + '\n-----END CERTIFICATE-----' ) return crt | Pretty display of a certificate . |
55,099 | def info ( gandi , resource , format ) : result = gandi . webacc . info ( resource ) if format : output_json ( gandi , format , result ) return result output_base = { 'name' : result [ 'name' ] , 'algorithm' : result [ 'lb' ] [ 'algorithm' ] , 'datacenter' : result [ 'datacenter' ] [ 'name' ] , 'state' : result [ 'state' ] , 'ssl' : 'Disable' if result [ 'ssl_enable' ] is False else 'Enabled' } output_keys = [ 'name' , 'state' , 'datacenter' , 'ssl' , 'algorithm' ] output_generic ( gandi , output_base , output_keys , justify = 14 ) gandi . echo ( 'Vhosts :' ) for vhost in result [ 'vhosts' ] : output_vhosts = [ 'vhost' , 'ssl' ] vhost [ 'vhost' ] = vhost [ 'name' ] vhost [ 'ssl' ] = 'None' if vhost [ 'cert_id' ] is None else 'Exists' output_sub_generic ( gandi , vhost , output_vhosts , justify = 14 ) gandi . echo ( '' ) gandi . echo ( 'Backends :' ) for server in result [ 'servers' ] : try : ip = gandi . ip . info ( server [ 'ip' ] ) iface = gandi . iface . info ( ip [ 'iface_id' ] ) server [ 'name' ] = gandi . iaas . info ( iface [ 'vm_id' ] ) [ 'hostname' ] output_servers = [ 'name' , 'ip' , 'port' , 'state' ] except Exception : warningmsg = ( '\tBackend with ip address %s no longer exists.' '\n\tYou should remove it.' % server [ 'ip' ] ) gandi . echo ( warningmsg ) output_servers = [ 'ip' , 'port' , 'state' ] output_sub_generic ( gandi , server , output_servers , justify = 14 ) gandi . echo ( '' ) gandi . echo ( 'Probe :' ) output_probe = [ 'state' , 'host' , 'interval' , 'method' , 'response' , 'threshold' , 'timeout' , 'url' , 'window' ] result [ 'probe' ] [ 'state' ] = ( 'Disable' if result [ 'probe' ] [ 'enable' ] is False else 'Enabled' ) output_sub_generic ( gandi , result [ 'probe' ] , output_probe , justify = 14 ) return result | Display information about a webaccelerator |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.