aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/orchestrator/heat.py
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/orchestrator/heat.py')
-rw-r--r--yardstick/orchestrator/heat.py59
1 files changed, 38 insertions, 21 deletions
diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py
index 3c3d28146..d69f86044 100644
--- a/yardstick/orchestrator/heat.py
+++ b/yardstick/orchestrator/heat.py
@@ -26,21 +26,16 @@ import shade
import yardstick.common.openstack_utils as op_utils
from yardstick.common import exceptions
from yardstick.common import template_format
+from yardstick.common import constants as consts
log = logging.getLogger(__name__)
-HEAT_KEY_UUID_LENGTH = 8
-
PROVIDER_SRIOV = "sriov"
_DEPLOYED_STACKS = {}
-def get_short_key_uuid(uuid):
- return str(uuid)[:HEAT_KEY_UUID_LENGTH]
-
-
class HeatStack(object):
"""Represents a Heat stack (deployed template) """
@@ -50,6 +45,13 @@ class HeatStack(object):
self._cloud = shade.openstack_cloud()
self._stack = None
+ def _update_stack_tracking(self):
+ outputs = self._stack.outputs
+ self.outputs = {output['output_key']: output['output_value'] for output
+ in outputs}
+ if self.uuid:
+ _DEPLOYED_STACKS[self.uuid] = self._stack
+
def create(self, template, heat_parameters, wait, timeout):
"""Creates an OpenStack stack from a template"""
with tempfile.NamedTemporaryFile('wb', delete=False) as template_file:
@@ -58,11 +60,21 @@ class HeatStack(object):
self._stack = self._cloud.create_stack(
self.name, template_file=template_file.name, wait=wait,
timeout=timeout, **heat_parameters)
- outputs = self._stack.outputs
- self.outputs = {output['output_key']: output['output_value'] for output
- in outputs}
- if self.uuid:
- _DEPLOYED_STACKS[self.uuid] = self._stack
+
+ self._update_stack_tracking()
+
+ def get(self):
+ """Retrieves an existing stack from the target cloud
+
+ Returns a bool indicating whether the stack exists in the target cloud
+ If the stack exists, it will be stored as self._stack
+ """
+ self._stack = self._cloud.get_stack(self.name)
+ if not self._stack:
+ return False
+
+ self._update_stack_tracking()
+ return True
@staticmethod
def stacks_exist():
@@ -322,21 +334,24 @@ name (i.e. %s).
}
}
- def add_port(self, name, network_name, subnet_name, vnic_type, sec_group_id=None,
+ def add_port(self, name, network, sec_group_id=None,
provider=None, allowed_address_pairs=None):
"""add to the template a named Neutron Port
"""
- log.debug("adding Neutron::Port '%s', network:'%s', subnet:'%s', vnic_type:'%s', "
- "secgroup:%s", name, network_name, subnet_name, vnic_type, sec_group_id)
+ net_is_existing = network.net_flags.get(consts.IS_EXISTING)
+ depends_on = [] if net_is_existing else [network.subnet_stack_name]
+ fixed_ips = [{'subnet': network.subnet}] if net_is_existing else [
+ {'subnet': {'get_resource': network.subnet_stack_name}}]
+ network_ = network.name if net_is_existing else {
+ 'get_resource': network.stack_name}
self.resources[name] = {
'type': 'OS::Neutron::Port',
- 'depends_on': [subnet_name],
+ 'depends_on': depends_on,
'properties': {
'name': name,
- 'binding:vnic_type': vnic_type,
- 'fixed_ips': [{'subnet': {'get_resource': subnet_name}}],
- 'network_id': {'get_resource': network_name},
- 'replacement_policy': 'AUTO',
+ 'binding:vnic_type': network.vnic_type,
+ 'fixed_ips': fixed_ips,
+ 'network': network_,
}
}
@@ -353,6 +368,8 @@ name (i.e. %s).
self.resources[name]['properties'][
'allowed_address_pairs'] = allowed_address_pairs
+ log.debug("adding Neutron::Port %s", self.resources[name])
+
self._template['outputs'][name] = {
'description': 'Address for interface %s' % name,
'value': {'get_attr': [name, 'fixed_ips', 0, 'ip_address']}
@@ -413,7 +430,7 @@ name (i.e. %s).
}
}
- def add_keypair(self, name, key_uuid):
+ def add_keypair(self, name, key_id):
"""add to the template a Nova KeyPair"""
log.debug("adding Nova::KeyPair '%s'", name)
self.resources[name] = {
@@ -425,7 +442,7 @@ name (i.e. %s).
pkg_resources.resource_string(
'yardstick.resources',
'files/yardstick_key-' +
- get_short_key_uuid(key_uuid) + '.pub'),
+ key_id + '.pub'),
'utf-8')
}
}