Пример #1
0
    def create_network(self, context, network):
        LOG.debug(_("Create network in progress: %r"), network)
        session = context.session

        tenant_id = self._get_tenant_id_for_create(context, network['network'])
        # Create a new SDN-VE tenant if need be
        sdnve_tenant = self.sdnve_client.sdnve_check_and_create_tenant(
            tenant_id)
        if sdnve_tenant is None:
            raise sdnve_exc.SdnveException(
                msg=_('Create net failed: no SDN-VE tenant.'))

        with session.begin(subtransactions=True):
            net = super(SdnvePluginV2, self).create_network(context, network)
            self._process_l3_create(context, net, network['network'])

        # Create SDN-VE network
        (res, data) = self.sdnve_client.sdnve_create('network', net)
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2, self).delete_network(context, net['id'])
            raise sdnve_exc.SdnveException(
                msg=(_('Create net failed in SDN-VE: %s') % res))

        LOG.debug(_("Created network: %s"), net['id'])
        return net
Пример #2
0
    def create_router(self, context, router):
        LOG.debug(_("Create router in progress: %r"), router)

        if router['router']['admin_state_up'] is False:
            LOG.warning(
                _('Ignoring admin_state_up=False for router=%r.  '
                  'Overriding with True'), router)
            router['router']['admin_state_up'] = True

        tenant_id = self._get_tenant_id_for_create(context, router['router'])
        # Create a new Pinnaacles tenant if need be
        sdnve_tenant = self.sdnve_client.sdnve_check_and_create_tenant(
            tenant_id)
        if sdnve_tenant is None:
            raise sdnve_exc.SdnveException(
                msg=_('Create router failed: no SDN-VE tenant.'))

        new_router = super(SdnvePluginV2, self).create_router(context, router)
        # Create Sdnve router
        (res, data) = self.sdnve_client.sdnve_create('router', new_router)
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2, self).delete_router(context, new_router['id'])
            raise sdnve_exc.SdnveException(
                msg=(_('Create router failed in SDN-VE: %s') % res))

        LOG.debug(_("Router created: %r"), new_router)
        return new_router
Пример #3
0
    def add_router_interface(self, context, router_id, interface_info):
        LOG.debug(
            _("Add router interface in progress: "
              "router_id=%(router_id)s "
              "interface_info=%(interface_info)r"), {
                  'router_id': router_id,
                  'interface_info': interface_info
              })

        new_interface = super(SdnvePluginV2, self).add_router_interface(
            context, router_id, interface_info)
        LOG.debug(
            _("SdnvePluginV2.add_router_interface called. Port info: %s"),
            new_interface)
        request_info = interface_info.copy()
        request_info['port_id'] = new_interface['port_id']
        # Add the subnet_id to the request sent to the controller
        if 'subnet_id' not in interface_info:
            request_info['subnet_id'] = new_interface['subnet_id']

        (res, data) = self.sdnve_client.sdnve_update(
            'router', router_id + '/add_router_interface', request_info)
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2,
                  self).remove_router_interface(context, router_id,
                                                interface_info)
            raise sdnve_exc.SdnveException(
                msg=(_('Update router-add-interface failed in SDN-VE: %s') %
                     res))

        LOG.debug(_("Added router interface: %r"), new_interface)
        return new_interface
Пример #4
0
    def update_router(self, context, id, router):
        LOG.debug(
            _("Update router in progress: id=%(id)s "
              "router=%(router)r"), {
                  'id': id,
                  'router': router
              })
        session = context.session

        processed_request = {}
        if not router['router'].get('admin_state_up', True):
            raise n_exc.NotImplementedError(
                _('admin_state_up=False '
                  'routers are not '
                  'supported.'))

        with session.begin(subtransactions=True):
            original_router = super(SdnvePluginV2,
                                    self).get_router(context, id)
            processed_request['router'] = self._process_request(
                router['router'], original_router)
            updated_router = super(SdnvePluginV2,
                                   self).update_router(context, id, router)

        if processed_request['router']:
            (res, data) = self.sdnve_client.sdnve_update(
                'router', id, processed_request['router'])
            if res not in constants.HTTP_ACCEPTABLE:
                super(SdnvePluginV2,
                      self).update_router(context, id,
                                          {'router': original_router})
                raise sdnve_exc.SdnveException(
                    msg=(_('Update router failed in SDN-VE: %s') % res))

        return updated_router
