nova/nova/api/openstack/compute/multinic.py
Stephen Finucane 998475f5bd nova-net: Remove unused nova-network objects
With the removal of the related quotas, the 'FixedIP', 'FloatingIP',
'SecurityGroupRule', 'Network' and 'NetworkList' objects can all be
deleted. As noted previously, the 'SecurityGroup' object must be
retained until we bump the 'Instance' object version to v3 and drop the
'security_group' field. In addition, we need to make a small change to
the object versioning test to ensure we're only testing objects in the
nova namespace. If we don't do this, we end up pulling in things like
os_vif objects. This was previously noted in change
Ica9f217d0318fc7c2db4bcdea12d00aad749c30c.

Change-Id: I6aba959eff1e50af4ac040148c7177f235a09a1f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-02-18 13:19:43 +00:00

70 lines
2.6 KiB
Python

# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""The multinic extension."""
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas import multinic
from nova.api.openstack import wsgi
from nova.api import validation
from nova.compute import api as compute
from nova import exception
from nova.policies import multinic as multinic_policies
class MultinicController(wsgi.Controller):
"""This API is deprecated from Microversion '2.44'."""
def __init__(self):
super(MultinicController, self).__init__()
self.compute_api = compute.API()
@wsgi.Controller.api_version("2.1", "2.43")
@wsgi.response(202)
@wsgi.action('addFixedIp')
@wsgi.expected_errors((400, 404))
@validation.schema(multinic.add_fixed_ip)
def _add_fixed_ip(self, req, id, body):
"""Adds an IP on a given network to an instance."""
context = req.environ['nova.context']
context.can(multinic_policies.BASE_POLICY_NAME)
instance = common.get_instance(self.compute_api, context, id)
network_id = body['addFixedIp']['networkId']
try:
self.compute_api.add_fixed_ip(context, instance, network_id)
except exception.NoMoreFixedIps as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
@wsgi.Controller.api_version("2.1", "2.43")
@wsgi.response(202)
@wsgi.action('removeFixedIp')
@wsgi.expected_errors((400, 404))
@validation.schema(multinic.remove_fixed_ip)
def _remove_fixed_ip(self, req, id, body):
"""Removes an IP from an instance."""
context = req.environ['nova.context']
context.can(multinic_policies.BASE_POLICY_NAME)
instance = common.get_instance(self.compute_api, context, id)
address = body['removeFixedIp']['address']
try:
self.compute_api.remove_fixed_ip(context, instance, address)
except exception.FixedIpNotFoundForInstance as e:
raise exc.HTTPBadRequest(explanation=e.format_message())