@@ -298,6 +298,70 @@ def create_hypervisors_stats(attrs={}, count=2):
298298 return hypervisors
299299
300300
301+ class FakeSecurityGroup (object ):
302+ """Fake one or more security groups."""
303+
304+ @staticmethod
305+ def create_one_security_group (attrs = None , methods = None ):
306+ """Create a fake security group.
307+
308+ :param Dictionary attrs:
309+ A dictionary with all attributes
310+ :param Dictionary methods:
311+ A dictionary with all methods
312+ :return:
313+ A FakeResource object, with id, name, etc.
314+ """
315+ if attrs is None :
316+ attrs = {}
317+ if methods is None :
318+ methods = {}
319+
320+ # Set default attributes.
321+ security_group_attrs = {
322+ 'id' : 'security-group-id-' + uuid .uuid4 ().hex ,
323+ 'name' : 'security-group-name-' + uuid .uuid4 ().hex ,
324+ 'description' : 'security-group-description-' + uuid .uuid4 ().hex ,
325+ 'tenant_id' : 'project-id-' + uuid .uuid4 ().hex ,
326+ 'rules' : [],
327+ }
328+
329+ # Overwrite default attributes.
330+ security_group_attrs .update (attrs )
331+
332+ # Set default methods.
333+ security_group_methods = {}
334+
335+ # Overwrite default methods.
336+ security_group_methods .update (methods )
337+
338+ security_group = fakes .FakeResource (
339+ info = copy .deepcopy (security_group_attrs ),
340+ methods = copy .deepcopy (security_group_methods ),
341+ loaded = True )
342+ return security_group
343+
344+ @staticmethod
345+ def create_security_groups (attrs = None , methods = None , count = 2 ):
346+ """Create multiple fake security groups.
347+
348+ :param Dictionary attrs:
349+ A dictionary with all attributes
350+ :param Dictionary methods:
351+ A dictionary with all methods
352+ :param int count:
353+ The number of security groups to fake
354+ :return:
355+ A list of FakeResource objects faking the security groups
356+ """
357+ security_groups = []
358+ for i in range (0 , count ):
359+ security_groups .append (
360+ FakeSecurityGroup .create_one_security_group (attrs , methods ))
361+
362+ return security_groups
363+
364+
301365class FakeSecurityGroupRule (object ):
302366 """Fake one or more security group rules."""
303367
0 commit comments