Пример #5
0
    def update_subnet(self, context, id, subnet):
        LOG.debug(_("Update subnet in progress: %r"), subnet)
        session = context.session

        processed_request = {}
        with session.begin(subtransactions=True):
            original_subnet = super(SdnvePluginV2,
                                    self).get_subnet(context, id)
            processed_request['subnet'] = self._process_request(
                subnet['subnet'], original_subnet)
            updated_subnet = super(SdnvePluginV2,
                                   self).update_subnet(context, id, subnet)

        if processed_request['subnet']:
            # Note(mb): Use of string containing null required by controller
            if 'gateway_ip' in processed_request['subnet']:
                if processed_request['subnet'].get('gateway_ip') is None:
                    processed_request['subnet']['gateway_ip'] = 'null'
            (res, data) = self.sdnve_client.sdnve_update(
                'subnet', id, processed_request['subnet'])
            if res not in constants.HTTP_ACCEPTABLE:
                for key in subnet['subnet'].keys():
                    subnet['subnet'][key] = original_subnet[key]
                super(SdnvePluginV2, self).update_subnet(context, id, subnet)
                raise sdnve_exc.SdnveException(
                    msg=(_('Update subnet failed in SDN-VE: %s') % res))

        return updated_subnet
Пример #6
0
    def update_port(self, context, id, port):
        LOG.debug(_("Update port in progress: %r"), port)
        session = context.session

        processed_request = {}
        with session.begin(subtransactions=True):
            original_port = super(SdnvePluginV2, self).get_port(context, id)
            processed_request['port'] = self._process_request(
                port['port'], original_port)
            updated_port = super(SdnvePluginV2,
                                 self).update_port(context, id, port)

            os_tenant_id = updated_port['tenant_id']
            id_na, tenant_type = self.sdnve_client.sdnve_get_tenant_byid(
                os_tenant_id)
            self._update_base_binding_dict(tenant_type)
            self._process_portbindings_create_and_update(
                context, port['port'], updated_port)

        if processed_request['port']:
            (res,
             data) = self.sdnve_client.sdnve_update('port', id,
                                                    processed_request['port'])
            if res not in constants.HTTP_ACCEPTABLE:
                updated_port = super(SdnvePluginV2,
                                     self).update_port(context, id,
                                                       {'port': original_port})
                raise sdnve_exc.SdnveException(
                    msg=(_('Update port failed in SDN-VE: %s') % res))

        return updated_port
Пример #7
0
    def update_network(self, context, id, network):
        LOG.debug(_("Update network in progress: %r"), network)
        session = context.session

        processed_request = {}
        with session.begin(subtransactions=True):
            original_network = super(SdnvePluginV2,
                                     self).get_network(context, id)
            processed_request['network'] = self._process_request(
                network['network'], original_network)
            net = super(SdnvePluginV2,
                        self).update_network(context, id, network)
            self._process_l3_update(context, net, network['network'])

        if processed_request['network']:
            (res, data) = self.sdnve_client.sdnve_update(
                'network', id, processed_request['network'])
            if res not in constants.HTTP_ACCEPTABLE:
                net = super(SdnvePluginV2,
                            self).update_network(context, id,
                                                 {'network': original_network})
                raise sdnve_exc.SdnveException(
                    msg=(_('Update net failed in SDN-VE: %s') % res))

        return net
Пример #8
0
    def update_router(self, context, id, router):
        LOG.debug("Update router in progress: id=%(id)s "
                  "router=%(router)r",
                  {'id': id, 'router': router})
        session = context.session

        processed_request = {}
        if not router['router'].get('admin_state_up', True):
            raise n_exc.NotImplementedError(_('admin_state_up=False '
                                              'routers are not '
                                              'supported.'))

        with session.begin(subtransactions=True):
            original_router = super(SdnvePluginV2, self).get_router(
                context, id)
            processed_request['router'] = self._process_request(
                router['router'], original_router)
            updated_router = super(SdnvePluginV2, self).update_router(
                context, id, router)

        if processed_request['router']:
            egw = processed_request['router'].get('external_gateway_info')
            # Check for existing empty set (different from None) in request
            if egw == {}:
                processed_request['router'][
                    'external_gateway_info'] = {'network_id': 'null'}
            (res, data) = self.sdnve_client.sdnve_update(
                'router', id, processed_request['router'])
            if res not in constants.HTTP_ACCEPTABLE:
                super(SdnvePluginV2, self).update_router(
                    context, id, {'router': original_router})
                raise sdnve_exc.SdnveException(
                    msg=(_('Update router failed in SDN-VE: %s') % res))

        return updated_router
