<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> import os <EOL> import sys <EOL> import getopt <EOL> r = sys . argv [ <NUM_LIT:0> ] . rfind ( '<STR_LIT:/>' ) <EOL> if r < <NUM_LIT:0> : <EOL> osconnector_path = "<STR_LIT:..>" <EOL> else : <EOL> osconnector_path = sys . argv [ <NUM_LIT:0> ] [ : r + <NUM_LIT:1> ] + "<STR_LIT:..>" <EOL> sys . path . insert ( <NUM_LIT:0> , osconnector_path ) <EOL> import osconnector <EOL> version = "<STR_LIT>" <EOL> def usage ( ) : <EOL> print "<STR_LIT>" , sys . argv [ <NUM_LIT:0> ] , "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> return <EOL> def delete_items ( ) : <EOL> global myvim <EOL> global rollback_list <EOL> print "<STR_LIT>" <EOL> for i in range ( len ( rollback_list ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> item , name , id_ = rollback_list [ i ] <EOL> if item == "<STR_LIT>" : <EOL> print ( "<STR_LIT>" % ( name , id_ ) ) . ljust ( <NUM_LIT:50> ) , <EOL> else : <EOL> print ( "<STR_LIT>" % ( item , name ) ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> if item == "<STR_LIT>" : <EOL> result , message = myvim . delete_tenant_flavor ( id_ ) <EOL> elif item == "<STR_LIT:image>" : <EOL> result , message = myvim . delete_tenant_image ( id_ ) <EOL> elif item == "<STR_LIT>" : <EOL> result , message = myvim . delete_tenant ( id_ ) <EOL> elif item == "<STR_LIT:user>" : <EOL> result , message = myvim . delete_user ( id_ ) <EOL> elif item == "<STR_LIT>" : <EOL> result , message = myvim . delete_tenant_network ( id_ ) <EOL> elif item == "<STR_LIT>" : <EOL> result , message = myvim . delete_tenant_vminstance ( id_ ) <EOL> elif item == "<STR_LIT>" : <EOL> try : <EOL> myvim [ name ] = id_ <EOL> result = <NUM_LIT:1> <EOL> except Exception , e : <EOL> result = - <NUM_LIT:1> <EOL> message = "<STR_LIT:U+0020>" + str ( type ( e ) ) [ <NUM_LIT:6> : - <NUM_LIT:1> ] + "<STR_LIT>" + str ( e ) <EOL> else : <EOL> print "<STR_LIT>" % ( item , name , id_ ) <EOL> continue <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , message <EOL> continue <EOL> else : <EOL> print "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> global myvim <EOL> global rollback_list <EOL> rollback_list = [ ] <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' ] ) <EOL> except getopt . GetoptError , err : <EOL> print "<STR_LIT>" , err <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> creds = { } <EOL> creds [ '<STR_LIT:version>' ] = os . environ . get ( '<STR_LIT>' , '<STR_LIT:2>' ) <EOL> creds [ '<STR_LIT:username>' ] = os . environ . get ( '<STR_LIT>' ) <EOL> creds [ '<STR_LIT:password>' ] = os . environ . get ( '<STR_LIT>' ) <EOL> creds [ '<STR_LIT>' ] = os . environ . get ( '<STR_LIT>' ) <EOL> creds [ '<STR_LIT>' ] = os . environ . get ( '<STR_LIT>' ) <EOL> skip_admin_tests = False <EOL> image_path = "<STR_LIT>" <EOL> for o , a in opts : <EOL> if o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> usage ( ) <EOL> sys . exit ( ) <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> creds [ '<STR_LIT:version>' ] = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> creds [ '<STR_LIT:username>' ] = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> creds [ '<STR_LIT:password>' ] = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> creds [ '<STR_LIT>' ] = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> creds [ '<STR_LIT>' ] = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> image_path = a <EOL> elif o == "<STR_LIT>" : <EOL> skip_admin_tests = True <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> if creds [ '<STR_LIT>' ] == None : <EOL> print "<STR_LIT>" <EOL> sys . exit ( ) <EOL> print "<STR_LIT>" , creds <EOL> try : <EOL> print '<STR_LIT>' . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> try : <EOL> myvim = osconnector . osconnector ( uuid = None , name = '<STR_LIT>' , tenant = creds [ '<STR_LIT>' ] , <EOL> url = creds [ '<STR_LIT>' ] , url_admin = None , <EOL> user = creds [ '<STR_LIT:username>' ] , passwd = creds [ '<STR_LIT:password>' ] , <EOL> debug = False , config = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> print "<STR_LIT>" <EOL> except Exception , e : <EOL> print "<STR_LIT>" <EOL> print str ( type ( e ) ) [ <NUM_LIT:6> : - <NUM_LIT:1> ] + "<STR_LIT>" + str ( e ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> if not skip_admin_tests : <EOL> tenant_name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % tenant_name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> result , new_tenant = myvim . new_tenant ( tenant_name , "<STR_LIT>" ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_tenant <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_tenant <EOL> rollback_list . append ( ( "<STR_LIT>" , tenant_name , new_tenant ) ) <EOL> user_name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % user_name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> result , new_user = myvim . new_user ( user_name , user_name , tenant_id = new_tenant ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_user <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_user <EOL> rollback_list . append ( ( "<STR_LIT:user>" , user_name , new_user ) ) <EOL> name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> flavor = { } <EOL> flavor [ '<STR_LIT:name>' ] = name <EOL> result , new_flavor1 = myvim . new_tenant_flavor ( flavor , True ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_flavor1 <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_flavor1 <EOL> rollback_list . append ( ( "<STR_LIT>" , name , new_flavor1 ) ) <EOL> name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> image = { } <EOL> image [ '<STR_LIT:name>' ] = name <EOL> image [ '<STR_LIT:location>' ] = image_path <EOL> result , new_image1 = myvim . new_tenant_image ( image ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_image1 <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_image1 <EOL> rollback_list . append ( ( "<STR_LIT:image>" , name , new_image1 ) ) <EOL> if not skip_admin_tests : <EOL> try : <EOL> print '<STR_LIT>' . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> myvim [ '<STR_LIT>' ] = tenant_name <EOL> myvim [ '<STR_LIT:user>' ] = user_name <EOL> myvim [ '<STR_LIT>' ] = user_name <EOL> print "<STR_LIT>" <EOL> rollback_list . append ( ( "<STR_LIT>" , "<STR_LIT>" , creds [ "<STR_LIT>" ] ) ) <EOL> rollback_list . append ( ( "<STR_LIT>" , "<STR_LIT:user>" , creds [ "<STR_LIT:username>" ] ) ) <EOL> rollback_list . append ( ( "<STR_LIT>" , "<STR_LIT>" , creds [ "<STR_LIT:password>" ] ) ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , str ( type ( e ) ) [ <NUM_LIT:6> : - <NUM_LIT:1> ] + "<STR_LIT>" + str ( e ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> result , new_net1 = myvim . new_tenant_network ( name , "<STR_LIT>" ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_net1 <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_net1 <EOL> rollback_list . append ( ( "<STR_LIT>" , name , new_net1 ) ) <EOL> name = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % name ) . ljust ( <NUM_LIT:50> ) , <EOL> sys . stdout . flush ( ) <EOL> result , new_vm1 = myvim . new_tenant_vminstance ( name , "<STR_LIT>" , False , new_image1 , new_flavor1 , <EOL> [ { "<STR_LIT>" : new_net1 , "<STR_LIT:type>" : "<STR_LIT>" } ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , new_vm1 <EOL> exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" , new_vm1 <EOL> rollback_list . append ( ( "<STR_LIT>" , name , new_vm1 ) ) <EOL> print '<STR_LIT>' <EOL> print "<STR_LIT>" <EOL> raw_input ( '<STR_LIT>' ) <EOL> exit ( ) <EOL> except KeyboardInterrupt : <EOL> print "<STR_LIT>" <EOL> except SystemExit : <EOL> pass <EOL> if len ( rollback_list ) : <EOL> delete_items ( ) </s>
