Moving network_id_from_subnet_id to neutron client

Code for getting network_id from subnet_id is used in several resources.
So function network_id_from_subnet_id should be moved to neutron client
plugin, because it will allow to avoid strange references on
NetworkInterface resource.

Change-Id: I18dfb9a21fdca7a3d047c1cc2e8950bec9622d8c
This commit is contained in:
Sergey Kraynev 2014-07-08 03:18:13 -04:00
parent 319651aaf8
commit 18921d6a22
5 changed files with 22 additions and 10 deletions

View File

@ -77,6 +77,10 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
props.pop(subnet_key)
return props[subnet_id_key]
def network_id_from_subnet_id(self, subnet_id):
subnet_info = self.client().show_subnet(subnet_id)
return subnet_info['subnet']['network_id']
class NetworkConstraint(constraints.BaseCustomConstraint):

View File

@ -21,7 +21,6 @@ from heat.engine import attributes
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.network_interface import NetworkInterface
from heat.engine.resources.neutron import neutron
from heat.engine.resources import volume
from heat.engine import scheduler
@ -468,8 +467,9 @@ class Instance(resource.Resource):
# if SubnetId property in Instance, ensure subnet exists
if subnet_id:
neutronclient = self.neutron()
network_id = NetworkInterface.network_id_from_subnet_id(
neutronclient, subnet_id)
network_id = \
self.client_plugin('neutron').network_id_from_subnet_id(
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.

View File

@ -103,7 +103,8 @@ class NetworkInterface(resource.Resource):
client = self.neutron()
subnet_id = self.properties[self.SUBNET_ID]
network_id = self.network_id_from_subnet_id(client, subnet_id)
network_id = self.client_plugin().network_id_from_subnet_id(
subnet_id)
fixed_ip = {'subnet_id': subnet_id}
if self.properties[self.PRIVATE_IP_ADDRESS]:

View File

@ -23,12 +23,12 @@ from neutronclient.v2_0 import client as neutronclient
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.clients.os import neutron
from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
from heat.engine.resources import instance as instances
from heat.engine.resources import network_interface
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -1271,11 +1271,9 @@ class InstancesTest(HeatTestCase):
neutronclient.Client, 'list_security_groups')
neutronclient.Client.list_security_groups().AndReturn(
fake_groups_list)
net_interface = network_interface.NetworkInterface
self.m.StubOutWithMock(net_interface, 'network_id_from_subnet_id')
net_interface.network_id_from_subnet_id(
nclient,
self.m.StubOutWithMock(neutron.NeutronClientPlugin,
'network_id_from_subnet_id')
neutron.NeutronClientPlugin.network_id_from_subnet_id(
'fake_subnet_id').MultipleTimes().AndReturn('fake_network_id')
if not get_secgroup_raises:

View File

@ -15,6 +15,7 @@ import uuid
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.clients.os import neutron
from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
@ -179,6 +180,10 @@ class instancesTest(HeatTestCase):
self.m.StubOutWithMock(instance, 'neutron')
instance.neutron().MultipleTimes().AndReturn(FakeNeutron())
self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create')
neutron.NeutronClientPlugin._create().MultipleTimes().AndReturn(
FakeNeutron())
# need to resolve the template functions
server_userdata = instance.client_plugin().build_userdata(
metadata,
@ -231,6 +236,10 @@ class instancesTest(HeatTestCase):
self.m.StubOutWithMock(nic, 'neutron')
nic.neutron().MultipleTimes().AndReturn(FakeNeutron())
self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create')
neutron.NeutronClientPlugin._create().MultipleTimes().AndReturn(
FakeNeutron())
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)