예제 #1
0
파일: plugin.py 프로젝트: mshabdiz/neutron
 def _validate_create_subnet(self, subnet):
     if ('host_routes' in subnet
             and attributes.is_attr_set(subnet['host_routes'])):
         msg = 'host_routes extensions not supported for subnets'
         raise nuage_exc.OperationNotSupported(msg=msg)
     if subnet['gateway_ip'] is None:
         msg = "no-gateway option not supported with subnets"
         raise nuage_exc.OperationNotSupported(msg=msg)
예제 #2
0
 def _validate_nuage_sharedresource(self, context, resource, net_id):
     filter = {'network_id': [net_id]}
     existing_subn = self.get_subnets(context, filters=filter)
     if len(existing_subn) > 1:
         msg = _('Only one subnet is allowed per '
                 'external network %s') % net_id
         raise nuage_exc.OperationNotSupported(msg=msg)
     return existing_subn
예제 #3
0
    def _create_update_floatingip(self, context, neutron_fip, port_id):
        rtr_id = neutron_fip['router_id']
        net_id = neutron_fip['floating_network_id']

        fip_pool = self.nuageclient.get_nuage_fip_pool_by_id(net_id)
        if not fip_pool:
            msg = _('sharedresource %s not found on VSD') % net_id
            raise n_exc.BadRequest(resource='floatingip', msg=msg)

        ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
            context.session, rtr_id)
        if not ent_rtr_mapping:
            msg = _('router %s is not associated with '
                    'any net-partition') % rtr_id
            raise n_exc.BadRequest(resource='floatingip', msg=msg)

        params = {
            'router_id': ent_rtr_mapping['nuage_router_id'],
            'fip_id': neutron_fip['id'],
            'neutron_fip': neutron_fip
        }

        fip = self.nuageclient.get_nuage_fip_by_id(params)
        if not fip:
            params = {
                'nuage_rtr_id': ent_rtr_mapping['nuage_router_id'],
                'nuage_fippool_id': fip_pool['nuage_fip_pool_id'],
                'neutron_fip_ip': neutron_fip['floating_ip_address'],
                'neutron_fip_id': neutron_fip['id']
            }
            nuage_fip_id = self.nuageclient.create_nuage_floatingip(params)
        else:
            nuage_fip_id = fip['nuage_fip_id']

        # Update VM if required
        params = {
            'neutron_port_id': port_id,
            'nuage_fip_id': nuage_fip_id,
            'nuage_rtr_id': ent_rtr_mapping['nuage_router_id']
        }
        nuage_port = self.nuageclient.get_nuage_port_by_id(params)
        if nuage_port:
            if (nuage_port['nuage_domain_id']) != (
                    ent_rtr_mapping['nuage_router_id']):
                msg = _('Floating IP can not be associated to VM in '
                        'different router context')
                raise nuage_exc.OperationNotSupported(msg=msg)

            params = {
                'nuage_vport_id': nuage_port['nuage_vport_id'],
                'nuage_fip_id': nuage_fip_id
            }
            self.nuageclient.update_nuage_vm_vport(params)
예제 #4
0
 def _validate_update_network(self, context, id, network):
     req_data = network['network']
     is_external_set = req_data.get(external_net.EXTERNAL)
     if not attributes.is_attr_set(is_external_set):
         return (None, None)
     neutron_net = self.get_network(context, id)
     if neutron_net.get(external_net.EXTERNAL) == is_external_set:
         return (None, None)
     subnet = self._validate_nuage_sharedresource(context, 'network', id)
     if subnet and not is_external_set:
         msg = _('External network with subnets can not be '
                 'changed to non-external network')
         raise nuage_exc.OperationNotSupported(msg=msg)
     return (is_external_set, subnet)
예제 #5
0
    def _create_update_floatingip(self, context,
                                  neutron_fip, port_id):
        rtr_id = neutron_fip['router_id']
        net_id = neutron_fip['floating_network_id']

        fip_pool_mapping = nuagedb.get_fip_pool_from_netid(context.session,
                                                           net_id)
        fip_mapping = nuagedb.get_fip_mapping_by_id(context.session,
                                                    neutron_fip['id'])

        if not fip_mapping:
            ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
                context.session, rtr_id)
            if not ent_rtr_mapping:
                msg = _('router %s is not associated with '
                        'any net-partition') % rtr_id
                raise n_exc.BadRequest(resource='floatingip',
                                       msg=msg)
            params = {
                'nuage_rtr_id': ent_rtr_mapping['nuage_router_id'],
                'nuage_fippool_id': fip_pool_mapping['fip_pool_id'],
                'neutron_fip_ip': neutron_fip['floating_ip_address']
            }
            nuage_fip_id = self.nuageclient.create_nuage_floatingip(params)
            nuagedb.add_fip_mapping(context.session,
                                    neutron_fip['id'],
                                    rtr_id, nuage_fip_id)
        else:
            if rtr_id != fip_mapping['router_id']:
                msg = _('Floating IP can not be associated to VM in '
                        'different router context')
                raise nuage_exc.OperationNotSupported(msg=msg)
            nuage_fip_id = fip_mapping['nuage_fip_id']

        fip_pool_dict = {'router_id': neutron_fip['router_id']}
        nuagedb.update_fip_pool_mapping(fip_pool_mapping,
                                        fip_pool_dict)

        # Update VM if required
        port_mapping = nuagedb.get_port_mapping_by_id(context.session,
                                                      port_id)
        if port_mapping:
            params = {
                'nuage_vport_id': port_mapping['nuage_vport_id'],
                'nuage_fip_id': nuage_fip_id
            }
            self.nuageclient.update_nuage_vm_vport(params)
예제 #6
0
 def _validate_update_network(self, context, id, network):
     req_data = network['network']
     is_external_set = req_data.get(external_net.EXTERNAL)
     if not attributes.is_attr_set(is_external_set):
         return (None, None)
     neutron_net = self.get_network(context, id)
     if neutron_net.get(external_net.EXTERNAL) == is_external_set:
         return (None, None)
     subnet = self._validate_nuage_sharedresource(context, 'network', id)
     if subnet and not is_external_set:
         msg = _('External network with subnets can not be '
                 'changed to non-external network')
         raise nuage_exc.OperationNotSupported(msg=msg)
     if is_external_set:
         # Check if there are vm ports attached to this network
         # If there are, then updating the network is not allowed
         ports = self.get_ports(context, filters={'network_id': [id]})
         for p in ports:
             if p['device_owner'].startswith(
                     constants.NOVA_PORT_OWNER_PREF):
                 raise n_exc.NetworkInUse(net_id=id)
     return (is_external_set, subnet)