Ejemplo n.º 1
0
    def _get_resources_by_subnet(self, cntxt, neutron_client):
        try:
            subnets = neutron_client.list_subnets().get('subnets')
            subnets_metadata = {}

            allowed_keys = [
                'cidr', 'allocation_pools', 'description', 'dns_nameservers',
                'enable_dhcp', 'gateway_ip', 'host_routes', 'id', 'ip_version',
                'ipv6_address_mode', 'ipv6_ra_mode', 'name', 'network_id',
                'subnetpool_id', 'tenant_id'
            ]

            for subnet in subnets:
                subnet_metadata = {
                    k: subnet[k]
                    for k in subnet if k in allowed_keys
                }
                subnets_metadata[subnet["id"]] = subnet_metadata

            return subnets_metadata
        except Exception as e:
            LOG.exception("List all summary subnets from neutron failed.")
            raise exception.GetProtectionNetworkSubResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPES, reason=six.text_type(e))
        else:
            return []
Ejemplo n.º 2
0
    def _get_resources_by_network(self, cntxt, neutron_client):
        try:
            networks = neutron_client.list_networks().get('networks')
            networks_metadata = {}

            allowed_keys = [
                'id', 'admin_state_up', 'availability_zone_hints',
                'description', 'ipv4_address_scope', 'ipv6_address_scope',
                'mtu', 'name', 'port_security_enabled', 'router:external',
                'shared', 'status', 'subnets', 'tags', 'tenant_id'
            ]

            for network in networks:
                network_metadata = {
                    k: network[k]
                    for k in network if k in allowed_keys
                }
                networks_metadata[network["id"]] = network_metadata
            return networks_metadata
        except Exception as e:
            LOG.exception("List all summary networks from neutron failed.")
            raise exception.GetProtectionNetworkSubResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPES, reason=six.text_type(e))
        else:
            return []
    def _get_resources_by_port(self, cntxt, neutron_client):
        try:
            ports = neutron_client.list_ports(
                project_id=cntxt.project_id).get('ports')
            ports_metadata = {}

            allowed_keys = [
                'admin_state_up',
                'allowed_address_pairs',
                'description',
                'device_id',
                'device_owner',
                'extra_dhcp_opts',
                'fixed_ips',
                'id',
                'mac_address',
                'name',
                'network_id',
                'port_security_enabled',
                'security_groups',
                'status',
                'tenant_id'
                ]

            for port in ports:
                port_metadata = {
                    k: port[k] for k in port if k in allowed_keys}
                ports_metadata[port["id"]] = port_metadata
            return ports_metadata
        except Exception as e:
            LOG.exception("List all summary ports from neutron failed.")
            raise exception.GetProtectionNetworkSubResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPES,
                reason=six.text_type(e))
    def _get_resources_by_router(self, cntxt, neutron_client):
        try:
            routers = neutron_client.list_routers(
                project_id=cntxt.project_id).get('routers')
            routers_metadata = {}

            allowed_keys = [
                'admin_state_u',
                'availability_zone_hints',
                'description',
                'external_gateway_info',
                'id',
                'name',
                'routes',
                'status'
                ]

            for router in routers:
                router_metadata = {
                    k: router[k] for k in router if k in allowed_keys}
                routers_metadata[router["id"]] = router_metadata

            return routers_metadata
        except Exception as e:
            LOG.exception("List all summary routers from neutron failed.")
            raise exception.GetProtectionNetworkSubResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPES,
                reason=six.text_type(e))
Ejemplo n.º 5
0
    def _get_resources_by_security_group(self, cntxt, neutron_client):
        try:
            sgs = neutron_client.list_security_groups(
                project_id=cntxt.project_id).get('security_groups')
            sgs_metadata = {}

            allowed_keys = [
                'id', 'description', 'name', 'security_group_rules',
                'tenant_id'
            ]

            for sg in sgs:
                sg_metadata = {k: sg[k] for k in sg if k in allowed_keys}
                sgs_metadata[sg["id"]] = sg_metadata
            return sgs_metadata
        except Exception as e:
            LOG.exception("List all summary security_groups from neutron "
                          "failed.")
            raise exception.GetProtectionNetworkSubResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPES, reason=six.text_type(e))