def _get_compute_nodes(self, accommodation): try: return nova.get_available_compute_nodes(self.openstack_client.nova) except nova.ForbiddenException: # user has no permissions to list compute nodes LOG.info('OpenStack user does not have permission to list compute ' 'nodes - treat him as non-admin') self.privileged_mode = False count = accommodation.get('compute_nodes') if not count: raise DeploymentException( 'When run with non-admin user the scenario must specify ' 'number of compute nodes to use') zones = accommodation.get('zones') or ['nova'] return [dict(host=None, zone=zones[n % len(zones)]) for n in range(count)]
def _deploy_from_hot(self, specification, base_dir=None): agents = generate_agents( nova.get_available_compute_nodes(self.openstack_client.nova), specification['vm_accommodation'], self.stack_name) # render template by jinja vars_values = { 'agents': agents, 'unique': self.stack_name, } heat_template = utils.read_file(specification['template'], base_dir=base_dir) compiled_template = jinja2.Template(heat_template) rendered_template = compiled_template.render(vars_values) LOG.debug('Rendered template: %s', rendered_template) # create stack by Heat merged_parameters = { 'server_endpoint': self.server_endpoint, 'external_net': self.external_net, 'image': self.image_name, 'flavor': self.flavor_name, } merged_parameters.update(specification.get('template_parameters', {})) stack_params = { 'stack_name': self.stack_name, 'parameters': merged_parameters, 'template': rendered_template, } LOG.debug('Creating stack with parameters: %s', stack_params) stack = self.openstack_client.heat.stacks.create( **stack_params)['stack'] LOG.info('New stack: %s', stack) heat.wait_stack_completion(self.openstack_client.heat, stack['id']) self.stack_deployed = True # get info about deployed objects outputs = heat.get_stack_outputs(self.openstack_client.heat, stack['id']) return filter_agents(agents, outputs)
def _deploy_from_hot(self, specification, base_dir=None): agents = generate_agents( nova.get_available_compute_nodes(self.openstack_client.nova), specification.get('accommodation') or specification.get('vm_accommodation'), self.stack_name) # render template by jinja vars_values = { 'agents': agents, 'unique': self.stack_name, } heat_template = utils.read_file(specification['template'], base_dir=base_dir) compiled_template = jinja2.Template(heat_template) rendered_template = compiled_template.render(vars_values) LOG.debug('Rendered template: %s', rendered_template) # create stack by Heat merged_parameters = { 'server_endpoint': self.server_endpoint, 'external_net': self.external_net, 'image': self.image_name, 'flavor': self.flavor_name, } merged_parameters.update(specification.get('template_parameters', {})) stack_id = heat.create_stack( self.openstack_client.heat, self.stack_name, rendered_template, merged_parameters) self.stack_created = True # get info about deployed objects outputs = heat.get_stack_outputs(self.openstack_client.heat, stack_id) override = self._get_override(specification.get('override')) return filter_agents(agents, outputs, override)
def _deploy_from_hot(self, specification, base_dir=None): agents = generate_agents( nova.get_available_compute_nodes(self.openstack_client.nova), specification.get('accommodation') or specification.get('vm_accommodation'), self.stack_name) # render template by jinja vars_values = { 'agents': agents, 'unique': self.stack_name, } heat_template = utils.read_file(specification['template'], base_dir=base_dir) compiled_template = jinja2.Template(heat_template) rendered_template = compiled_template.render(vars_values) LOG.debug('Rendered template: %s', rendered_template) # create stack by Heat merged_parameters = { 'server_endpoint': self.server_endpoint, 'external_net': self.external_net, 'image': self.image_name, 'flavor': self.flavor_name, } merged_parameters.update(specification.get('template_parameters', {})) stack_id = heat.create_stack(self.openstack_client.heat, self.stack_name, rendered_template, merged_parameters) self.stack_created = True # get info about deployed objects outputs = heat.get_stack_outputs(self.openstack_client.heat, stack_id) override = self._get_override(specification.get('override')) return filter_agents(agents, outputs, override)