def list_by_instance(self, instance_id): """Gets security groups of an instance.""" # TODO(gabriel): This needs to be moved up to novaclient, and should # be removed once novaclient supports this call. security_groups = [] nclient = self.client resp, body = nclient.client.get('/servers/%s/os-security-groups' % instance_id) if body: # Wrap data in SG objects as novaclient would. sg_objs = [NovaSecurityGroup(nclient.security_groups, sg, loaded=True) for sg in body.get('security_groups', [])] # Then wrap novaclient's object with our own. Yes, sadly wrapping # with two layers of objects is necessary. security_groups = [SecurityGroup(sg) for sg in sg_objs] return security_groups
def server_security_groups(request, instance_id): """Gets security groups of an instance.""" # TODO(gabriel): This needs to be moved up to novaclient, and should # be removed once novaclient supports this call. security_groups = [] nclient = novaclient(request) resp, body = nclient.client.get('/servers/%s/os-security-groups' % instance_id) if body: # Wrap data in SG objects as novaclient would. sg_objs = [NovaSecurityGroup(nclient.security_groups, sg, loaded=True) for sg in body.get('security_groups', [])] # Then wrap novaclient's object with our own. Yes, sadly wrapping # with two layers of objects is necessary. security_groups = [SecurityGroup(sg) for sg in sg_objs] # Package up the rules, as well. for sg in security_groups: rule_objects = [SecurityGroupRule(rule) for rule in sg.rules] sg.rules = rule_objects return security_groups