Пример #9
0
    def remove_router_interface(self, context, router_id, interface_info):
        LOG.debug("Remove router interface in progress: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})

        subnet_id = interface_info.get('subnet_id')
        port_id = interface_info.get('port_id')
        if not subnet_id:
            if not port_id:
                raise sdnve_exc.BadInputException(msg=_('No port ID'))
            myport = super(SdnvePluginV2, self).get_port(context, port_id)
            LOG.debug("SdnvePluginV2.remove_router_interface port: %s",
                      myport)
            myfixed_ips = myport.get('fixed_ips')
            if not myfixed_ips:
                raise sdnve_exc.BadInputException(msg=_('No fixed IP'))
            subnet_id = myfixed_ips[0].get('subnet_id')
            if subnet_id:
                interface_info['subnet_id'] = subnet_id
                LOG.debug(
                    "SdnvePluginV2.remove_router_interface subnet_id: %s",
                    subnet_id)
        else:
            if not port_id:
                # The backend requires port id info in the request
                subnet = super(SdnvePluginV2, self).get_subnet(context,
                                                               subnet_id)
                df = {'device_id': [router_id],
                      'device_owner': [n_const.DEVICE_OWNER_ROUTER_INTF],
                      'network_id': [subnet['network_id']]}
                ports = self.get_ports(context, filters=df)
                if ports:
                    pid = ports[0]['id']
                    interface_info['port_id'] = pid
                    msg = ("SdnvePluginV2.remove_router_interface "
                           "subnet_id: %(sid)s  port_id: %(pid)s")
                    LOG.debug(msg, {'sid': subnet_id, 'pid': pid})

        (res, data) = self.sdnve_client.sdnve_update(
            'router', router_id + '/remove_router_interface', interface_info)

        if res not in constants.HTTP_ACCEPTABLE:
            raise sdnve_exc.SdnveException(
                msg=(_('Update router-remove-interface failed SDN-VE: %s') %
                     res))

        session = context.session
        with session.begin(subtransactions=True):
            try:
                info = super(SdnvePluginV2, self).remove_router_interface(
                    context, router_id, interface_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self._add_router_interface_only(context,
                                                    router_id, interface_info)

        return info
Пример #10
0
    def create_port(self, context, port):
        LOG.debug("Create port in progress: %r", port)
        session = context.session

        # Set port status as 'ACTIVE' to avoid needing the agent
        port['port']['status'] = n_const.PORT_STATUS_ACTIVE
        port_data = port['port']

        with session.begin(subtransactions=True):
            port = super(SdnvePluginV2, self).create_port(context, port)
            if 'id' not in port:
                return port
            # If the tenant_id is set to '' by create_port, add the id to
            # the request being sent to the controller as the controller
            # requires a tenant id
            tenant_id = port.get('tenant_id')
            if not tenant_id:
                LOG.debug("Create port does not have tenant id info")
                original_network = super(SdnvePluginV2, self).get_network(
                    context, port['network_id'])
                original_tenant_id = original_network['tenant_id']
                port['tenant_id'] = original_tenant_id
                LOG.debug(
                    "Create port does not have tenant id info; "
                    "obtained is: %s",
                    port['tenant_id'])

            os_tenant_id = tenant_id
            id_na, tenant_type = self.sdnve_client.sdnve_get_tenant_byid(
                os_tenant_id)
            self._update_base_binding_dict(tenant_type)
            self._process_portbindings_create_and_update(context,
                                                         port_data, port)

        # NOTE(mb): Remove this block when controller is updated
        # Remove the information that the controller does not accept
        sdnve_port = port.copy()
        sdnve_port.pop('device_id', None)
        sdnve_port.pop('device_owner', None)

        (res, data) = self.sdnve_client.sdnve_create('port', sdnve_port)
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2, self).delete_port(context, port['id'])
            raise sdnve_exc.SdnveException(
                msg=(_('Create port failed in SDN-VE: %s') % res))

        LOG.debug("Created port: %s", port.get('id', 'id not found'))
        return port
Пример #11
0
    def create_floatingip(self, context, floatingip):
        LOG.debug(_("Create floatingip in progress: %r"), floatingip)
        new_floatingip = super(SdnvePluginV2,
                               self).create_floatingip(context, floatingip)

        (res,
         data) = self.sdnve_client.sdnve_create('floatingip',
                                                {'floatingip': new_floatingip})
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2,
                  self).delete_floatingip(context, new_floatingip['id'])
            raise sdnve_exc.SdnveException(
                msg=(_('Creating floating ip operation failed '
                       'in SDN-VE controller: %s') % res))

        LOG.debug(_("Created floatingip : %r"), new_floatingip)
        return new_floatingip
