<s> '''<STR_LIT>''' <EOL> import random <EOL> import uuid <EOL> import itertools <EOL> from faker import Faker <EOL> fake = Faker ( ) <EOL> fake . seed ( <NUM_LIT> ) <EOL> class Create ( object ) : <EOL> def __init__ ( self , get_result ) : <EOL> self . get_result = get_result <EOL> def create ( self , * args , ** kwargs ) : <EOL> return self . get_result ( * args , ** kwargs ) <EOL> class CreateAndList ( Create ) : <EOL> def __init__ ( self , get_result , list_result ) : <EOL> super ( CreateAndList , self ) . __init__ ( get_result ) <EOL> self . list_result = list_result <EOL> def list ( self ) : <EOL> return self . list_result ( ) <EOL> class FakeOSServer ( object ) : <EOL> addresses = { "<STR_LIT>" : [ { "<STR_LIT>" : "<STR_LIT:127.0.0.1>" } ] } <EOL> class ServerCreate ( Create ) : <EOL> def add_floating_ip ( self , * args , ** kwargs ) : <EOL> return <EOL> def get ( self , server_id ) : <EOL> return FakeOSServer ( ) <EOL> class MockNovaClient ( object ) : <EOL> def __init__ ( self , version , username , password , tenant_name , auth_url ) : <EOL> self . version = version <EOL> self . username = username <EOL> self . password = password <EOL> self . tenant_name = tenant_name <EOL> self . auth_url = auth_url <EOL> self . floating_ips = Create ( self . fip_create_result ) <EOL> self . servers = ServerCreate ( self . server_create_result ) <EOL> self . images = CreateAndList ( self . image_create_result , self . image_list_result ) <EOL> self . flavors = CreateAndList ( self . flavor_create_result , self . flavor_list_result ) <EOL> self . security_groups = CreateAndList ( self . secgroup_create_result , self . secgroup_list_result ) <EOL> self . networks = CreateAndList ( None , self . network_list_result ) <EOL> self . security_group_rules = Create ( self . secgroup_rule_create_result ) <EOL> class ImageResult ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . id = fake . md5 ( ) <EOL> self . name = name <EOL> _image_list = [ ImageResult ( n ) for n in ( u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' ) ] <EOL> def image_create_result ( self , * args , ** kwargs ) : <EOL> return random . choice ( self . _image_list ) <EOL> def image_list_result ( self ) : <EOL> return list ( self . _image_list ) <EOL> class FlavorResult ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . id = fake . md5 ( ) <EOL> self . name = name <EOL> _flavor_list = [ FlavorResult ( n ) for n in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) ] <EOL> def flavor_create_result ( self , * args , ** kwargs ) : <EOL> return random . choice ( self . _flavor_list ) <EOL> def flavor_list_result ( self ) : <EOL> return list ( self . _flavor_list ) <EOL> class SecGroupResult ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . id = fake . md5 ( ) <EOL> self . name = name <EOL> _secgroup_list = [ SecGroupResult ( n ) for n in ( u'<STR_LIT:default>' , u'<STR_LIT>' ) ] <EOL> def secgroup_create_result ( self , * args , ** kwargs ) : <EOL> return random . choice ( self . _secgroup_list ) <EOL> def secgroup_list_result ( self ) : <EOL> return list ( itertools . chain ( self . _secgroup_list , <EOL> [ MockNovaClient . SecGroupResult ( sgr . id ) for sgr in self . _secgroup_list ] ) ) <EOL> def secgroup_rule_create_result ( self , * args , ** kwargs ) : <EOL> class SecGroupRuleResult ( object ) : <EOL> def __init__ ( self ) : <EOL> self . id = fake . md5 ( ) <EOL> return SecGroupRuleResult ( ) <EOL> def fip_create_result ( self , * args , ** kwargs ) : <EOL> class FIPResult ( object ) : <EOL> def __init__ ( self ) : <EOL> self . ip = fake . ipv4 ( ) <EOL> self . id = fake . md5 ( ) <EOL> return FIPResult ( ) <EOL> class NetworkResult ( object ) : <EOL> def __init__ ( self , label ) : <EOL> self . label = label <EOL> self . id = uuid . uuid4 ( ) <EOL> _networks_list = [ NetworkResult ( n ) for n in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' ) ] <EOL> def network_list_result ( self ) : <EOL> return list ( self . _networks_list ) <EOL> def server_create_result ( self , * args , ** kwargs ) : <EOL> class ServerResult ( object ) : <EOL> def __init__ ( self ) : <EOL> self . id = fake . md5 ( ) <EOL> self . addresses = { u"<STR_LIT>" : [ { u'<STR_LIT>' : fake . ipv4 ( ) } ] } <EOL> return ServerResult ( ) <EOL> class MockNeutronClient ( object ) : <EOL> def __init__ ( self , username = None , password = None , auth_url = None , tenant_name = None ) : <EOL> self . username = username <EOL> self . password = password <EOL> self . auth_url = auth_url <EOL> self . tenant_name = tenant_name <EOL> def create_network ( self , body = None ) : <EOL> result = { "<STR_LIT>" : { "<STR_LIT:id>" : MockNovaClient . _networks_list [ <NUM_LIT:0> ] . id } } <EOL> return result <EOL> def create_subnet ( self , body = None ) : <EOL> result = { '<STR_LIT>' : [ { '<STR_LIT:id>' : fake . md5 ( ) } ] } <EOL> return result <EOL> def create_router ( self , body = None ) : <EOL> result = { '<STR_LIT>' : { '<STR_LIT:id>' : fake . md5 ( ) } } <EOL> return result <EOL> def list_routers ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:id>' : fake . md5 ( ) } ] } <EOL> def add_gateway_router ( self , * args , ** kwargs ) : <EOL> return { } <EOL> def add_interface_router ( self , * args , ** kwargs ) : <EOL> return { u'<STR_LIT:id>' : uuid . uuid4 ( ) } </s>
