@@ -587,3 +587,61 @@ def get_floating_ips(floating_ips=None, count=2):
587587 if floating_ips is None :
588588 floating_ips = FakeFloatingIP .create_floating_ips (count )
589589 return mock .MagicMock (side_effect = floating_ips )
590+
591+
592+ class FakeNetwork (object ):
593+ """Fake one or more networks."""
594+
595+ @staticmethod
596+ def create_one_network (attrs = {}, methods = {}):
597+ """Create a fake network.
598+
599+ :param Dictionary attrs:
600+ A dictionary with all attributes
601+ :param Dictionary methods:
602+ A dictionary with all methods
603+ :return:
604+ A FakeResource object, with id, label, cidr
605+ """
606+ # Set default attributes.
607+ network_attrs = {
608+ 'id' : 'network-id-' + uuid .uuid4 ().hex ,
609+ 'label' : 'network-label-' + uuid .uuid4 ().hex ,
610+ 'cidr' : '10.0.0.0/24' ,
611+ }
612+
613+ # Overwrite default attributes.
614+ network_attrs .update (attrs )
615+
616+ # Set default methods.
617+ network_methods = {
618+ 'keys' : ['id' , 'label' , 'cidr' ],
619+ }
620+
621+ # Overwrite default methods.
622+ network_methods .update (methods )
623+
624+ network = fakes .FakeResource (info = copy .deepcopy (network_attrs ),
625+ methods = copy .deepcopy (network_methods ),
626+ loaded = True )
627+
628+ return network
629+
630+ @staticmethod
631+ def create_networks (attrs = {}, methods = {}, count = 2 ):
632+ """Create multiple fake networks.
633+
634+ :param Dictionary attrs:
635+ A dictionary with all attributes
636+ :param Dictionary methods:
637+ A dictionary with all methods
638+ :param int count:
639+ The number of networks to fake
640+ :return:
641+ A list of FakeResource objects faking the networks
642+ """
643+ networks = []
644+ for i in range (0 , count ):
645+ networks .append (FakeNetwork .create_one_network (attrs , methods ))
646+
647+ return networks
0 commit comments