Browse Source

Rename Quantum to Neutron

quantumclient is gone upstream and has been replaced by neutronclient.

This patch retains the OS::Quantum::XX namespace

Fixes: bug #1197208

Change-Id: Id48f9598ea1884132d411ad533770ae49494102b
changes/37/40537/5
Steven Dake 8 years ago
parent
commit
ed0fb7e823
  1. 2
      README.rst
  2. 2
      doc/docbkx/heat-cli-guide/src/heat_cli_howto.xml
  3. 22
      heat/engine/clients.py
  4. 4
      heat/engine/resource.py
  5. 6
      heat/engine/resources/instance.py
  6. 10
      heat/engine/resources/internet_gateway.py
  7. 14
      heat/engine/resources/network_interface.py
  8. 0
      heat/engine/resources/neutron/__init__.py
  9. 33
      heat/engine/resources/neutron/floatingip.py
  10. 19
      heat/engine/resources/neutron/net.py
  11. 14
      heat/engine/resources/neutron/neutron.py
  12. 22
      heat/engine/resources/neutron/port.py
  13. 43
      heat/engine/resources/neutron/router.py
  14. 19
      heat/engine/resources/neutron/subnet.py
  15. 4
      heat/engine/resources/rackspace/rackspace_resource.py
  16. 32
      heat/engine/resources/route_table.py
  17. 32
      heat/engine/resources/security_group.py
  18. 16
      heat/engine/resources/subnet.py
  19. 24
      heat/engine/resources/vpc.py
  20. 18
      heat/tests/templates/Neutron.template
  21. 16
      heat/tests/templates/Neutron.yaml
  22. 10
      heat/tests/test_instance_network.py
  23. 286
      heat/tests/test_neutron.py
  24. 80
      heat/tests/test_security_group.py
  25. 6
      heat/tests/test_template_format.py
  26. 126
      heat/tests/test_vpc.py
  27. 2
      requirements.txt

2
README.rst

@ -36,4 +36,4 @@ We have integration with
* https://github.com/openstack/python-novaclient (instance)
* https://github.com/openstack/python-keystoneclient (auth)
* https://github.com/openstack/python-swiftclient (s3)
* https://github.com/openstack/python-quantumclient (networking)
* https://github.com/openstack/python-neutronclient (networking)

2
doc/docbkx/heat-cli-guide/src/heat_cli_howto.xml

@ -5,7 +5,7 @@
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:html="http://www.w3.org/1999/xhtml"
version="5.0"
xml:id="quantum-cli-reference">
xml:id="neutron-cli-reference">
<?dbhtml stop-chunking?>
<title>OpenStack Heat CLI Guide</title>
<para>This section describes heat commands</para>

22
heat/engine/clients.py

@ -29,10 +29,10 @@ except ImportError:
swiftclient = None
logger.info('swiftclient not available')
try:
from quantumclient.v2_0 import client as quantumclient
from neutronclient.v2_0 import client as neutronclient
except ImportError:
quantumclient = None
logger.info('quantumclient not available')
neutronclient = None
logger.info('neutronclient not available')
try:
from cinderclient import client as cinderclient
except ImportError:
@ -64,7 +64,7 @@ class OpenStackClients(object):
self._nova = {}
self._keystone = None
self._swift = None
self._quantum = None
self._neutron = None
self._cinder = None
self._ceilometer = None
@ -133,15 +133,15 @@ class OpenStackClients(object):
self._swift = swiftclient.Connection(**args)
return self._swift
def quantum(self):
if quantumclient is None:
def neutron(self):
if neutronclient is None:
return None
if self._quantum:
return self._quantum
if self._neutron:
return self._neutron
con = self.context
if self.auth_token is None:
logger.error("Quantum connection failed, no auth_token!")
logger.error("Neutron connection failed, no auth_token!")
return None
args = {
@ -151,9 +151,9 @@ class OpenStackClients(object):
'endpoint_url': self.url_for(service_type='network')
}
self._quantum = quantumclient.Client(**args)
self._neutron = neutronclient.Client(**args)
return self._quantum
return self._neutron
def cinder(self):
if cinderclient is None:

4
heat/engine/resource.py

@ -325,8 +325,8 @@ class Resource(object):
def swift(self):
return self.stack.clients.swift()
def quantum(self):
return self.stack.clients.quantum()
def neutron(self):
return self.stack.clients.neutron()
def cinder(self):
return self.stack.clients.cinder()

6
heat/engine/resources/instance.py

