def save_security_group_info(request, security_group_ids, path): path = u.join_path(path, "security_groups.json") sg = [] sg_manager = nova.SecurityGroupManager(request) for sg_id in security_group_ids: sg_info = sg_manager.get(sg_id).to_dict() sg.append(sg_info) sgs_info = {"security_groups": sg} u.save_to_json(path, sgs_info)
def __init__(self, request): neutron_enabled = base.is_service_enabled(request, 'network') if neutron_enabled: self.floating_ips = neutron.FloatingIpManager(request) else: self.floating_ips = nova.FloatingIpManager(request) if (neutron_enabled and neutron.is_extension_supported(request, 'security-group')): self.secgroups = neutron.SecurityGroupManager(request) else: self.secgroups = nova.SecurityGroupManager(request)
def recovery_sg(request, sg): sg_manager = nova.SecurityGroupManager(request) new_sg = sg_manager.create(sg['name'] + uuidutils.generate_uuid()[0:7], sg['description']).to_dict() sg_rules = sg['rules'] for rule in sg_rules: sg_manager.rule_create(parent_group_id=new_sg['id'], ip_protocol=rule['ip_protocol'], from_port=rule['from_port'], to_port=rule['to_port'], cidr=rule['ip_range']['cidr']) new_sg = sg_manager.get(new_sg['id']).to_dict() new_sg['old_id'] = sg['id'] return new_sg
def __init__(self, request): neutron_enabled = base.is_service_enabled(request, 'network') if neutron_enabled: self.floating_ips = neutron.FloatingIpManager(request) else: self.floating_ips = nova.FloatingIpManager(request) # Not all qunantum plugins support security group, # so we have enable_security_group configuration parameter. neutron_sg_enabled = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}).get('enable_security_group', True) if neutron_enabled and neutron_sg_enabled: self.secgroups = neutron.SecurityGroupManager(request) else: self.secgroups = nova.SecurityGroupManager(request)
def delete_sgs(request, sgs): sg_manager = nova.SecurityGroupManager(request) for sg in sgs: sg_manager.delete(sg['id'])