<s> import cStringIO <EOL> import codecs <EOL> from base64 import b64encode <EOL> from os . path import exists , expanduser <EOL> from io import StringIO <EOL> from pydoc import pager <EOL> from kamaki . cli import command <EOL> from kamaki . cli . cmdtree import CommandTree <EOL> from kamaki . cli . utils import remove_from_items , filter_dicts_by_dict <EOL> from kamaki . cli . errors import raiseCLIError , CLISyntaxError , CLIInvalidArgument <EOL> from kamaki . clients . cyclades import ( <EOL> CycladesComputeClient , ClientError , CycladesNetworkClient ) <EOL> from kamaki . cli . argument import ( <EOL> FlagArgument , ValueArgument , KeyValueArgument , RepeatableArgument , <EOL> DateArgument , IntArgument , StatusArgument ) <EOL> from kamaki . cli . cmds import ( <EOL> CommandInit , fall_back , OptionalOutput , NameFilter , IDFilter , Wait , errors , <EOL> client_log ) <EOL> server_cmds = CommandTree ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> flavor_cmds = CommandTree ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> namespaces = [ server_cmds , flavor_cmds ] <EOL> howto_personality = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> server_states = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class _ServerWait ( Wait ) : <EOL> def wait_while ( self , server_id , current_status , timeout = <NUM_LIT> ) : <EOL> if current_status in ( '<STR_LIT>' , ) : <EOL> def update_cb ( item_details ) : <EOL> return item_details . get ( '<STR_LIT>' , None ) <EOL> else : <EOL> update_cb = None <EOL> super ( _ServerWait , self ) . wait ( <EOL> '<STR_LIT>' , server_id , self . client . wait_server_while , current_status , <EOL> countdown = ( current_status not in ( '<STR_LIT>' , ) ) , <EOL> timeout = timeout , update_cb = update_cb ) <EOL> def wait_until ( self , server_id , target_status , timeout = <NUM_LIT> ) : <EOL> super ( _ServerWait , self ) . wait ( <EOL> '<STR_LIT>' , server_id , self . client . wait_server_until , target_status , <EOL> timeout = timeout , msg = '<STR_LIT>' ) <EOL> def assert_not_in_status ( self , server_id , status ) : <EOL> """<STR_LIT>""" <EOL> current = self . client . get_server_details ( server_id ) . get ( '<STR_LIT:status>' , None ) <EOL> if current in ( status , ) : <EOL> raiseCLIError ( '<STR_LIT>' % ( server_id , status ) ) <EOL> return current <EOL> class _CycladesInit ( CommandInit ) : <EOL> @ errors . Generic . all <EOL> @ client_log <EOL> def _run ( self ) : <EOL> self . client = self . get_client ( CycladesComputeClient , '<STR_LIT>' ) <EOL> @ errors . Cyclades . flavor_id <EOL> def _flavor_exists ( self , flavor_id ) : <EOL> self . client . get_flavor_details ( flavor_id = flavor_id ) <EOL> @ errors . Cyclades . server_id <EOL> def _server_exists ( self , server_id ) : <EOL> self . client . get_server_details ( server_id = server_id ) <EOL> @ fall_back <EOL> def _restruct_server_info ( self , vm ) : <EOL> if not vm : <EOL> return vm <EOL> img = vm [ '<STR_LIT:image>' ] <EOL> try : <EOL> img . pop ( '<STR_LIT>' , None ) <EOL> img [ '<STR_LIT:name>' ] = self . client . get_image_details ( img [ '<STR_LIT:id>' ] ) [ '<STR_LIT:name>' ] <EOL> except Exception : <EOL> pass <EOL> flv = vm [ '<STR_LIT>' ] <EOL> try : <EOL> flv . pop ( '<STR_LIT>' , None ) <EOL> flv [ '<STR_LIT:name>' ] = self . client . get_flavor_details ( flv [ '<STR_LIT:id>' ] ) [ '<STR_LIT:name>' ] <EOL> except Exception : <EOL> pass <EOL> vm [ '<STR_LIT>' ] = vm . pop ( '<STR_LIT>' , dict ( ) ) <EOL> for port in vm [ '<STR_LIT>' ] : <EOL> netid = port . get ( '<STR_LIT>' ) <EOL> for k in vm [ '<STR_LIT>' ] . get ( netid , [ ] ) : <EOL> k . pop ( '<STR_LIT>' , None ) <EOL> k . pop ( '<STR_LIT:version>' , None ) <EOL> port . update ( k ) <EOL> uuids = self . _uuids2usernames ( [ vm [ '<STR_LIT>' ] , vm [ '<STR_LIT>' ] ] ) <EOL> vm [ '<STR_LIT>' ] += '<STR_LIT>' % uuids [ vm [ '<STR_LIT>' ] ] <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> vm . pop ( key , None ) <EOL> return vm <EOL> def main ( self ) : <EOL> self . _run ( ) <EOL> @ command ( server_cmds ) <EOL> class server_list ( _CycladesInit , OptionalOutput , NameFilter , IDFilter ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> detail = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> since = DateArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> limit = IntArgument ( <EOL> '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> more = FlagArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> enum = FlagArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> flavor_id = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> image_id = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> user_id = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> user_name = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> status = ValueArgument ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' ) ) , <EOL> meta = KeyValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> meta_like = KeyValueArgument ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' ) ) , <EOL> ) <EOL> def _add_user_name ( self , servers ) : <EOL> uuids = self . _uuids2usernames ( list ( set ( <EOL> [ srv [ '<STR_LIT>' ] for srv in servers ] ) ) ) <EOL> for srv in servers : <EOL> srv [ '<STR_LIT>' ] += '<STR_LIT>' % uuids [ srv [ '<STR_LIT>' ] ] <EOL> return servers <EOL> def _apply_common_filters ( self , servers ) : <EOL> common_filters = dict ( ) <EOL> if self [ '<STR_LIT:status>' ] : <EOL> common_filters [ '<STR_LIT:status>' ] = self [ '<STR_LIT:status>' ] <EOL> if self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] : <EOL> uuid = self [ '<STR_LIT>' ] or self . _username2uuid ( self [ '<STR_LIT>' ] ) <EOL> common_filters [ '<STR_LIT>' ] = uuid <EOL> return filter_dicts_by_dict ( servers , common_filters ) <EOL> def _filter_by_image ( self , servers ) : <EOL> iid = self [ '<STR_LIT>' ] <EOL> return [ srv for srv in servers if srv [ '<STR_LIT:image>' ] [ '<STR_LIT:id>' ] == iid ] <EOL> def _filter_by_flavor ( self , servers ) : <EOL> fid = self [ '<STR_LIT>' ] <EOL> return [ srv for srv in servers if ( <EOL> '<STR_LIT:%s>' % srv [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] == '<STR_LIT:%s>' % fid ) ] <EOL> def _filter_by_metadata ( self , servers ) : <EOL> new_servers = [ ] <EOL> for srv in servers : <EOL> if '<STR_LIT>' not in srv : <EOL> continue <EOL> meta = [ dict ( srv [ '<STR_LIT>' ] ) ] <EOL> if self [ '<STR_LIT>' ] : <EOL> meta = filter_dicts_by_dict ( meta , self [ '<STR_LIT>' ] ) <EOL> if meta and self [ '<STR_LIT>' ] : <EOL> meta = filter_dicts_by_dict ( <EOL> meta , self [ '<STR_LIT>' ] , exact_match = False ) <EOL> if meta : <EOL> new_servers . append ( srv ) <EOL> return new_servers <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . date <EOL> def _run ( self ) : <EOL> withimage = bool ( self [ '<STR_LIT>' ] ) <EOL> withflavor = bool ( self [ '<STR_LIT>' ] ) <EOL> withmeta = bool ( self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] ) <EOL> withcommons = bool ( <EOL> self [ '<STR_LIT:status>' ] or self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] ) <EOL> detail = self [ '<STR_LIT>' ] or ( <EOL> withimage or withflavor or withmeta or withcommons ) <EOL> ch_since = self . arguments [ '<STR_LIT>' ] . isoformat if self [ '<STR_LIT>' ] else None <EOL> servers = list ( self . client . list_servers ( detail , ch_since ) or [ ] ) <EOL> servers = self . _filter_by_name ( servers ) <EOL> servers = self . _filter_by_id ( servers ) <EOL> servers = self . _apply_common_filters ( servers ) <EOL> if withimage : <EOL> servers = self . _filter_by_image ( servers ) <EOL> if withflavor : <EOL> servers = self . _filter_by_flavor ( servers ) <EOL> if withmeta : <EOL> servers = self . _filter_by_metadata ( servers ) <EOL> if detail and self [ '<STR_LIT>' ] : <EOL> pass <EOL> else : <EOL> for srv in servers : <EOL> for key in set ( srv ) . difference ( [ '<STR_LIT:id>' , '<STR_LIT:name>' ] ) : <EOL> srv . pop ( key ) <EOL> kwargs = dict ( with_enumeration = self [ '<STR_LIT>' ] ) <EOL> if self [ '<STR_LIT>' ] : <EOL> codecinfo = codecs . lookup ( '<STR_LIT:utf-8>' ) <EOL> kwargs [ '<STR_LIT>' ] = codecs . StreamReaderWriter ( <EOL> cStringIO . StringIO ( ) , <EOL> codecinfo . streamreader , <EOL> codecinfo . streamwriter ) <EOL> kwargs [ '<STR_LIT:title>' ] = ( ) <EOL> if self [ '<STR_LIT>' ] : <EOL> servers = servers [ : self [ '<STR_LIT>' ] ] <EOL> self . print_ ( servers , ** kwargs ) <EOL> if self [ '<STR_LIT>' ] : <EOL> pager ( kwargs [ '<STR_LIT>' ] . getvalue ( ) ) <EOL> def main ( self ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( ) <EOL> @ command ( server_cmds ) <EOL> class server_info ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> nics = FlagArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> stats = FlagArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> diagnostics = FlagArgument ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> if self [ '<STR_LIT>' ] : <EOL> self . print_ ( <EOL> self . client . get_server_nics ( server_id ) , self . print_dict ) <EOL> elif self [ '<STR_LIT>' ] : <EOL> self . print_ ( <EOL> self . client . get_server_stats ( server_id ) , self . print_dict ) <EOL> elif self [ '<STR_LIT>' ] : <EOL> self . print_ ( self . client . get_server_diagnostics ( server_id ) ) <EOL> else : <EOL> vm = self . client . get_server_details ( server_id ) <EOL> self . print_ ( vm , self . print_dict ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> choose_one = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> count = len ( [ a for a in choose_one if self [ a ] ] ) <EOL> if count > <NUM_LIT:1> : <EOL> raise CLIInvalidArgument ( '<STR_LIT>' , details = [ <EOL> '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ self . arguments [ a ] . lvalue for a in choose_one ] ) ] ) <EOL> self . _run ( server_id = server_id ) <EOL> class PersonalityArgument ( KeyValueArgument ) : <EOL> terms = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:path>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ property <EOL> def value ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , [ ] ) <EOL> @ value . setter <EOL> def value ( self , newvalue ) : <EOL> if newvalue == self . default : <EOL> return self . value <EOL> self . _value , input_dict = [ ] , { } <EOL> for i , terms in enumerate ( newvalue ) : <EOL> termlist = terms . split ( '<STR_LIT:U+002C>' ) <EOL> if len ( termlist ) > len ( self . terms ) : <EOL> msg = '<STR_LIT>' % len ( self . terms ) <EOL> raiseCLIError ( CLISyntaxError ( msg ) , details = howto_personality ) <EOL> for k , v in self . terms : <EOL> prefix = '<STR_LIT>' % k <EOL> for item in termlist : <EOL> if item . lower ( ) . startswith ( prefix ) : <EOL> input_dict [ k ] = item [ len ( k ) + <NUM_LIT:1> : ] <EOL> break <EOL> item = None <EOL> if item : <EOL> termlist . remove ( item ) <EOL> try : <EOL> path = input_dict [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> path = termlist . pop ( <NUM_LIT:0> ) <EOL> if not path : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' , <EOL> details = howto_personality ) <EOL> if not exists ( path ) : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' % path , <EOL> details = howto_personality ) <EOL> self . _value . append ( dict ( path = path ) ) <EOL> with open ( expanduser ( path ) ) as f : <EOL> self . _value [ i ] [ '<STR_LIT>' ] = b64encode ( f . read ( ) ) <EOL> for k , v in self . terms [ <NUM_LIT:1> : ] : <EOL> try : <EOL> self . _value [ i ] [ v ] = input_dict [ k ] <EOL> except KeyError : <EOL> try : <EOL> self . _value [ i ] [ v ] = termlist . pop ( <NUM_LIT:0> ) <EOL> except IndexError : <EOL> continue <EOL> if k in ( '<STR_LIT>' , ) and self . _value [ i ] [ v ] : <EOL> try : <EOL> self . _value [ i ] [ v ] = int ( self . _value [ i ] [ v ] , <NUM_LIT:8> ) <EOL> except ValueError as ve : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' , details = [ <EOL> '<STR_LIT:%s>' % ve ] ) <EOL> class NetworkArgument ( RepeatableArgument ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def value ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , self . default ) <EOL> @ value . setter <EOL> def value ( self , new_value ) : <EOL> for v in new_value or [ ] : <EOL> part1 , sep , part2 = v . partition ( '<STR_LIT:U+002C>' ) <EOL> netid , ip = '<STR_LIT>' , '<STR_LIT>' <EOL> if part1 . startswith ( '<STR_LIT>' ) : <EOL> netid = part1 [ len ( '<STR_LIT>' ) : ] <EOL> elif part1 . startswith ( '<STR_LIT>' ) : <EOL> ip = part1 [ len ( '<STR_LIT>' ) : ] <EOL> else : <EOL> netid = part1 <EOL> if part2 : <EOL> if ( part2 . startswith ( '<STR_LIT>' ) and netid ) or ( <EOL> part2 . startswith ( '<STR_LIT>' ) and ip ) : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' % v , <EOL> details = [ '<STR_LIT>' ] ) <EOL> if part2 . startswith ( '<STR_LIT>' ) : <EOL> netid = part2 [ len ( '<STR_LIT>' ) : ] <EOL> elif part2 . startswith ( '<STR_LIT>' ) : <EOL> ip = part2 [ len ( '<STR_LIT>' ) : ] <EOL> elif netid : <EOL> ip = part2 <EOL> else : <EOL> netid = part2 <EOL> if not netid : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' % v , <EOL> details = [ '<STR_LIT>' ] ) <EOL> self . _value = getattr ( self , '<STR_LIT>' , [ ] ) <EOL> self . _value . append ( dict ( uuid = netid ) ) <EOL> if ip : <EOL> self . _value [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] = ip <EOL> @ command ( server_cmds ) <EOL> class server_create ( _CycladesInit , OptionalOutput , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> server_name = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> flavor_id = IntArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> image_id = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> personality = PersonalityArgument ( <EOL> ( <NUM_LIT> * '<STR_LIT:U+0020>' ) . join ( howto_personality ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> wait = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> cluster_size = IntArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> max_threads = IntArgument ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> network_configuration = NetworkArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> no_network = FlagArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> project_id = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> metadata = KeyValueArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ) <EOL> required = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ errors . Cyclades . cluster_size <EOL> def _create_cluster ( self , prefix , flavor_id , image_id , size ) : <EOL> networks = self [ '<STR_LIT>' ] or ( <EOL> [ ] if self [ '<STR_LIT>' ] else None ) <EOL> servers = [ dict ( <EOL> name = '<STR_LIT>' % ( prefix , i if size > <NUM_LIT:1> else '<STR_LIT>' ) , <EOL> flavor_id = flavor_id , <EOL> image_id = image_id , <EOL> project_id = self [ '<STR_LIT>' ] , <EOL> personality = self [ '<STR_LIT>' ] , <EOL> metadata = self [ '<STR_LIT>' ] , <EOL> networks = networks ) for i in range ( <NUM_LIT:1> , <NUM_LIT:1> + size ) ] <EOL> if size == <NUM_LIT:1> : <EOL> return [ self . client . create_server ( ** servers [ <NUM_LIT:0> ] ) ] <EOL> self . client . MAX_THREADS = int ( self [ '<STR_LIT>' ] or <NUM_LIT:1> ) <EOL> try : <EOL> r = self . client . async_run ( self . client . create_server , servers ) <EOL> return r <EOL> except Exception as e : <EOL> if size == <NUM_LIT:1> : <EOL> raise e <EOL> try : <EOL> requested_names = [ s [ '<STR_LIT:name>' ] for s in servers ] <EOL> spawned_servers = [ dict ( <EOL> name = s [ '<STR_LIT:name>' ] , <EOL> id = s [ '<STR_LIT:id>' ] ) for s in self . client . list_servers ( ) if ( <EOL> s [ '<STR_LIT:name>' ] in requested_names ) ] <EOL> self . error ( '<STR_LIT>' % size ) <EOL> self . error ( '<STR_LIT>' % len ( spawned_servers ) ) <EOL> self . print_ ( spawned_servers , out = self . _err ) <EOL> self . error ( '<STR_LIT>' ) <EOL> except Exception as ne : <EOL> self . error ( '<STR_LIT>' % ne ) <EOL> finally : <EOL> raise e <EOL> def _get_network_client ( self ) : <EOL> network = getattr ( self , '<STR_LIT>' , None ) <EOL> if not network : <EOL> net_URL = self . astakos . get_endpoint_url ( <EOL> CycladesNetworkClient . service_type ) <EOL> network = CycladesNetworkClient ( net_URL , self . client . token ) <EOL> self . _network_client = network <EOL> return network <EOL> @ errors . Image . id <EOL> def _image_exists ( self , image_id ) : <EOL> self . client . get_image_details ( image_id ) <EOL> @ errors . Cyclades . network_id <EOL> def _network_exists ( self , network_id ) : <EOL> network = self . _get_network_client ( ) <EOL> network . get_network_details ( network_id ) <EOL> def _ip_ready ( self , ip , network_id , cerror ) : <EOL> network = self . _get_network_client ( ) <EOL> ips = [ fip for fip in network . list_floatingips ( ) if ( <EOL> fip [ '<STR_LIT>' ] == ip ) ] <EOL> if not ips : <EOL> msg = '<STR_LIT>' % ip <EOL> raiseCLIError ( cerror , details = [ msg ] + errors . Cyclades . about_ips ) <EOL> ipnet , ipvm = ips [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , ips [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> if getattr ( cerror , '<STR_LIT:status>' , <NUM_LIT:0> ) in ( <NUM_LIT> , ) : <EOL> msg = '<STR_LIT>' <EOL> if ipnet != network_id : <EOL> msg = '<STR_LIT>' % ( <EOL> ip , ipnet , network_id ) <EOL> elif ipvm : <EOL> msg = '<STR_LIT>' % ( ip , ipvm ) <EOL> if msg : <EOL> raiseCLIError ( cerror , details = [ <EOL> msg , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ip ] + errors . Cyclades . about_ips ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> def _run ( self ) : <EOL> try : <EOL> for r in self . _create_cluster ( <EOL> self [ '<STR_LIT>' ] , self [ '<STR_LIT>' ] , self [ '<STR_LIT>' ] , <EOL> size = self [ '<STR_LIT>' ] or <NUM_LIT:1> ) : <EOL> if not r : <EOL> self . error ( '<STR_LIT>' % ( <EOL> self [ '<STR_LIT>' ] , r ) ) <EOL> continue <EOL> self . print_ ( r , self . print_dict ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . wait_while ( r [ '<STR_LIT:id>' ] , r [ '<STR_LIT:status>' ] or '<STR_LIT>' ) <EOL> self . writeln ( '<STR_LIT:U+0020>' ) <EOL> except ClientError as ce : <EOL> if ce . status in ( <NUM_LIT> , <NUM_LIT> ) : <EOL> self . _flavor_exists ( flavor_id = self [ '<STR_LIT>' ] ) <EOL> self . _image_exists ( image_id = self [ '<STR_LIT>' ] ) <EOL> if ce . status in ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) : <EOL> for net in self [ '<STR_LIT>' ] or [ ] : <EOL> self . _network_exists ( network_id = net [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in net : <EOL> self . _ip_ready ( net [ '<STR_LIT>' ] , net [ '<STR_LIT>' ] , ce ) <EOL> if self [ '<STR_LIT>' ] and ce . status in ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) : <EOL> self . _project_id_exists ( project_id = self [ '<STR_LIT>' ] ) <EOL> raise <EOL> def main ( self ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> if self [ '<STR_LIT>' ] and self [ '<STR_LIT>' ] : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' , importance = <NUM_LIT:2> , details = [ <EOL> '<STR_LIT>' % ( <EOL> self . arguments [ '<STR_LIT>' ] . lvalue , <EOL> self . arguments [ '<STR_LIT>' ] . lvalue ) ] ) <EOL> self . _run ( ) <EOL> class FirewallProfileArgument ( ValueArgument ) : <EOL> profiles = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ property <EOL> def value ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , None ) <EOL> @ value . setter <EOL> def value ( self , new_profile ) : <EOL> if new_profile : <EOL> new_profile = new_profile . upper ( ) <EOL> if new_profile in self . profiles : <EOL> self . _value = new_profile <EOL> else : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' % new_profile , <EOL> details = [ '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( self . profiles ) ] ) <EOL> @ command ( server_cmds ) <EOL> class server_modify ( _CycladesInit ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> server_name = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> flavor_id = IntArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> firewall_profile = FirewallProfileArgument ( <EOL> '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( FirewallProfileArgument . profiles ) ) , <EOL> '<STR_LIT>' ) , <EOL> metadata_to_set = KeyValueArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> metadata_to_delete = RepeatableArgument ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> public_network_port_id = ValueArgument ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> required = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def _set_firewall_profile ( self , server_id ) : <EOL> vm = self . _restruct_server_info ( <EOL> self . client . get_server_details ( server_id ) ) <EOL> ports = [ p for p in vm [ '<STR_LIT>' ] if '<STR_LIT>' in p ] <EOL> pick_port = self . arguments [ '<STR_LIT>' ] <EOL> if pick_port . value : <EOL> ports = [ p for p in ports if pick_port . value in ( <EOL> '<STR_LIT:*>' , '<STR_LIT:%s>' % p [ '<STR_LIT:id>' ] ) ] <EOL> elif len ( ports ) > <NUM_LIT:1> : <EOL> port_strings = [ '<STR_LIT>' % server_id ] <EOL> for p in ports : <EOL> port_strings . append ( '<STR_LIT>' % p [ '<STR_LIT:id>' ] ) <EOL> for k in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> v = p . get ( k ) <EOL> if v : <EOL> port_strings . append ( '<STR_LIT>' % ( k , v ) ) <EOL> raiseCLIError ( <EOL> '<STR_LIT>' % ( <EOL> server_id ) , details = port_strings + [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % pick_port . lvalue , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % pick_port . lvalue , ] ) <EOL> if not ports : <EOL> pp = pick_port . value <EOL> raiseCLIError ( <EOL> '<STR_LIT>' % ( <EOL> server_id , '<STR_LIT>' % pp if pp else '<STR_LIT>' ) , <EOL> details = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % server_id , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( <EOL> server_id ) ] ) <EOL> for port in ports : <EOL> self . error ( '<STR_LIT>' % ( <EOL> port [ '<STR_LIT:id>' ] , self [ '<STR_LIT>' ] ) ) <EOL> self . client . set_firewall_profile ( <EOL> server_id = server_id , <EOL> profile = self [ '<STR_LIT>' ] , <EOL> port_id = port [ '<STR_LIT:id>' ] ) <EOL> def _server_is_stopped ( self , server_id , cerror ) : <EOL> vm = self . client . get_server_details ( server_id ) <EOL> if vm [ '<STR_LIT:status>' ] . lower ( ) not in ( '<STR_LIT>' ) : <EOL> raiseCLIError ( cerror , details = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( server_id , vm [ '<STR_LIT:status>' ] ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % server_id ] ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> if self [ '<STR_LIT>' ] is not None : <EOL> self . client . update_server_name ( ( server_id ) , self [ '<STR_LIT>' ] ) <EOL> if self [ '<STR_LIT>' ] : <EOL> try : <EOL> self . client . resize_server ( server_id , self [ '<STR_LIT>' ] ) <EOL> except ClientError as ce : <EOL> if ce . status in ( <NUM_LIT> , ) : <EOL> self . _flavor_exists ( flavor_id = self [ '<STR_LIT>' ] ) <EOL> if ce . status in ( <NUM_LIT> , ) : <EOL> self . _server_is_stopped ( server_id , ce ) <EOL> raise <EOL> if self [ '<STR_LIT>' ] : <EOL> self . _set_firewall_profile ( server_id ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . client . update_server_metadata ( <EOL> server_id , ** self [ '<STR_LIT>' ] ) <EOL> for key in ( self [ '<STR_LIT>' ] or [ ] ) : <EOL> errors . Cyclades . metadata ( <EOL> self . client . delete_server_metadata ) ( server_id , key = key ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> pnpid = self . arguments [ '<STR_LIT>' ] <EOL> fp = self . arguments [ '<STR_LIT>' ] <EOL> if pnpid . value and not fp . value : <EOL> raise CLIInvalidArgument ( '<STR_LIT>' , details = [ <EOL> '<STR_LIT>' % ( <EOL> pnpid . lvalue , fp . lvalue ) ] ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_reassign ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> project_id = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> required = ( '<STR_LIT>' , ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> try : <EOL> self . client . reassign_server ( server_id , self [ '<STR_LIT>' ] ) <EOL> except ClientError as ce : <EOL> if ce . status in ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) : <EOL> self . _project_id_exists ( project_id = self [ '<STR_LIT>' ] ) <EOL> raise <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_delete ( _CycladesInit , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> wait = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> cluster = FlagArgument ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ) <EOL> def _server_ids ( self , server_var ) : <EOL> if self [ '<STR_LIT>' ] : <EOL> return [ s [ '<STR_LIT:id>' ] for s in self . client . list_servers ( ) if ( <EOL> s [ '<STR_LIT:name>' ] . startswith ( server_var ) ) ] <EOL> return [ server_var , ] <EOL> @ errors . Cyclades . server_id <EOL> def _delete_server ( self , server_id ) : <EOL> if self [ '<STR_LIT>' ] : <EOL> details = self . client . get_server_details ( server_id ) <EOL> status = details [ '<STR_LIT:status>' ] <EOL> self . client . delete_server ( server_id ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . wait_while ( server_id , status ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> def _run ( self , server_var ) : <EOL> deleted_vms = [ ] <EOL> for server_id in self . _server_ids ( server_var ) : <EOL> self . _delete_server ( server_id = server_id ) <EOL> deleted_vms . append ( server_id ) <EOL> if self [ '<STR_LIT>' ] : <EOL> dlen = len ( deleted_vms ) <EOL> self . error ( '<STR_LIT>' % ( <EOL> dlen , '<STR_LIT>' if dlen == <NUM_LIT:1> else '<STR_LIT:s>' ) ) <EOL> def main ( self , server_id_or_cluster_prefix ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id_or_cluster_prefix ) <EOL> @ command ( server_cmds ) <EOL> class server_reboot ( _CycladesInit , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> type = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> wait = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> hard_reboot = None <EOL> if self [ '<STR_LIT:type>' ] : <EOL> if self [ '<STR_LIT:type>' ] . lower ( ) in ( '<STR_LIT>' , ) : <EOL> hard_reboot = False <EOL> elif self [ '<STR_LIT:type>' ] . lower ( ) in ( '<STR_LIT>' , ) : <EOL> hard_reboot = True <EOL> else : <EOL> raise CLISyntaxError ( <EOL> '<STR_LIT>' % self [ '<STR_LIT:type>' ] , <EOL> importance = <NUM_LIT:2> , details = [ <EOL> '<STR_LIT>' ] ) <EOL> self . client . reboot_server ( int ( server_id ) , hard_reboot ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . wait_while ( server_id , '<STR_LIT>' ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_start ( _CycladesInit , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> wait = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> status = self . assert_not_in_status ( server_id , '<STR_LIT>' ) <EOL> self . client . start_server ( int ( server_id ) ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . wait_while ( server_id , status ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_shutdown ( _CycladesInit , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> wait = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> status = self . assert_not_in_status ( server_id , '<STR_LIT>' ) <EOL> self . client . shutdown_server ( int ( server_id ) ) <EOL> if self [ '<STR_LIT>' ] : <EOL> self . wait_while ( server_id , status ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> _basic_cons = CycladesComputeClient . CONSOLE_TYPES <EOL> class ConsoleTypeArgument ( ValueArgument ) : <EOL> TRANSLATE = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> @ property <EOL> def value ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , None ) <EOL> @ value . setter <EOL> def value ( self , new_value ) : <EOL> global _basic_cons <EOL> if new_value : <EOL> v = new_value . lower ( ) <EOL> v = self . TRANSLATE . get ( v , v ) <EOL> if v in _basic_cons : <EOL> self . _value = v <EOL> else : <EOL> ctypes = set ( _basic_cons ) . difference ( self . TRANSLATE . values ( ) ) <EOL> ctypes = list ( ctypes ) + [ <EOL> '<STR_LIT>' % ( a , t ) for t , a in self . TRANSLATE . items ( ) ] <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' % new_value , details = [ <EOL> '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( ctypes ) ) , ] ) <EOL> _translated = ConsoleTypeArgument . TRANSLATE <EOL> VALID_CONSOLE_TYPES = list ( set ( _basic_cons ) . difference ( _translated . values ( ) ) ) <EOL> VALID_CONSOLE_TYPES += [ '<STR_LIT>' % ( a , t ) for t , a in _translated . items ( ) ] <EOL> @ command ( server_cmds ) <EOL> class server_console ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> console_type = ConsoleTypeArgument ( <EOL> '<STR_LIT>' % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( VALID_CONSOLE_TYPES ) , VALID_CONSOLE_TYPES [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT>' ) , <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> self . error ( '<STR_LIT>' ) <EOL> ctype = self [ '<STR_LIT>' ] or VALID_CONSOLE_TYPES [ <NUM_LIT:0> ] <EOL> self . print_ ( <EOL> self . client . get_server_console ( server_id , ctype ) , self . print_dict ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_wait ( _CycladesInit , _ServerWait ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> timeout = IntArgument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , default = <NUM_LIT> ) , <EOL> status = StatusArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> valid_states = server_states ) , <EOL> status_w = StatusArgument ( <EOL> '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( server_states ) , '<STR_LIT>' , <EOL> valid_states = server_states ) , <EOL> status_u = StatusArgument ( <EOL> '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( server_states ) , <EOL> '<STR_LIT>' , <EOL> valid_states = server_states ) , <EOL> ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> def _run ( self , server_id ) : <EOL> r = self . client . get_server_details ( server_id ) <EOL> if self [ '<STR_LIT>' ] : <EOL> if r [ '<STR_LIT:status>' ] . lower ( ) == self [ '<STR_LIT>' ] . lower ( ) : <EOL> self . error ( <EOL> '<STR_LIT>' % ( server_id , r [ '<STR_LIT:status>' ] ) ) <EOL> else : <EOL> self . wait_until ( <EOL> server_id , self [ '<STR_LIT>' ] , timeout = self [ '<STR_LIT>' ] ) <EOL> else : <EOL> status_w = self [ '<STR_LIT>' ] or self [ '<STR_LIT:status>' ] or '<STR_LIT>' <EOL> if r [ '<STR_LIT:status>' ] . lower ( ) == status_w . lower ( ) : <EOL> self . wait_while ( <EOL> server_id , status_w , timeout = self [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . error ( <EOL> '<STR_LIT>' % ( server_id , r [ '<STR_LIT:status>' ] ) ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> status_args = [ self [ '<STR_LIT:status>' ] , self [ '<STR_LIT>' ] , self [ '<STR_LIT>' ] ] <EOL> if len ( [ x for x in status_args if x ] ) > <NUM_LIT:1> : <EOL> raise CLIInvalidArgument ( <EOL> '<STR_LIT>' , importance = <NUM_LIT:2> , details = [ <EOL> '<STR_LIT>' % ( <EOL> self . arguments [ '<STR_LIT:status>' ] . lvalue , <EOL> self . arguments [ '<STR_LIT>' ] . lvalue , <EOL> self . arguments [ '<STR_LIT>' ] . lvalue ) ] ) <EOL> if self [ '<STR_LIT:status>' ] : <EOL> self . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> self . arguments [ '<STR_LIT:status>' ] . lvalue , <EOL> self . arguments [ '<STR_LIT>' ] . lvalue ) ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( flavor_cmds ) <EOL> class flavor_list ( _CycladesInit , OptionalOutput , NameFilter , IDFilter ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> detail = FlagArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> limit = IntArgument ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> more = FlagArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> enum = FlagArgument ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ram = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> vcpus = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> disk = ValueArgument ( '<STR_LIT>' , ( '<STR_LIT>' ) ) , <EOL> disk_template = ValueArgument ( <EOL> '<STR_LIT>' , ( '<STR_LIT>' ) ) <EOL> ) <EOL> def _apply_common_filters ( self , flavors ) : <EOL> common_filters = dict ( ) <EOL> if self [ '<STR_LIT>' ] : <EOL> common_filters [ '<STR_LIT>' ] = self [ '<STR_LIT>' ] <EOL> if self [ '<STR_LIT>' ] : <EOL> common_filters [ '<STR_LIT>' ] = self [ '<STR_LIT>' ] <EOL> if self [ '<STR_LIT>' ] : <EOL> common_filters [ '<STR_LIT>' ] = self [ '<STR_LIT>' ] <EOL> if self [ '<STR_LIT>' ] : <EOL> common_filters [ '<STR_LIT>' ] = self [ '<STR_LIT>' ] <EOL> return filter_dicts_by_dict ( flavors , common_filters ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> def _run ( self ) : <EOL> withcommons = self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] or ( <EOL> self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] ) <EOL> detail = self [ '<STR_LIT>' ] or withcommons <EOL> flavors = self . client . list_flavors ( detail ) <EOL> flavors = self . _filter_by_name ( flavors ) <EOL> flavors = self . _filter_by_id ( flavors ) <EOL> if withcommons : <EOL> flavors = self . _apply_common_filters ( flavors ) <EOL> if not ( self [ '<STR_LIT>' ] or self [ '<STR_LIT>' ] ) : <EOL> remove_from_items ( flavors , '<STR_LIT>' ) <EOL> if detail and not self [ '<STR_LIT>' ] : <EOL> for flv in flavors : <EOL> for key in set ( flv ) . difference ( [ '<STR_LIT:id>' , '<STR_LIT:name>' ] ) : <EOL> flv . pop ( key ) <EOL> kwargs = dict ( out = StringIO ( ) , title = ( ) ) if self [ '<STR_LIT>' ] else { } <EOL> self . print_ ( flavors , with_enumeration = self [ '<STR_LIT>' ] , ** kwargs ) <EOL> if self [ '<STR_LIT>' ] : <EOL> pager ( kwargs [ '<STR_LIT>' ] . getvalue ( ) ) <EOL> def main ( self ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( ) <EOL> @ command ( flavor_cmds ) <EOL> class flavor_info ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . flavor_id <EOL> def _run ( self , flavor_id ) : <EOL> self . print_ ( self . client . get_flavor_details ( flavor_id ) , self . print_dict ) <EOL> def main ( self , flavor_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( flavor_id = flavor_id ) <EOL> @ command ( server_cmds ) <EOL> class server_attachment ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> attachment_id = ValueArgument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , ) <EOL> ) <EOL> required = ( '<STR_LIT>' , ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> @ errors . Cyclades . endpoint <EOL> def _run ( self , server_id ) : <EOL> r = self . client . get_volume_attachment ( server_id , self [ '<STR_LIT>' ] ) <EOL> self . print_ ( r , self . print_dict ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_attachments ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> @ errors . Cyclades . endpoint <EOL> def _run ( self , server_id ) : <EOL> r = self . client . list_volume_attachments ( server_id ) <EOL> self . print_ ( r ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_attach ( _CycladesInit , OptionalOutput ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> volume_id = ValueArgument ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> required = ( '<STR_LIT>' , ) <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> @ errors . Cyclades . endpoint <EOL> def _run ( self , server_id ) : <EOL> r = self . client . attach_volume ( server_id , self [ '<STR_LIT>' ] ) <EOL> self . print_ ( r , self . print_dict ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> self . _run ( server_id = server_id ) <EOL> @ command ( server_cmds ) <EOL> class server_detach ( _CycladesInit ) : <EOL> """<STR_LIT>""" <EOL> arguments = dict ( <EOL> attachment_id = ValueArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> volume_id = ValueArgument ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ) <EOL> required = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ errors . Generic . all <EOL> @ errors . Cyclades . connection <EOL> @ errors . Cyclades . server_id <EOL> @ errors . Cyclades . endpoint <EOL> def _run ( self , server_id ) : <EOL> att_id = self [ '<STR_LIT>' ] <EOL> if att_id : <EOL> self . client . delete_volume_attachment ( server_id , att_id ) <EOL> else : <EOL> r = self . client . detach_volume ( server_id , self [ '<STR_LIT>' ] ) <EOL> self . error ( '<STR_LIT>' % ( <EOL> len ( r ) , '<STR_LIT>' if len ( r ) == <NUM_LIT:1> else '<STR_LIT:s>' ) ) <EOL> self . error ( '<STR_LIT:OK>' ) <EOL> def main ( self , server_id ) : <EOL> super ( self . __class__ , self ) . _run ( ) <EOL> if all ( [ self [ '<STR_LIT>' ] , self [ '<STR_LIT>' ] ] ) : <EOL> raise CLISyntaxError ( '<STR_LIT>' , details = [ <EOL> '<STR_LIT>' % ( <EOL> self . arguments [ '<STR_LIT>' ] . lvalue , <EOL> self . arguments [ '<STR_LIT>' ] . lvalue ) ] ) <EOL> self . _run ( server_id = server_id ) </s>
