idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
243,800 | def close ( self ) : if self . debug : time . sleep ( 10 ) for host in self . workers : host . close ( ) for broker in self . brokers : try : broker . close ( ) except AttributeError : pass scoop . logger . info ( 'Finished cleaning spawned subprocesses.' ) | Subprocess cleanup . |
243,801 | def processConfig ( self , worker_config ) : self . config [ 'headless' ] |= worker_config . get ( "headless" , False ) if self . config [ 'headless' ] : if not self . discovery_thread : self . discovery_thread = discovery . Advertise ( port = "," . join ( str ( a ) for a in self . getPorts ( ) ) , ) | Update the pool configuration with a worker configuration . |
243,802 | def main ( self ) : if self . args is None : self . parse ( ) self . log = utils . initLogging ( self . verbose ) if self . args . workingDirectory : os . chdir ( self . args . workingDirectory ) if not self . args . brokerHostname : self . log . info ( "Discovering SCOOP Brokers on network..." ) pools = discovery . Se... | Bootstrap an arbitrary script . If no agruments were passed use discovery module to search and connect to a broker . |
243,803 | def makeParser ( self ) : self . parser = argparse . ArgumentParser ( description = 'Starts the executable.' , prog = ( "{0} -m scoop.bootstrap" ) . format ( sys . executable ) ) self . parser . add_argument ( '--origin' , help = "To specify that the worker is the origin" , action = 'store_true' ) self . parser . add_a... | Generate the argparse parser object containing the bootloader accepted parameters |
243,804 | def parse ( self ) : if self . parser is None : self . makeParser ( ) self . args = self . parser . parse_args ( ) self . verbose = self . args . verbose | Generate a argparse parser and parse the command - line arguments |
243,805 | def setScoop ( self ) : scoop . IS_RUNNING = True scoop . IS_ORIGIN = self . args . origin scoop . BROKER = BrokerInfo ( self . args . brokerHostname , self . args . taskPort , self . args . metaPort , self . args . externalBrokerHostname if self . args . externalBrokerHostname else self . args . brokerHostname , ) sco... | Setup the SCOOP constants . |
243,806 | def myFunc ( parameter ) : print ( 'Hello World from {0}!' . format ( scoop . worker ) ) print ( shared . getConst ( 'myVar' ) [ 2 ] ) return parameter + 1 | This function will be executed on the remote host even if it was not available at launch . |
243,807 | def sendResult ( self , future ) : future = copy . copy ( future ) future . callable = future . args = future . kargs = future . greenlet = None if not future . sendResultBack : future . resultValue = None self . _sendReply ( future . id . worker , pickle . dumps ( future , pickle . HIGHEST_PROTOCOL , ) , ) | Send a terminated future back to its parent . |
243,808 | def getSize ( string ) : try : with urllib . request . urlopen ( string , None , 1 ) as f : return sum ( len ( line ) for line in f ) except ( urllib . error . URLError , socket . timeout ) as e : return 0 | This functions opens a web sites and then calculate the total size of the page in bytes . This is for the sake of the example . Do not use this technique in real code as it is not a very bright way to do this . |
243,809 | def getValue ( words ) : value = 0 for word in words : for letter in word : value += shared . getConst ( 'lettersValue' ) [ letter ] return value | Computes the sum of the values of the words . |
243,810 | def _run_module_code ( code , init_globals = None , mod_name = None , mod_fname = None , mod_loader = None , pkg_name = None ) : with _ModifiedArgv0 ( mod_fname ) : with _TempModule ( mod_name ) as temp_module : mod_globals = temp_module . module . __dict__ _run_code ( code , mod_globals , init_globals , mod_name , mod... | Helper to run code in new namespace with sys modified |
243,811 | def run_module ( mod_name , init_globals = None , run_name = None , alter_sys = False ) : mod_name , loader , code , fname = _get_module_details ( mod_name ) if run_name is None : run_name = mod_name pkg_name = mod_name . rpartition ( '.' ) [ 0 ] if alter_sys : return _run_module_code ( code , init_globals , run_name ,... | Execute a module s code without importing it |
243,812 | def _get_importer ( path_name ) : cache = sys . path_importer_cache try : importer = cache [ path_name ] except KeyError : cache [ path_name ] = None for hook in sys . path_hooks : try : importer = hook ( path_name ) break except ImportError : pass else : try : importer = imp . NullImporter ( path_name ) except ImportE... | Python version of PyImport_GetImporter C API function |
243,813 | def run_path ( path_name , init_globals = None , run_name = None ) : if run_name is None : run_name = "<run_path>" importer = _get_importer ( path_name ) if isinstance ( importer , imp . NullImporter ) : code = _get_code_from_file ( path_name ) return _run_module_code ( code , init_globals , run_name , path_name ) else... | Execute code located at the specified filesystem location |
243,814 | def maxTreeDepthDivide ( rootValue , currentDepth = 0 , parallelLevel = 2 ) : thisRoot = shared . getConst ( 'myTree' ) . search ( rootValue ) if currentDepth >= parallelLevel : return thisRoot . maxDepth ( currentDepth ) else : if not any ( [ thisRoot . left , thisRoot . right ] ) : return currentDepth if not all ( [ ... | Finds a tree node that represents rootValue and computes the max depth of this tree branch . This function will emit new futures until currentDepth = parallelLevel |
243,815 | def insert ( self , value ) : if not self . payload or value == self . payload : self . payload = value else : if value <= self . payload : if self . left : self . left . insert ( value ) else : self . left = BinaryTreeNode ( value ) else : if self . right : self . right . insert ( value ) else : self . right = BinaryT... | Insert a value in the tree |
243,816 | def maxDepth ( self , currentDepth = 0 ) : if not any ( ( self . left , self . right ) ) : return currentDepth result = 0 for child in ( self . left , self . right ) : if child : result = max ( result , child . maxDepth ( currentDepth + 1 ) ) return result | Compute the depth of the longest branch of the tree |
243,817 | def search ( self , value ) : if self . payload == value : return self else : if value <= self . payload : if self . left : return self . left . search ( value ) else : if self . right : return self . right . search ( value ) return None | Find an element in the tree |
243,818 | def createZMQSocket ( self , sock_type ) : sock = self . ZMQcontext . socket ( sock_type ) sock . setsockopt ( zmq . LINGER , LINGER_TIME ) sock . setsockopt ( zmq . IPV4ONLY , 0 ) sock . setsockopt ( zmq . SNDHWM , 0 ) sock . setsockopt ( zmq . RCVHWM , 0 ) try : sock . setsockopt ( zmq . IMMEDIATE , 1 ) except : pass... | Create a socket of the given sock_type and deactivate message dropping |
243,819 | def _reportFutures ( self ) : try : while True : time . sleep ( scoop . TIME_BETWEEN_STATUS_REPORTS ) fids = set ( x . id for x in scoop . _control . execQueue . movable ) fids . update ( set ( x . id for x in scoop . _control . execQueue . ready ) ) fids . update ( set ( x . id for x in scoop . _control . execQueue . ... | Sends futures status updates to broker at intervals of scoop . TIME_BETWEEN_STATUS_REPORTS seconds . Is intended to be run by a separate thread . |
243,820 | def _sendReply ( self , destination , fid , * args ) : self . addPeer ( destination ) try : self . direct_socket . send_multipart ( [ destination , REPLY , ] + list ( args ) , flags = zmq . NOBLOCK ) except zmq . error . ZMQError as e : scoop . logger . debug ( "{0}: Could not send result directly to peer {1}, routing ... | Send a REPLY directly to its destination . If it doesn t work launch it back to the broker . |
243,821 | def _startup ( rootFuture , * args , ** kargs ) : import greenlet global _controller _controller = greenlet . greenlet ( control . runController ) try : result = _controller . switch ( rootFuture , * args , ** kargs ) except scoop . _comm . Shutdown : result = None control . execQueue . shutdown ( ) return result | Initializes the SCOOP environment . |
243,822 | def _recursiveReduce ( mapFunc , reductionFunc , scan , * iterables ) : if iterables : half = min ( len ( x ) // 2 for x in iterables ) data_left = [ list ( x ) [ : half ] for x in iterables ] data_right = [ list ( x ) [ half : ] for x in iterables ] else : data_left = data_right = [ [ ] ] out_futures = [ None , None ]... | Generates the recursive reduction tree . Used by mapReduce . |
243,823 | def _createFuture ( func , * args , ** kwargs ) : assert callable ( func ) , ( "The provided func parameter is not a callable." ) if scoop . IS_ORIGIN and "SCOOP_WORKER" not in sys . modules : sys . modules [ "SCOOP_WORKER" ] = sys . modules [ "__main__" ] lambdaType = type ( lambda : None ) funcIsLambda = isinstance (... | Helper function to create a future . |
243,824 | def _waitAny ( * children ) : n = len ( children ) for index , future in enumerate ( children ) : if future . exceptionValue : raise future . exceptionValue if future . _ended ( ) : future . _delete ( ) yield future n -= 1 else : future . index = index future = control . current while n > 0 : future . stopWatch . halt ... | Waits on any child Future created by the calling Future . |
243,825 | def wait ( fs , timeout = - 1 , return_when = ALL_COMPLETED ) : DoneAndNotDoneFutures = namedtuple ( 'DoneAndNotDoneFutures' , 'done not_done' ) if timeout < 0 : if return_when == FIRST_COMPLETED : next ( _waitAny ( * fs ) ) elif return_when in [ ALL_COMPLETED , FIRST_EXCEPTION ] : for _ in _waitAll ( * fs ) : pass don... | Wait for the futures in the given sequence to complete . Using this function may prevent a worker from executing . |
243,826 | def advertiseBrokerWorkerDown ( exctype , value , traceback ) : if not scoop . SHUTDOWN_REQUESTED : execQueue . shutdown ( ) sys . __excepthook__ ( exctype , value , traceback ) | Hook advertizing the broker if an impromptu shutdown is occuring . |
243,827 | def delFutureById ( futureId , parentId ) : try : del futureDict [ futureId ] except KeyError : pass try : toDel = [ a for a in futureDict [ parentId ] . children if a . id == futureId ] for f in toDel : del futureDict [ parentId ] . children [ f ] except KeyError : pass | Delete future on id basis |
243,828 | def delFuture ( afuture ) : try : del futureDict [ afuture . id ] except KeyError : pass try : del futureDict [ afuture . parentId ] . children [ afuture ] except KeyError : pass | Delete future afuture |
243,829 | def runFuture ( future ) : global debug_stats global QueueLength if scoop . DEBUG : init_debug ( ) debug_stats [ future . id ] [ 'start_time' ] . append ( time . time ( ) ) future . waitTime = future . stopWatch . get ( ) future . stopWatch . reset ( ) try : uniqueReference = [ cb . groupID for cb in future . callback ... | Callable greenlet in charge of running tasks . |
243,830 | def runController ( callable_ , * args , ** kargs ) : global execQueue rootId = ( - 1 , 0 ) if execQueue is None : execQueue = FutureQueue ( ) sys . excepthook = advertiseBrokerWorkerDown if scoop . DEBUG : from scoop import _debug _debug . redirectSTDOUTtoDebugFile ( ) headless = scoop . CONFIGURATION . get ( "headles... | Callable greenlet implementing controller logic . |
243,831 | def mode ( self ) : mu = self . mean ( ) sigma = self . std ( ) ret_val = math . exp ( mu - sigma ** 2 ) if math . isnan ( ret_val ) : ret_val = float ( "inf" ) return ret_val | Computes the mode of a log - normal distribution built with the stats data . |
243,832 | def median ( self ) : mu = self . mean ( ) ret_val = math . exp ( mu ) if math . isnan ( ret_val ) : ret_val = float ( "inf" ) return ret_val | Computes the median of a log - normal distribution built with the stats data . |
243,833 | def _decode_string ( buf , pos ) : for i in range ( pos , len ( buf ) ) : if buf [ i : i + 1 ] == _compat_bytes ( '\x00' ) : try : return ( buf [ pos : i ] . decode ( _CHARSET ) , i + 1 ) except UnicodeDecodeError : raise MinusconfError ( 'Not a valid ' + _CHARSET + ' string: ' + repr ( buf [ pos : i ] ) ) raise Minusc... | Decodes a string in the buffer buf starting at position pos . Returns a tupel of the read string and the next byte to read . |
243,834 | def _find_sock ( ) : if socket . has_ipv6 : try : return socket . socket ( socket . AF_INET6 , socket . SOCK_DGRAM ) except socket . gaierror : pass return socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) | Create a UDP socket |
243,835 | def _compat_inet_pton ( family , addr ) : if family == socket . AF_INET : res = _compat_bytes ( '' ) parts = addr . split ( '.' ) if len ( parts ) != 4 : raise ValueError ( 'Expected 4 dot-separated numbers' ) for part in parts : intval = int ( part , 10 ) if intval < 0 or intval > 0xff : raise ValueError ( "Invalid in... | socket . inet_pton for platforms that don t have it |
243,836 | def start_blocking ( self ) : self . _cav_started . clear ( ) self . start ( ) self . _cav_started . wait ( ) | Start the advertiser in the background but wait until it is ready |
243,837 | def _send_queries ( self ) : res = 0 addrs = _resolve_addrs ( self . addresses , self . port , self . ignore_senderrors , [ self . _sock . family ] ) for addr in addrs : try : self . _send_query ( addr [ 1 ] ) res += 1 except : if not self . ignore_senderrors : raise return res | Sends queries to multiple addresses . Returns the number of successful queries . |
243,838 | def clean ( self ) : raise forms . ValidationError ( self . error_messages [ 'invalid_login' ] , code = 'invalid_login' , params = { 'username' : self . username_field . verbose_name } ) | Always raise the default error message because we don t care what they entered here . |
243,839 | def types ( ** requirements ) : def predicate ( args ) : for name , kind in sorted ( requirements . items ( ) ) : assert hasattr ( args , name ) , "missing required argument `%s`" % name if not isinstance ( kind , tuple ) : kind = ( kind , ) if not any ( isinstance ( getattr ( args , name ) , k ) for k in kind ) : retu... | Specify a precondition based on the types of the function s arguments . |
243,840 | def ensure ( arg1 , arg2 = None ) : assert ( isinstance ( arg1 , str ) and isfunction ( arg2 ) ) or ( isfunction ( arg1 ) and arg2 is None ) description = "" predicate = lambda x : x if isinstance ( arg1 , str ) : description = arg1 predicate = arg2 else : description = get_function_source ( arg1 ) predicate = arg1 ret... | Specify a precondition described by description and tested by predicate . |
243,841 | def invariant ( arg1 , arg2 = None ) : desc = "" predicate = lambda x : x if isinstance ( arg1 , str ) : desc = arg1 predicate = arg2 else : desc = get_function_source ( arg1 ) predicate = arg1 def invariant ( c ) : def check ( name , func ) : exceptions = ( "__getitem__" , "__setitem__" , "__lt__" , "__le__" , "__eq__... | Specify a class invariant described by description and tested by predicate . |
243,842 | def mkpassword ( length = 16 , chars = None , punctuation = None ) : if chars is None : chars = string . ascii_letters + string . digits data = [ random . choice ( chars ) for _ in range ( length ) ] if punctuation : data = data [ : - punctuation ] for _ in range ( punctuation ) : data . append ( random . choice ( PUNC... | Generates a random ascii string - useful to generate authinfos |
243,843 | def disk_check_size ( ctx , param , value ) : if value : if isinstance ( value , tuple ) : val = value [ 1 ] else : val = value if val % 1024 : raise click . ClickException ( 'Size must be a multiple of 1024.' ) return value | Validation callback for disk size parameter . |
243,844 | def create ( cls , fqdn , flags , algorithm , public_key ) : fqdn = fqdn . lower ( ) params = { 'flags' : flags , 'algorithm' : algorithm , 'public_key' : public_key , } result = cls . call ( 'domain.dnssec.create' , fqdn , params ) return result | Create a dnssec key . |
243,845 | def from_name ( cls , name ) : snps = cls . list ( { 'name' : name } ) if len ( snps ) == 1 : return snps [ 0 ] [ 'id' ] elif not snps : return raise DuplicateResults ( 'snapshot profile name %s is ambiguous.' % name ) | Retrieve a snapshot profile accsociated to a name . |
243,846 | def list ( cls , options = None , target = None ) : options = options or { } result = [ ] if not target or target == 'paas' : for profile in cls . safe_call ( 'paas.snapshotprofile.list' , options ) : profile [ 'target' ] = 'paas' result . append ( ( profile [ 'id' ] , profile ) ) if not target or target == 'vm' : for ... | List all snapshot profiles . |
243,847 | def records ( cls , fqdn , sort_by = None , text = False ) : meta = cls . get_fqdn_info ( fqdn ) url = meta [ 'domain_records_href' ] kwargs = { } if text : kwargs = { 'headers' : { 'Accept' : 'text/plain' } } return cls . json_get ( cls . get_sort_url ( url , sort_by ) , ** kwargs ) | Display records information about a domain . |
243,848 | def add_record ( cls , fqdn , name , type , value , ttl ) : data = { "rrset_name" : name , "rrset_type" : type , "rrset_values" : value , } if ttl : data [ 'rrset_ttl' ] = int ( ttl ) meta = cls . get_fqdn_info ( fqdn ) url = meta [ 'domain_records_href' ] return cls . json_post ( url , data = json . dumps ( data ) ) | Create record for a domain . |
243,849 | def update_record ( cls , fqdn , name , type , value , ttl , content ) : data = { "rrset_name" : name , "rrset_type" : type , "rrset_values" : value , } if ttl : data [ 'rrset_ttl' ] = int ( ttl ) meta = cls . get_fqdn_info ( fqdn ) if content : url = meta [ 'domain_records_href' ] kwargs = { 'headers' : { 'Content-Typ... | Update all records for a domain . |
243,850 | def del_record ( cls , fqdn , name , type ) : meta = cls . get_fqdn_info ( fqdn ) url = meta [ 'domain_records_href' ] delete_url = url if name : delete_url = '%s/%s' % ( delete_url , name ) if type : delete_url = '%s/%s' % ( delete_url , type ) return cls . json_delete ( delete_url ) | Delete record for a domain . |
243,851 | def keys ( cls , fqdn , sort_by = None ) : meta = cls . get_fqdn_info ( fqdn ) url = meta [ 'domain_keys_href' ] return cls . json_get ( cls . get_sort_url ( url , sort_by ) ) | Display keys information about a domain . |
243,852 | def keys_info ( cls , fqdn , key ) : return cls . json_get ( '%s/domains/%s/keys/%s' % ( cls . api_url , fqdn , key ) ) | Retrieve key information . |
243,853 | def keys_create ( cls , fqdn , flag ) : data = { "flags" : flag , } meta = cls . get_fqdn_info ( fqdn ) url = meta [ 'domain_keys_href' ] ret , headers = cls . json_post ( url , data = json . dumps ( data ) , return_header = True ) return cls . json_get ( headers [ 'location' ] ) | Create new key entry for a domain . |
243,854 | def list ( gandi , datacenter , id , subnet , gateway ) : output_keys = [ 'name' , 'state' , 'dc' ] if id : output_keys . append ( 'id' ) if subnet : output_keys . append ( 'subnet' ) if gateway : output_keys . append ( 'gateway' ) datacenters = gandi . datacenter . list ( ) vlans = gandi . vlan . list ( datacenter ) f... | List vlans . |
243,855 | def info ( gandi , resource , ip ) : output_keys = [ 'name' , 'state' , 'dc' , 'subnet' , 'gateway' ] datacenters = gandi . datacenter . list ( ) vlan = gandi . vlan . info ( resource ) gateway = vlan [ 'gateway' ] if not ip : output_vlan ( gandi , vlan , datacenters , output_keys , justify = 11 ) return vlan gateway_e... | Display information about a vlan . |
243,856 | def create ( gandi , name , datacenter , subnet , gateway , background ) : try : gandi . datacenter . is_opened ( datacenter , 'iaas' ) except DatacenterLimited as exc : gandi . echo ( '/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % ( datacenter , exc . date ) ) result = gandi .... | Create a new vlan |
243,857 | def update ( gandi , resource , name , gateway , create , bandwidth ) : params = { } if name : params [ 'name' ] = name vlan_id = gandi . vlan . usable_id ( resource ) try : if gateway : IP ( gateway ) params [ 'gateway' ] = gateway except ValueError : vm = gandi . iaas . info ( gateway ) ips = [ ip for sublist in [ [ ... | Update a vlan |
243,858 | def list_migration_choice ( cls , datacenter ) : datacenter_id = cls . usable_id ( datacenter ) dc_list = cls . list ( ) available_dcs = [ dc for dc in dc_list if dc [ 'id' ] == datacenter_id ] [ 0 ] [ 'can_migrate_to' ] choices = [ dc for dc in dc_list if dc [ 'id' ] in available_dcs ] return choices | List available datacenters for migration from given datacenter . |
243,859 | def is_opened ( cls , dc_code , type_ ) : options = { 'dc_code' : dc_code , '%s_opened' % type_ : True } datacenters = cls . safe_call ( 'hosting.datacenter.list' , options ) if not datacenters : options = { 'iso' : dc_code , '%s_opened' % type_ : True } datacenters = cls . safe_call ( 'hosting.datacenter.list' , optio... | List opened datacenters for given type . |
243,860 | def filtered_list ( cls , name = None , obj = None ) : options = { } if name : options [ 'id' ] = cls . usable_id ( name ) def obj_ok ( dc , obj ) : if not obj or obj [ 'datacenter_id' ] == dc [ 'id' ] : return True return False return [ x for x in cls . list ( options ) if obj_ok ( x , obj ) ] | List datacenters matching name and compatible with obj |
243,861 | def from_iso ( cls , iso ) : result = cls . list ( { 'sort_by' : 'id ASC' } ) dc_isos = { } for dc in result : if dc [ 'iso' ] not in dc_isos : dc_isos [ dc [ 'iso' ] ] = dc [ 'id' ] return dc_isos . get ( iso ) | Retrieve the first datacenter id associated to an ISO . |
243,862 | def from_name ( cls , name ) : result = cls . list ( ) dc_names = { } for dc in result : dc_names [ dc [ 'name' ] ] = dc [ 'id' ] return dc_names . get ( name ) | Retrieve datacenter id associated to a name . |
243,863 | def from_country ( cls , country ) : result = cls . list ( { 'sort_by' : 'id ASC' } ) dc_countries = { } for dc in result : if dc [ 'country' ] not in dc_countries : dc_countries [ dc [ 'country' ] ] = dc [ 'id' ] return dc_countries . get ( country ) | Retrieve the first datacenter id associated to a country . |
243,864 | def from_dc_code ( cls , dc_code ) : result = cls . list ( ) dc_codes = { } for dc in result : if dc . get ( 'dc_code' ) : dc_codes [ dc [ 'dc_code' ] ] = dc [ 'id' ] return dc_codes . get ( dc_code ) | Retrieve the datacenter id associated to a dc_code |
243,865 | 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 =... | Retrieve id from input which can be ISO name country dc_code . |
243,866 | 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 |
243,867 | 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 |
243,868 | 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 ) ... | Exit or check ssh mux |
243,869 | 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' , 'Cont... | Setup the tunnel |
243,870 | 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 ... | List operations . |
243,871 | 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 . |
243,872 | def create ( gandi , resource , flags , algorithm , public_key ) : result = gandi . dnssec . create ( resource , flags , algorithm , public_key ) return result | Create DNSSEC key . |
243,873 | def list ( gandi , resource ) : keys = gandi . dnssec . list ( resource ) gandi . pretty_echo ( keys ) return keys | List DNSSEC keys . |
243,874 | def delete ( gandi , resource ) : result = gandi . dnssec . delete ( resource ) gandi . echo ( 'Delete successful.' ) return result | Delete DNSSEC key . |
243,875 | 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 . |
243,876 | 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 ] } ) nee... | Update configuration if needed . |
243,877 | 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 . _co... | Load yaml configuration from filename . |
243,878 | 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 . |
243,879 | 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 ,... | Retrieve a key value from loaded configuration . |
243,880 | 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 . p... | Update and save configuration value to file . |
243,881 | 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 . |
243,882 | 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 . |
243,883 | 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 |
243,884 | 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... | Delete an ip by deleting the iface |
243,885 | 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 . |
243,886 | 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 |
243,887 | 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 . |
243,888 | 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 ) e... | Delete a vlan . |
243,889 | 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 [ 'subn... | Create a new vlan . |
243,890 | 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 . |
243,891 | 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 . |
243,892 | 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 . |
243,893 | 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 . |
243,894 | 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 , ... | Create a new iface |
243,895 | 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 . |
243,896 | 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... | Update this iface . |
243,897 | 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 . |
243,898 | 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 : ... | Update a domain mail forward destinations . |
243,899 | 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.