def get_node_count(role, baremetal_client): count = 0 for n in baremetal_client.node.list(): node = baremetal_client.node.get(n.uuid) caps = nodes.capabilities_to_dict(node.properties['capabilities']) if caps.get('profile') == role: count += 1 return count
def run_module(): result = dict(success=False, error="", nodes=[]) argument_spec = openstack_full_argument_spec( **yaml.safe_load(DOCUMENTATION)['options']) module = AnsibleModule(argument_spec, supports_check_mode=True, **openstack_module_kwargs()) _, conn = openstack_cloud_from_module(module) tripleo = tc.TripleOCommon(session=conn.session) # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications if module.check_mode: module.exit_json(**result) nodes_json = nodes.convert_nodes_json_mac_to_ports( module.params['nodes_json']) for node in nodes_json: caps = node.get('capabilities', {}) caps = nodes.capabilities_to_dict(caps) if module.params['instance_boot_option'] is not None: caps.setdefault('boot_option', module.params['instance_boot_option']) node['capabilities'] = nodes.dict_to_capabilities(caps) baremetal_client = tripleo.get_baremetal_client() image_client = tripleo.get_image_client() try: registered_nodes = nodes.register_all_nodes( nodes_json, client=baremetal_client, remove=module.params['remove'], glance_client=image_client, kernel_name=module.params['kernel_name'], ramdisk_name=module.params['ramdisk_name']) result['success'] = True result['nodes'] = [ dict(uuid=node.uuid, provision_state=node.provision_state) for node in registered_nodes ] except Exception as exc: # LOG.exception("Error registering nodes with ironic.") result['error'] = str(exc) module.fail_json(msg='Validation Failed', **result) # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results module.exit_json(**result)
def run(self, context): baremetal_client = self.get_baremetal_client(context) image_client = self.get_image_client(context) try: image_ids = {'kernel': None, 'ramdisk': None} if self.kernel_name is not None and self.ramdisk_name is not None: image_ids = glance.create_or_find_kernel_and_ramdisk( image_client, self.kernel_name, self.ramdisk_name) node = baremetal_client.node.get(self.node_uuid) capabilities = node.properties.get('capabilities', {}) capabilities = nodes.capabilities_to_dict(capabilities) if self.instance_boot_option is not None: capabilities['boot_option'] = self.instance_boot_option else: # Add boot option capability if it didn't exist capabilities.setdefault('boot_option', self.instance_boot_option or 'local') capabilities = nodes.dict_to_capabilities(capabilities) baremetal_client.node.update(node.uuid, [ { 'op': 'add', 'path': '/properties/capabilities', 'value': capabilities, }, { 'op': 'add', 'path': '/driver_info/deploy_ramdisk', 'value': image_ids['ramdisk'], }, { 'op': 'add', 'path': '/driver_info/deploy_kernel', 'value': image_ids['kernel'], }, { 'op': 'add', 'path': '/driver_info/rescue_ramdisk', 'value': image_ids['ramdisk'], }, { 'op': 'add', 'path': '/driver_info/rescue_kernel', 'value': image_ids['kernel'], }, ]) LOG.debug("Configuring boot option for Node %s", self.node_uuid) except Exception as err: LOG.exception("Error configuring node boot options with Ironic.") return actions.Result(error=six.text_type(err))
def run(self, context): baremetal_client = self.get_baremetal_client(context) image_client = self.get_image_client(context) try: image_ids = {'kernel': None, 'ramdisk': None} if self.kernel_name is not None and self.ramdisk_name is not None: image_ids = glance.create_or_find_kernel_and_ramdisk( image_client, self.kernel_name, self.ramdisk_name) node = baremetal_client.node.get(self.node_uuid) capabilities = node.properties.get('capabilities', {}) capabilities = nodes.capabilities_to_dict(capabilities) if self.instance_boot_option is not None: capabilities['boot_option'] = self.instance_boot_option else: # Add boot option capability if it didn't exist capabilities.setdefault( 'boot_option', self.instance_boot_option or 'local') capabilities = nodes.dict_to_capabilities(capabilities) baremetal_client.node.update(node.uuid, [ { 'op': 'add', 'path': '/properties/capabilities', 'value': capabilities, }, { 'op': 'add', 'path': '/driver_info/deploy_ramdisk', 'value': image_ids['ramdisk'], }, { 'op': 'add', 'path': '/driver_info/deploy_kernel', 'value': image_ids['kernel'], }, ]) LOG.debug("Configuring boot option for Node %s", self.node_uuid) except Exception as err: LOG.exception("Error configuring node boot options with Ironic.") return actions.Result(error=six.text_type(err))
def run(self, context): for node in self.nodes_json: caps = node.get('capabilities', {}) caps = nodes.capabilities_to_dict(caps) caps.setdefault('boot_option', self.instance_boot_option) node['capabilities'] = nodes.dict_to_capabilities(caps) baremetal_client = self.get_baremetal_client(context) image_client = self.get_image_client(context) try: return nodes.register_all_nodes(self.nodes_json, client=baremetal_client, remove=self.remove, glance_client=image_client, kernel_name=self.kernel_name, ramdisk_name=self.ramdisk_name) except Exception as err: LOG.exception("Error registering nodes with ironic.") return actions.Result(error=six.text_type(err))
def run(self, context): for node in self.nodes_json: caps = node.get('capabilities', {}) caps = nodes.capabilities_to_dict(caps) caps.setdefault('boot_option', self.instance_boot_option) node['capabilities'] = nodes.dict_to_capabilities(caps) baremetal_client = self.get_baremetal_client(context) image_client = self.get_image_client(context) try: return nodes.register_all_nodes( self.nodes_json, client=baremetal_client, remove=self.remove, glance_client=image_client, kernel_name=self.kernel_name, ramdisk_name=self.ramdisk_name) except Exception as err: LOG.exception("Error registering nodes with ironic.") return actions.Result(error=six.text_type(err))
def run(self, context): warnings = [] errors = [] message = ("Node {uuid} has an incorrectly configured " "{property}. Expected \"{expected}\" but got " "\"{actual}\".") if self.node['driver_info'].get('deploy_ramdisk') != self.ramdisk_id: errors.append(message.format( uuid=self.node['uuid'], property='driver_info/deploy_ramdisk', expected=self.ramdisk_id, actual=self.node['driver_info'].get('deploy_ramdisk') )) if self.node['driver_info'].get('deploy_kernel') != self.kernel_id: errors.append(message.format( uuid=self.node['uuid'], property='driver_info/deploy_kernel', expected=self.kernel_id, actual=self.node['driver_info'].get('deploy_kernel') )) capabilities = nodeutils.capabilities_to_dict( self.node['properties'].get('capabilities', '')) if capabilities.get('boot_option') != 'local': boot_option_message = ("Node {uuid} is not configured to use " "boot_option:local in capabilities. It " "will not be used for deployment with " "flavors that require boot_option:local.") warnings.append(boot_option_message.format(uuid=self.node['uuid'])) return_value = { 'errors': errors, 'warnings': warnings } if errors: mistral_result = {'error': return_value} else: mistral_result = {'data': return_value} return actions.Result(**mistral_result)
def run(self): for node in self.nodes_json: caps = node.get('capabilities', {}) caps = nodes.capabilities_to_dict(caps) caps.setdefault('boot_option', self.instance_boot_option) node['capabilities'] = nodes.dict_to_capabilities(caps) baremetal_client = self._get_baremetal_client() image_client = self._get_image_client() try: return nodes.register_all_nodes( 'service_host', # unused self.nodes_json, client=baremetal_client, remove=self.remove, glance_client=image_client, kernel_name=self.kernel_name, ramdisk_name=self.ramdisk_name) except Exception as err: LOG.exception("Error registering nodes with ironic.") return mistral_workflow_utils.Result("", err.message)
def run(self): warnings = [] errors = [] message = ("Node {uuid} has an incorrectly configured " "{property}. Expected \"{expected}\" but got " "\"{actual}\".") if self.node['driver_info'].get('deploy_ramdisk') != self.ramdisk_id: errors.append( message.format( uuid=self.node['uuid'], property='driver_info/deploy_ramdisk', expected=self.ramdisk_id, actual=self.node['driver_info'].get('deploy_ramdisk'))) if self.node['driver_info'].get('deploy_kernel') != self.kernel_id: errors.append( message.format( uuid=self.node['uuid'], property='driver_info/deploy_kernel', expected=self.kernel_id, actual=self.node['driver_info'].get('deploy_kernel'))) capabilities = nodeutils.capabilities_to_dict( self.node['properties'].get('capabilities', '')) if capabilities.get('boot_option') != 'local': boot_option_message = ("Node {uuid} is not configured to use " "boot_option:local in capabilities. It " "will not be used for deployment with " "flavors that require boot_option:local.") warnings.append(boot_option_message.format(uuid=self.node['uuid'])) return_value = {'errors': errors, 'warnings': warnings} if errors: mistral_result = {'error': return_value} else: mistral_result = {'data': return_value} return mistral_workflow_utils.Result(**mistral_result)
def _node_get_capabilities(self, node): """Get node capabilities.""" return nodeutils.capabilities_to_dict( node['properties'].get('capabilities'))