def _get_db_nodes(): nodes = [] for i in range(5): n = models.Node() n.update(self.fake_node) nodes.append(n) return nodes
def create_node(self, values): # ensure defaults are present for new nodes if 'uuid' not in values: values['uuid'] = uuidutils.generate_uuid() if 'power_state' not in values: values['power_state'] = states.NOSTATE if 'provision_state' not in values: values['provision_state'] = states.ENROLL # TODO(zhenguo): Support creating node with tags if 'tags' in values: LOG.warning( _LW('Ignore the specified tags %(tags)s when creating node: ' '%(node)s.'), { 'tags': values['tags'], 'node': values['uuid'] }) del values['tags'] node = models.Node() node.update(values) with _session_for_write() as session: try: session.add(node) session.flush() except db_exc.DBDuplicateEntry as exc: if 'name' in exc.columns: raise exception.DuplicateName(name=values['name']) elif 'instance_uuid' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['instance_uuid'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) return node
def create_node(self, values): # ensure defaults are present for new nodes if 'uuid' not in values: values['uuid'] = uuidutils.generate_uuid() if 'power_state' not in values: values['power_state'] = states.NOSTATE if 'provision_state' not in values: values['provision_state'] = states.ENROLL # TODO(zhenguo): Support creating node with tags if 'tags' in values: msg = _("Cannot create node with tags.") raise exception.InvalidParameterValue(err=msg) node = models.Node() node.update(values) with _session_for_write() as session: try: session.add(node) session.flush() except db_exc.DBDuplicateEntry as exc: if 'name' in exc.columns: raise exception.DuplicateName(name=values['name']) elif 'instance_uuid' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['instance_uuid'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) # Set tags to [] for new created node node['tags'] = [] return node
def create_node(self, values): # ensure defaults are present for new nodes if not values.get('uuid'): values['uuid'] = utils.generate_uuid() if not values.get('power_state'): values['power_state'] = states.NOSTATE if not values.get('provision_state'): values['provision_state'] = states.NOSTATE node = models.Node() node.update(values) node.save() return node
def create_node(self, values): # ensure defaults are present for new nodes if not values.get('uuid'): values['uuid'] = uuidutils.generate_uuid() if not values.get('task_state'): values['task_state'] = states.NOSTATE if not values.get('properties'): values['properties'] = '{}' if not values.get('extra'): values['extra'] = '{}' if not values.get('driver_info'): values['driver_info'] = '{}' node = models.Node() node.update(values) node.save() return node
def get_test_node(**kw): node = models.Node() node.id = kw.get('id', 123) node.uuid = kw.get('uuid', '1be26c0b-03f2-4d2e-ae87-c02d7f33c123') node.task_state = kw.get('task_state', 'NOSTATE') node.instance_uuid = kw.get('instance_uuid', '8227348d-5f1d-4488-aad1-7c92b2d42504') node.control_driver = kw.get('control_driver', 'ipmi') node.control_info = kw.get('control_info', _control_info) node.deploy_driver = kw.get('deploy_driver', 'pxe') node.deploy_info = kw.get('deploy_info', _deploy_info) node.properties = kw.get('properties', _properties) return node
def create_node(self, values): # ensure defaults are present for new nodes if not values.get('uuid'): values['uuid'] = utils.generate_uuid() if not values.get('power_state'): values['power_state'] = states.NOSTATE if not values.get('provision_state'): values['provision_state'] = states.NOSTATE node = models.Node() node.update(values) try: node.save() except db_exc.DBDuplicateEntry as exc: if 'instance_uuid' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['instance_uuid'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) return node
def create_node(self, values): # ensure defaults are present for new nodes if 'uuid' not in values: values['uuid'] = uuidutils.generate_uuid() if 'power_state' not in values: values['power_state'] = states.NOSTATE if 'provision_state' not in values: # TODO(deva): change this to ENROLL values['provision_state'] = states.AVAILABLE node = models.Node() node.update(values) try: node.save() except db_exc.DBDuplicateEntry as exc: if 'name' in exc.columns: raise exception.DuplicateName(name=values['name']) elif 'instance_uuid' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['instance_uuid'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) return node
def get_test_node(**kw): power_info = json.dumps({ 'driver': 'ipmi', 'user': '******', 'password': '******', 'address': 'fake-address' }) node = models.Node() node.id = kw.get('id', 123) node.uuid = kw.get('uuid', '1be26c0b-03f2-4d2e-ae87-c02d7f33c123') node.cpu_arch = kw.get('cpu_arch', 'x86_64') node.cpu_num = kw.get('cpu_num', 4) node.local_storage_max = kw.get('local_storage_max', 1000) node.task_state = kw.get('task_state', 'NOSTATE') node.image_path = kw.get('image_path', '/fake/image/path') node.instance_uuid = kw.get('instance_uuid', '8227348d-5f1d-4488-aad1-7c92b2d42504') node.instance_name = kw.get('instance_name', 'fake-image-name') node.power_info = kw.get('power_info', power_info) node.extra = kw.get('extra', '{}') return node
def create_node(self, values): # ensure defaults are present for new nodes if 'uuid' not in values: values['uuid'] = uuidutils.generate_uuid() if 'power_state' not in values: values['power_state'] = states.NOSTATE if 'provision_state' not in values: values['provision_state'] = states.ENROLL node = models.Node() node.update(values) with _session_for_write() as session: try: session.add(node) session.flush() except db_exc.DBDuplicateEntry as exc: if 'name' in exc.columns: raise exception.DuplicateName(name=values['name']) elif 'instance_uuid' in exc.columns: raise exception.InstanceAssociated( instance_uuid=values['instance_uuid'], node=values['uuid']) raise exception.NodeAlreadyExists(uuid=values['uuid']) return node
def _get_db_node(): n = models.Node() n.update(self.fake_node) return n
def convert_nova_nodes(nodes, cpu_arch, nova_conf): ironic_nodes = [] for n_node in nodes: # Create an empty Ironic Node i_node = ironic_models.Node() # Populate basic properties i_node.id = n_node.id i_node.uuid = n_node.uuid i_node.chassis_id = None i_node.last_error = None i_node.instance_uuid = n_node.instance_uuid i_node.reservation = None i_node.maintenance = False i_node.updated_at = n_node.updated_at i_node.created_at = n_node.created_at # Populate states if n_node.task_state == nova_states.ACTIVE: i_node.power_state = ironic_states.POWER_ON else: i_node.power_state = ironic_states.POWER_OFF i_node.target_power_state = None if i_node.instance_uuid: prov_state = ironic_states.ACTIVE else: prov_state = ironic_states.NOSTATE i_node.provision_state = prov_state i_node.target_provision_state = None # Populate extra properties i_node.extra = {} # Populate driver_info i_node.driver_info = {} power_manager = nova_conf['power_manager'] if power_manager.endswith('IPMI'): i_node.driver = 'pxe_ipmitool' if n_node.pm_address: i_node.driver_info['ipmi_address'] = n_node.pm_address if n_node.pm_user: i_node.driver_info['ipmi_username'] = n_node.pm_user if n_node.pm_password: i_node.driver_info['ipmi_password'] = n_node.pm_password elif power_manager.endswith('VirtualPowerManager'): i_node.driver = 'pxe_ssh' i_node.driver_info = { 'ssh_virt_type': nova_conf['virtual_power_type'], 'ssh_address': nova_conf['virtual_power_ssh_host'], 'ssh_username': nova_conf['virtual_power_host_user'], } ssh_port = nova_conf.get('ssh_port') if ssh_port: ssh_port = nova_conf['virtual_power_ssh_port'] ssh_key = nova_conf.get('virtual_power_host_key') if ssh_key: i_node.driver_info['ssh_key_filename'] = ssh_key ssh_pass = nova_conf.get('virtual_power_host_pass') if ssh_pass: i_node.driver_info['ssh_password'] = ssh_pass else: print("This does not support migration from power driver: " "%s\n" % nova_conf['driver'], file=sys.stderr) sys.exit(2) # Populate instance_info i_node.instance_info = {} if n_node.root_mb: i_node.instance_info['root_mb'] = n_node.root_mb if n_node.swap_mb: i_node.instance_info['swap_mb'] = n_node.swap_mb if n_node.ephemeral_mb: i_node.instance_info['ephemeral_mb'] = n_node.ephemeral_mb i_node.properties = { 'cpu_arch': cpu_arch, 'cpus': n_node.cpus, 'local_gb': n_node.local_gb, 'memory_mb': n_node.memory_mb } ironic_nodes.append(i_node) return ironic_nodes
def create_node(self, values): node = models.Node() node.update(values) node.save() return node