@ -280,9 +280,9 @@ class Instance(resource.Resource):
else:
# if SubnetId property in Instance, ensure subnet exists
if subnet_id:
quantumclient = self.quantum()
neutronclient = self.neutron()
network_id = NetworkInterface.network_id_from_subnet_id(
quantumclient, subnet_id)
neutronclient, subnet_id)
# if subnet verified, create a port to use this subnet
# if port is not created explicitly, nova will choose
# the first subnet in the given network.
@ -293,7 +293,7 @@ class Instance(resource.Resource):
'network_id': network_id,
'fixed_ips': [fixed_ip]
}
port = quantumclient.create_port({'port': props})['port']
port = neutronclient.create_port({'port': props})['port']
nics = [{'port-id': port['id']}]
return nics

10
heat/engine/resources/internet_gateway.py

@ -83,26 +83,26 @@ class VPCGatewayAttachment(resource.Resource):
deps += (self, route_table)
def handle_create(self):
client = self.quantum()
client = self.neutron()
external_network_id = InternetGateway.get_external_network_id(client)
for router in self._vpc_route_tables():
client.add_gateway_router(router.resource_id, {
'network_id': external_network_id})
def handle_delete(self):
from quantumclient.common.exceptions import QuantumClientException
from neutronclient.common.exceptions import NeutronClientException
client = self.quantum()
client = self.neutron()
for router in self._vpc_route_tables():
try:
client.remove_gateway_router(router.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {

14
heat/engine/resources/network_interface.py

@ -44,12 +44,12 @@ class NetworkInterface(resource.Resource):
}
@staticmethod
def network_id_from_subnet_id(quantumclient, subnet_id):
subnet_info = quantumclient.show_subnet(subnet_id)
def network_id_from_subnet_id(neutronclient, subnet_id):
subnet_info = neutronclient.show_subnet(subnet_id)
return subnet_info['subnet']['network_id']
def handle_create(self):
client = self.quantum()
client = self.neutron()
subnet_id = self.properties['SubnetId']
network_id = self.network_id_from_subnet_id(client, subnet_id)
@ -80,18 +80,18 @@ class NetworkInterface(resource.Resource):
self.resource_id_set(port['id'])
def handle_delete(self):
from quantumclient.common.exceptions import QuantumClientException
from neutronclient.common.exceptions import NeutronClientException
client = self.quantum()
client = self.neutron()
try:
client.delete_port(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {

0
heat/engine/resources/quantum/__init__.py → heat/engine/resources/neutron/__init__.py

33
heat/engine/resources/quantum/floatingip.py → heat/engine/resources/neutron/floatingip.py

@ -15,15 +15,15 @@
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
logger = logging.getLogger(__name__)
class FloatingIP(quantum.QuantumResource):
class FloatingIP(neutron.NeutronResource):
properties_schema = {'floating_network_id': {'Type': 'String',
'Required': True},
'value_specs': {'Type': 'Map',
@ -36,7 +36,8 @@ class FloatingIP(quantum.QuantumResource):
# depend on any RouterGateway in this template with the same
# network_id as this floating_network_id
for resource in self.stack.resources.itervalues():
if (resource.type() == 'OS::Quantum::RouterGateway' and
if ((resource.type() == 'OS::Neutron::RouterGateway' or
resource.type() == 'OS::Quantum::RouterGateway') and
resource.properties.get('network_id') ==
self.properties.get('floating_network_id')):
deps += (self, resource)
@ -45,29 +46,29 @@ class FloatingIP(quantum.QuantumResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
fip = self.quantum().create_floatingip({
fip = self.neutron().create_floatingip({
'floatingip': props})['floatingip']
self.resource_id_set(fip['id'])
def handle_delete(self):
client = self.quantum()
client = self.neutron()
try:
client.delete_floatingip(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def FnGetAtt(self, key):
try:
attributes = self.quantum().show_floatingip(
attributes = self.neutron().show_floatingip(
self.resource_id)['floatingip']
except QuantumClientException as ex:
except NeutronClientException as ex:
logger.warn("failed to fetch resource attributes: %s" % str(ex))
return None
return self.handle_get_attributes(self.name, key, attributes)
class FloatingIPAssociation(quantum.QuantumResource):
class FloatingIPAssociation(neutron.NeutronResource):
properties_schema = {'floatingip_id': {'Type': 'String',
'Required': True},
'port_id': {'Type': 'String',
@ -79,29 +80,31 @@ class FloatingIPAssociation(quantum.QuantumResource):
floatingip_id = props.pop('floatingip_id')
self.quantum().update_floatingip(floatingip_id, {
self.neutron().update_floatingip(floatingip_id, {
'floatingip': props})['floatingip']
self.resource_id_set('%s:%s' % (floatingip_id, props['port_id']))
def handle_delete(self):
if not self.resource_id:
return
client = self.quantum()
client = self.neutron()
(floatingip_id, port_id) = self.resource_id.split(':')
try:
client.update_floatingip(
floatingip_id,
{'floatingip': {'port_id': None}})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {
'OS::Neutron::FloatingIP': FloatingIP,
'OS::Neutron::FloatingIPAssociation': FloatingIPAssociation,
'OS::Quantum::FloatingIP': FloatingIP,
'OS::Quantum::FloatingIPAssociation': FloatingIPAssociation,
}

19
heat/engine/resources/quantum/net.py → heat/engine/resources/neutron/net.py

@ -15,16 +15,16 @@
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
from heat.engine import scheduler
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
logger = logging.getLogger(__name__)
class Net(quantum.QuantumResource):
class Net(neutron.NeutronResource):
properties_schema = {'name': {'Type': 'String'},
'value_specs': {'Type': 'Map',
'Default': {}},
@ -43,11 +43,11 @@ class Net(quantum.QuantumResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
net = self.quantum().create_network({'network': props})['network']
net = self.neutron().create_network({'network': props})['network']
self.resource_id_set(net['id'])
def _show_resource(self):
return self.quantum().show_network(
return self.neutron().show_network(
self.resource_id)['network']
def check_create_complete(self, *args):
@ -55,10 +55,10 @@ class Net(quantum.QuantumResource):
return self.is_built(attributes)
def handle_delete(self):
client = self.quantum()
client = self.neutron()
try:
client.delete_network(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
else:
@ -66,9 +66,10 @@ class Net(quantum.QuantumResource):
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {
'OS::Neutron::Net': Net,
'OS::Quantum::Net': Net,
}

14
heat/engine/resources/quantum/quantum.py → heat/engine/resources/neutron/neutron.py

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from quantumclient.common.exceptions import QuantumClientException
from neutronclient.common.exceptions import NeutronClientException
from heat.common import exception
from heat.engine import resource
@ -23,13 +23,13 @@ from heat.openstack.common import log as logging
logger = logging.getLogger(__name__)
class QuantumResource(resource.Resource):
class NeutronResource(resource.Resource):
def validate(self):
'''
Validate any of the provided params
'''
res = super(QuantumResource, self).validate()
res = super(NeutronResource, self).validate()
if res:
return res
return self.validate_properties(self.properties)
@ -54,7 +54,7 @@ class QuantumResource(resource.Resource):
def prepare_properties(properties, name):
'''
Prepares the property values so that they can be passed directly to
the Quantum call.
the Neutron call.
Removes None values and value_specs, merges value_specs with the main
values.
@ -91,13 +91,13 @@ class QuantumResource(resource.Resource):
return True
else:
raise exception.Error('%s resource[%s] status[%s]' %
('quantum reported unexpected',
('neutron reported unexpected',
attributes['name'], attributes['status']))
def _resolve_attribute(self, name):
try:
attributes = self._show_resource()
except QuantumClientException as ex:
except NeutronClientException as ex:
logger.warn("failed to fetch resource attributes: %s" % str(ex))
return None
return self.handle_get_attributes(self.name, name, attributes)
@ -107,7 +107,7 @@ class QuantumResource(resource.Resource):
try:
yield
self._show_resource()
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
return

22
heat/engine/resources/quantum/port.py → heat/engine/resources/neutron/port.py

@ -15,16 +15,16 @@
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
from heat.engine import scheduler
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
logger = logging.getLogger(__name__)
class Port(quantum.QuantumResource):
class Port(neutron.NeutronResource):
fixed_ip_schema = {'subnet_id': {'Type': 'String',
'Required': True},
@ -65,7 +65,8 @@ class Port(quantum.QuantumResource):
# to so all subnets in a network should be created before
# the ports in that network.
for resource in self.stack.resources.itervalues():
if (resource.type() == 'OS::Quantum::Subnet' and
if ((resource.type() == 'OS::Neutron::Subnet' or
resource.type() == 'OS::Quantum::Subnet') and
resource.properties.get('network_id') ==
self.properties.get('network_id')):
deps += (self, resource)
@ -74,11 +75,11 @@ class Port(quantum.QuantumResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
port = self.quantum().create_port({'port': props})['port']
port = self.neutron().create_port({'port': props})['port']
self.resource_id_set(port['id'])
def _show_resource(self):
return self.quantum().show_port(
return self.neutron().show_port(
self.resource_id)['port']
def check_create_complete(self, *args):
@ -86,10 +87,10 @@ class Port(quantum.QuantumResource):
return self.is_built(attributes)
def handle_delete(self):
client = self.quantum()
client = self.neutron()
try:
client.delete_port(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
else:
@ -97,9 +98,10 @@ class Port(quantum.QuantumResource):
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {
'OS::Neutron::Port': Port,
'OS::Quantum::Port': Port,
}

43
heat/engine/resources/quantum/router.py → heat/engine/resources/neutron/router.py

@ -14,18 +14,18 @@
# under the License.
from heat.engine import clients
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
from heat.engine import scheduler
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
from heat.openstack.common import log as logging
logger = logging.getLogger(__name__)
class Router(quantum.QuantumResource):
class Router(neutron.NeutronResource):
properties_schema = {'name': {'Type': 'String'},
'value_specs': {'Type': 'Map',
'Default': {}},
@ -44,11 +44,11 @@ class Router(quantum.QuantumResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
router = self.quantum().create_router({'router': props})['router']
router = self.neutron().create_router({'router': props})['router']
self.resource_id_set(router['id'])
def _show_resource(self):
return self.quantum().show_router(
return self.neutron().show_router(
self.resource_id)['router']
def check_create_complete(self, *args):
@ -56,17 +56,17 @@ class Router(quantum.QuantumResource):
return self.is_built(attributes)
def handle_delete(self):
client = self.quantum()
client = self.neutron()
try:
client.delete_router(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
else:
return scheduler.TaskRunner(self._confirm_delete)()
class RouterInterface(quantum.QuantumResource):
class RouterInterface(neutron.NeutronResource):
properties_schema = {'router_id': {'Type': 'String',
'Required': True},
'subnet_id': {'Type': 'String',
@ -75,24 +75,24 @@ class RouterInterface(quantum.QuantumResource):
def handle_create(self):
router_id = self.properties.get('router_id')
subnet_id = self.properties.get('subnet_id')
self.quantum().add_interface_router(
self.neutron().add_interface_router(
router_id,
{'subnet_id': subnet_id})
self.resource_id_set('%s:%s' % (router_id, subnet_id))
def handle_delete(self):
client = self.quantum()
client = self.neutron()
(router_id, subnet_id) = self.resource_id.split(':')
try:
client.remove_interface_router(
router_id,
{'subnet_id': subnet_id})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
class RouterGateway(quantum.QuantumResource):
class RouterGateway(neutron.NeutronResource):
properties_schema = {'router_id': {'Type': 'String',
'Required': True},
'network_id': {'Type': 'String',
@ -103,14 +103,16 @@ class RouterGateway(quantum.QuantumResource):
for resource in self.stack.resources.itervalues():
# depend on any RouterInterface in this template with the same
# router_id as this router_id
if (resource.type() == 'OS::Quantum::RouterInterface' and
if ((resource.type() == 'OS::Neutron::RouterInterface' or
resource.type() == 'OS::Quantum::RouterInterface') and
resource.properties.get('router_id') ==
self.properties.get('router_id')):
deps += (self, resource)
# depend on any subnet in this template with the same network_id
# as this network_id, as the gateway implicitly creates a port
# on that subnet
elif (resource.type() == 'OS::Quantum::Subnet' and
elif ((resource.type() == 'OS::Neutron::Subnet' or
resource.type() == 'OS::Quantum::Subnet') and
resource.properties.get('network_id') ==
self.properties.get('network_id')):
deps += (self, resource)
@ -118,26 +120,29 @@ class RouterGateway(quantum.QuantumResource):
def handle_create(self):
router_id = self.properties.get('router_id')
network_id = self.properties.get('network_id')
self.quantum().add_gateway_router(
self.neutron().add_gateway_router(
router_id,
{'network_id': network_id})
self.resource_id_set('%s:%s' % (router_id, network_id))
def handle_delete(self):
client = self.quantum()
client = self.neutron()
(router_id, network_id) = self.resource_id.split(':')
try:
client.remove_gateway_router(router_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {
'OS::Neutron::Router': Router,
'OS::Neutron::RouterInterface': RouterInterface,
'OS::Neutron::RouterGateway': RouterGateway,
'OS::Quantum::Router': Router,
'OS::Quantum::RouterInterface': RouterInterface,
'OS::Quantum::RouterGateway': RouterGateway,

19
heat/engine/resources/quantum/subnet.py → heat/engine/resources/neutron/subnet.py

@ -15,16 +15,16 @@
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
from heat.engine import scheduler
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
logger = logging.getLogger(__name__)
class Subnet(quantum.QuantumResource):
class Subnet(neutron.NeutronResource):
allocation_schema = {'start': {'Type': 'String',
'Required': True},
@ -68,27 +68,28 @@ class Subnet(quantum.QuantumResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
subnet = self.quantum().create_subnet({'subnet': props})['subnet']
subnet = self.neutron().create_subnet({'subnet': props})['subnet']
self.resource_id_set(subnet['id'])
def handle_delete(self):
client = self.quantum()
client = self.neutron()
try:
client.delete_subnet(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
else:
return scheduler.TaskRunner(self._confirm_delete)()
def _show_resource(self):
return self.quantum().show_subnet(self.resource_id)['subnet']
return self.neutron().show_subnet(self.resource_id)['subnet']
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {
'OS::Neutron::Subnet': Subnet,
'OS::Quantum::Subnet': Subnet,
}

4
heat/engine/resources/rackspace/rackspace_resource.py

@ -83,8 +83,8 @@ class RackspaceResource(resource.Resource):
return self._cloud_blockstore
def quantum(self):
'''Rackspace quantum client.'''
def neutron(self):
'''Rackspace neutron client.'''
if not self._cloud_nw:
self.__authenticate()
self._cloud_nw = self.pyrax.cloud_networks

32
heat/engine/resources/route_table.py

@ -16,11 +16,11 @@
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine import resource
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
from heat.engine.resources.vpc import VPC
if clients.quantumclient is not None:
from quantumclient.common.exceptions import QuantumClientException
if clients.neutronclient is not None:
from neutronclient.common.exceptions import NeutronClientException
logger = logging.getLogger(__name__)
@ -42,16 +42,16 @@ class RouteTable(resource.Resource):
}
def handle_create(self):
client = self.quantum()
client = self.neutron()
props = {'name': self.physical_resource_name()}
router = client.create_router({'router': props})['router']
self.resource_id_set(router['id'])
def check_create_complete(self, *args):
client = self.quantum()
client = self.neutron()
attributes = client.show_router(
self.resource_id)['router']
if not quantum.QuantumResource.is_built(attributes):
if not neutron.NeutronResource.is_built(attributes):
return False
network_id = self.properties.get('VpcId')
@ -66,19 +66,19 @@ class RouteTable(resource.Resource):
return True
def handle_delete(self):
client = self.quantum()
client = self.neutron()
router_id = self.resource_id
try:
client.delete_router(router_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
# just in case this router has been added to a gateway, remove it
try:
client.remove_gateway_router(router_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
@ -95,7 +95,7 @@ class SubnetRouteTableAssocation(resource.Resource):
}
def handle_create(self):
client = self.quantum()
client = self.neutron()
subnet_id = self.properties.get('SubnetId')
router_id = self.properties.get('RouteTableId')
@ -107,7 +107,7 @@ class SubnetRouteTableAssocation(resource.Resource):
client.remove_interface_router(
previous_router['id'],
{'subnet_id': subnet_id})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
@ -115,14 +115,14 @@ class SubnetRouteTableAssocation(resource.Resource):
router_id, {'subnet_id': subnet_id})
def _router_for_subnet(self, subnet_id):
client = self.quantum()
client = self.neutron()
subnet = client.show_subnet(
subnet_id)['subnet']
network_id = subnet['network_id']
return VPC.router_for_vpc(client, network_id)
def handle_delete(self):
client = self.quantum()
client = self.neutron()
subnet_id = self.properties.get('SubnetId')
router_id = self.properties.get('RouteTableId')
@ -130,7 +130,7 @@ class SubnetRouteTableAssocation(resource.Resource):
try:
client.remove_interface_router(router_id, {
'subnet_id': subnet_id})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
@ -140,13 +140,13 @@ class SubnetRouteTableAssocation(resource.Resource):
if default_router:
client.add_interface_router(
default_router['id'], {'subnet_id': subnet_id})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {

32
heat/engine/resources/security_group.py

@ -29,14 +29,14 @@ class SecurityGroup(resource.Resource):
'SecurityGroupEgress': {'Type': 'List'}}
def handle_create(self):
if self.properties['VpcId'] and clients.quantumclient is not None:
self._handle_create_quantum()
if self.properties['VpcId'] and clients.neutronclient is not None:
self._handle_create_neutron()
else:
self._handle_create_nova()
def _handle_create_quantum(self):
from quantumclient.common.exceptions import QuantumClientException
client = self.quantum()
def _handle_create_neutron(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
sec = client.create_security_group({'security_group': {
'name': self.physical_resource_name(),
@ -46,7 +46,7 @@ class SecurityGroup(resource.Resource):
self.resource_id_set(sec['id'])
if self.properties['SecurityGroupIngress']:
for i in self.properties['SecurityGroupIngress']:
# Quantum only accepts positive ints
# Neutron only accepts positive ints
if int(i['FromPort']) < 0:
i['FromPort'] = None
if int(i['ToPort']) < 0:
@ -66,7 +66,7 @@ class SecurityGroup(resource.Resource):
'security_group_id': sec['id']
}
})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code == 409:
# no worries, the rule is already there
pass
@ -87,7 +87,7 @@ class SecurityGroup(resource.Resource):
'security_group_id': sec['id']
}
})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code == 409:
# no worries, the rule is already there
pass
@ -128,8 +128,8 @@ class SecurityGroup(resource.Resource):
raise
def handle_delete(self):
if self.properties['VpcId'] and clients.quantumclient is not None:
self._handle_delete_quantum()
if self.properties['VpcId'] and clients.neutronclient is not None:
self._handle_delete_neutron()
else:
self._handle_delete_nova()
@ -149,28 +149,28 @@ class SecurityGroup(resource.Resource):
self.nova().security_groups.delete(self.resource_id)
self.resource_id = None
def _handle_delete_quantum(self):
from quantumclient.common.exceptions import QuantumClientException
client = self.quantum()
def _handle_delete_neutron(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
if self.resource_id is not None:
try:
sec = client.show_security_group(
self.resource_id)['security_group']
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise
else:
for rule in sec['security_group_rules']:
try:
client.delete_security_group_rule(rule['id'])
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise
try:
client.delete_security_group(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise
self.resource_id = None

16
heat/engine/resources/subnet.py

@ -43,7 +43,7 @@ class Subnet(resource.Resource):
}
def handle_create(self):
client = self.quantum()
client = self.neutron()
# TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
network_id = self.properties.get('VpcId')
@ -55,7 +55,7 @@ class Subnet(resource.Resource):
}
subnet = client.create_subnet({'subnet': props})['subnet']
router = VPC.router_for_vpc(self.quantum(), network_id)
router = VPC.router_for_vpc(self.neutron(), network_id)
if router:
client.add_interface_router(
router['id'],
@ -63,25 +63,25 @@ class Subnet(resource.Resource):
self.resource_id_set(subnet['id'])
def handle_delete(self):
from quantumclient.common.exceptions import QuantumClientException
from neutronclient.common.exceptions import NeutronClientException
client = self.quantum()
client = self.neutron()
network_id = self.properties.get('VpcId')
subnet_id = self.resource_id
try:
router = VPC.router_for_vpc(self.quantum(), network_id)
router = VPC.router_for_vpc(self.neutron(), network_id)
if router:
client.remove_interface_router(
router['id'],
{'subnet_id': subnet_id})
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
try:
client.delete_subnet(subnet_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
@ -92,7 +92,7 @@ class Subnet(resource.Resource):
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {

24
heat/engine/resources/vpc.py

@ -17,7 +17,7 @@ from heat.common import exception
from heat.engine import clients
from heat.openstack.common import log as logging
from heat.engine import resource
from heat.engine.resources.quantum import quantum
from heat.engine.resources.neutron import neutron
logger = logging.getLogger(__name__)
@ -43,7 +43,7 @@ class VPC(resource.Resource):
}
def handle_create(self):
client = self.quantum()
client = self.neutron()
# The VPC's net and router are associated by having identical names.
net_props = {'name': self.physical_resource_name()}
router_props = {'name': self.physical_resource_name()}
@ -59,7 +59,7 @@ class VPC(resource.Resource):
@staticmethod
def router_for_vpc(client, network_id):
# first get the quantum net
# first get the neutron net
net = VPC.network_for_vpc(client, network_id)
# then find a router with the same name
routers = client.list_routers(name=net['name'])['routers']
@ -73,31 +73,31 @@ class VPC(resource.Resource):
return routers[0]
def check_create_complete(self, *args):
net = self.network_for_vpc(self.quantum(), self.resource_id)
if not quantum.QuantumResource.is_built(net):
net = self.network_for_vpc(self.neutron(), self.resource_id)
if not neutron.NeutronResource.is_built(net):
return False
router = self.router_for_vpc(self.quantum(), self.resource_id)
return quantum.QuantumResource.is_built(router)
router = self.router_for_vpc(self.neutron(), self.resource_id)
return neutron.NeutronResource.is_built(router)
def handle_delete(self):
from quantumclient.common.exceptions import QuantumClientException
client = self.quantum()
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
router = self.router_for_vpc(client, self.resource_id)
try:
client.delete_router(router['id'])
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
try:
client.delete_network(self.resource_id)
except QuantumClientException as ex:
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
def resource_mapping():
if clients.quantumclient is None:
if clients.neutronclient is None:
return {}
return {

18
heat/tests/templates/Quantum.template → heat/tests/templates/Neutron.template

@ -1,7 +1,7 @@
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Template to test Quantum resources",
"Description" : "Template to test Neutron resources",
"Parameters" : {
@ -9,23 +9,23 @@
"Resources" : {
"network": {
"Type": "OS::Quantum::Net",
"Type": "OS::Neutron::Net",
"Properties": {
"name": "the_network"
}
},
"unnamed_network": {
"Type": "OS::Quantum::Net"
"Type": "OS::Neutron::Net"
},
"admin_down_network": {
"Type": "OS::Quantum::Net",
"Type": "OS::Neutron::Net",
"Properties": {
"admin_state_up": false
}
},
"subnet": {
"Type": "OS::Quantum::Subnet",
"Type": "OS::Neutron::Subnet",
"Properties": {
"network_id": { "Ref" : "network" },
"ip_version": 4,
@ -35,7 +35,7 @@
},
"port": {
"Type": "OS::Quantum::Port",
"Type": "OS::Neutron::Port",
"Properties": {
"device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
"name": "port1",
@ -48,11 +48,11 @@
},
"router": {
"Type": "OS::Quantum::Router"
"Type": "OS::Neutron::Router"
},
"router_interface": {
"Type": "OS::Quantum::RouterInterface",
"Type": "OS::Neutron::RouterInterface",
"Properties": {
"router_id": { "Ref" : "router" },
"subnet_id": { "Ref" : "subnet" }
@ -97,4 +97,4 @@
"Description" : "All attributes for router"
}
}
}
}

16
heat/tests/templates/Quantum.yaml → heat/tests/templates/Neutron.yaml

@ -1,16 +1,16 @@
HeatTemplateFormatVersion: '2012-12-12'
Description: Template to test Quantum resources
Description: Template to test Neutron resources
Resources:
network:
Type: OS::Quantum::Net
Type: OS::Neutron::Net
Properties: {name: the_network}
unnamed_network:
Type: 'OS::Quantum::Net'
Type: 'OS::Neutron::Net'
admin_down_network:
Type: OS::Quantum::Net
Type: OS::Neutron::Net
Properties: {admin_state_up: false}
subnet:
Type: OS::Quantum::Subnet
Type: OS::Neutron::Subnet
Properties:
network_id: {Ref: network}
ip_version: 4
@ -18,7 +18,7 @@ Resources:
allocation_pools:
- {end: 10.0.3.150, start: 10.0.3.20}
port:
Type: OS::Quantum::Port
Type: OS::Neutron::Port
Properties:
device_id: d6b4d3a5-c700-476f-b609-1493dd9dadc0
name: port1
@ -27,9 +27,9 @@ Resources:
- subnet_id: {Ref: subnet}
ip_address: 10.0.3.21
router:
Type: 'OS::Quantum::Router'
Type: 'OS::Neutron::Router'
router_interface:
Type: OS::Quantum::RouterInterface
Type: OS::Neutron::RouterInterface
Properties:
router_id: {Ref: router}
subnet_id: {Ref: subnet}

10
heat/tests/test_instance_network.py

@ -110,7 +110,7 @@ wp_template_with_nic = '''
'''
class FakeQuantum(object):
class FakeNeutron(object):
def show_subnet(self, subnet, **_params):
return {
@ -169,8 +169,8 @@ class instancesTest(HeatTestCase):
self.m.StubOutWithMock(instance, 'nova')
instance.nova().MultipleTimes().AndReturn(self.fc)
self.m.StubOutWithMock(instance, 'quantum')
instance.quantum().MultipleTimes().AndReturn(FakeQuantum())
self.m.StubOutWithMock(instance, 'neutron')
instance.neutron().MultipleTimes().AndReturn(FakeNeutron())
instance.t = instance.stack.resolve_runtime_data(instance.t)
@ -212,8 +212,8 @@ class instancesTest(HeatTestCase):
instance = instances.Instance('%s_name' % name,
t['Resources']['WebServer'], stack)
self.m.StubOutWithMock(nic, 'quantum')
nic.quantum().MultipleTimes().AndReturn(FakeQuantum())
self.m.StubOutWithMock(nic, 'neutron')
nic.neutron().MultipleTimes().AndReturn(FakeNeutron())
self.m.StubOutWithMock(instance, 'nova')
instance.nova().MultipleTimes().AndReturn(self.fc)

286
heat/tests/test_quantum.py → heat/tests/test_neutron.py

@ -21,10 +21,10 @@ from heat.common import template_format
from heat.engine import properties
from heat.engine import resource
from heat.engine import scheduler
from heat.engine.resources.quantum import net
from heat.engine.resources.quantum import subnet
from heat.engine.resources.quantum import router
from heat.engine.resources.quantum.quantum import QuantumResource as qr
from heat.engine.resources.neutron import net
from heat.engine.resources.neutron import subnet
from heat.engine.resources.neutron import router
from heat.engine.resources.neutron.neutron import NeutronResource as qr
from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase
from heat.tests import fakes
@ -32,32 +32,32 @@ from heat.tests import utils
from heat.tests.utils import setup_dummy_db
from heat.tests.utils import parse_stack
quantumclient = try_import('quantumclient.v2_0.client')
qe = try_import('quantumclient.common.exceptions')
neutronclient = try_import('neutronclient.v2_0.client')
qe = try_import('neutronclient.common.exceptions')
quantum_template = '''
neutron_template = '''
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Template to test Quantum resources",
"Description" : "Template to test Neutron resources",
"Parameters" : {},
"Resources" : {
"network": {
"Type": "OS::Quantum::Net",
"Type": "OS::Neutron::Net",
"Properties": {
"name": "the_network"
}
},
"unnamed_network": {
"Type": "OS::Quantum::Net"
"Type": "OS::Neutron::Net"
},
"admin_down_network": {
"Type": "OS::Quantum::Net",
"Type": "OS::Neutron::Net",
"Properties": {
"admin_state_up": false
}
},
"subnet": {
"Type": "OS::Quantum::Subnet",
"Type": "OS::Neutron::Subnet",
"Properties": {
"network_id": { "Ref" : "network" },
"ip_version": 4,
@ -67,7 +67,7 @@ quantum_template = '''
}
},
"port": {
"Type": "OS::Quantum::Port",
"Type": "OS::Neutron::Port",
"Properties": {
"device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0",
"name": "port1",
@ -79,24 +79,24 @@ quantum_template = '''
}
},
"port2": {
"Type": "OS::Quantum::Port",
"Type": "OS::Neutron::Port",
"Properties": {
"name": "port2",
"network_id": { "Ref" : "network" }
}
},
"router": {
"Type": "OS::Quantum::Router"
"Type": "OS::Neutron::Router"
},
"router_interface": {
"Type": "OS::Quantum::RouterInterface",
"Type": "OS::Neutron::RouterInterface",
"Properties": {
"router_id": { "Ref" : "router" },
"subnet_id": { "Ref" : "subnet" }
}
},
"gateway": {
"Type": "OS::Quantum::RouterGateway",
"Type": "OS::Neutron::RouterGateway",
"Properties": {
"router_id": { "Ref" : "router" },
"network_id": { "Ref" : "network" }
@ -106,14 +106,14 @@ quantum_template = '''
}
'''
quantum_floating_template = '''
neutron_floating_template = '''
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Template to test Quantum resources",
"Description" : "Template to test Neutron resources",
"Parameters" : {},
"Resources" : {
"port_floating": {
"Type": "OS::Quantum::Port",
"Type": "OS::Neutron::Port",
"Properties": {
"network_id": "xyz1234",
"fixed_ips": [{
@ -123,23 +123,23 @@ quantum_floating_template = '''
}
},
"floating_ip": {
"Type": "OS::Quantum::FloatingIP",
"Type": "OS::Neutron::FloatingIP",
"Properties": {
"floating_network_id": "abcd1234",
}
},
"floating_ip_assoc": {
"Type": "OS::Quantum::FloatingIPAssociation",
"Type": "OS::Neutron::FloatingIPAssociation",
"Properties": {
"floatingip_id": { "Ref" : "floating_ip" },
"port_id": { "Ref" : "port_floating" }
}
},
"router": {
"Type": "OS::Quantum::Router"
"Type": "OS::Neutron::Router"
},
"gateway": {
"Type": "OS::Quantum::RouterGateway",
"Type": "OS::Neutron::RouterGateway",
"Properties": {
"router_id": { "Ref" : "router" },
"network_id": "abcd1234"
@ -150,7 +150,7 @@ quantum_floating_template = '''
'''
class QuantumTest(HeatTestCase):
class NeutronTest(HeatTestCase):
def test_validate_properties(self):
vs = {'router:external': True}
@ -205,14 +205,14 @@ class QuantumTest(HeatTestCase):
})
@skipIf(quantumclient is None, 'quantumclient unavailable')
class QuantumNetTest(HeatTestCase):
@skipIf(neutronclient is None, 'neutronclient unavailable')