Пример #12
0
    def remove_router_interface(self, context, router_id, interface_info):
        LOG.debug(
            _("Remove router interface in progress: "
              "router_id=%(router_id)s "
              "interface_info=%(interface_info)r"), {
                  'router_id': router_id,
                  'interface_info': interface_info
              })

        subnet_id = interface_info.get('subnet_id')
        if not subnet_id:
            portid = interface_info.get('port_id')
            if not portid:
                raise sdnve_exc.BadInputException(msg=_('No port ID'))
            myport = super(SdnvePluginV2, self).get_port(context, portid)
            LOG.debug(_("SdnvePluginV2.remove_router_interface port: %s"),
                      myport)
            myfixed_ips = myport.get('fixed_ips')
            if not myfixed_ips:
                raise sdnve_exc.BadInputException(msg=_('No fixed IP'))
            subnet_id = myfixed_ips[0].get('subnet_id')
            if subnet_id:
                interface_info['subnet_id'] = subnet_id
                LOG.debug(
                    _("SdnvePluginV2.remove_router_interface subnet_id: %s"),
                    subnet_id)

        (res, data) = self.sdnve_client.sdnve_update(
            'router', router_id + '/remove_router_interface', interface_info)

        if res not in constants.HTTP_ACCEPTABLE:
            raise sdnve_exc.SdnveException(
                msg=(_('Update router-remove-interface failed SDN-VE: %s') %
                     res))

        session = context.session
        with session.begin(subtransactions=True):
            try:
                info = super(SdnvePluginV2, self).remove_router_interface(
                    context, router_id, interface_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self._add_router_interface_only(context, router_id,
                                                    interface_info)

        return info
Пример #13
0
    def create_subnet(self, context, subnet):
        LOG.debug(_("Create subnet in progress: %r"), subnet)
        new_subnet = super(SdnvePluginV2, self).create_subnet(context, subnet)

        # Note(mb): Use of null string currently required by controller
        sdnve_subnet = new_subnet.copy()
        if subnet.get('gateway_ip') is None:
            sdnve_subnet['gateway_ip'] = 'null'
        (res, data) = self.sdnve_client.sdnve_create('subnet', sdnve_subnet)
        if res not in constants.HTTP_ACCEPTABLE:
            super(SdnvePluginV2, self).delete_subnet(context, new_subnet['id'])
            raise sdnve_exc.SdnveException(
                msg=(_('Create subnet failed in SDN-VE: %s') % res))

        LOG.debug(_("Subnet created: %s"), new_subnet['id'])

        return new_subnet
Пример #14
0
    def update_floatingip(self, context, id, floatingip):
        LOG.debug(_("Update floatingip in progress: %r"), floatingip)
        session = context.session

        processed_request = {}
        with session.begin(subtransactions=True):
            original_floatingip = super(SdnvePluginV2,
                                        self).get_floatingip(context, id)
            processed_request['floatingip'] = self._process_request(
                floatingip['floatingip'], original_floatingip)
            updated_floatingip = super(SdnvePluginV2, self).update_floatingip(
                context, id, floatingip)

        if processed_request['floatingip']:
            (res, data) = self.sdnve_client.sdnve_update(
                'floatingip', id,
                {'floatingip': processed_request['floatingip']})
            if res not in constants.HTTP_ACCEPTABLE:
                super(SdnvePluginV2, self).update_floatingip(
                    context, id, {'floatingip': original_floatingip})
                raise sdnve_exc.SdnveException(
                    msg=(_('Update floating ip failed in SDN-VE: %s') % res))

        return updated_floatingip