def _node_manage_power(self, state, retry=60): if state is None: raise exception.IllegalArgumentException( message=_("The target state is not defined")) ironic_client = self.osc.ironic() nova_client = self.osc.nova() current_state = ironic_client.node.get(self.node_uuid).power_state # power state: 'power on' or 'power off', if current node state # is the same as state, just return True if state in current_state: return True if state == NodeState.POWEROFF.value: node_info = ironic_client.node.get(self.node_uuid).to_dict() compute_node_id = node_info['extra']['compute_node_id'] compute_node = nova_client.hypervisors.get(compute_node_id) compute_node = compute_node.to_dict() if (compute_node['running_vms'] == 0): ironic_client.node.set_power_state(self.node_uuid, state) else: ironic_client.node.set_power_state(self.node_uuid, state) ironic_node = ironic_client.node.get(self.node_uuid) while ironic_node.power_state == current_state and retry: time.sleep(10) retry -= 1 ironic_node = ironic_client.node.get(self.node_uuid) if retry > 0: return True else: return False
def _nova_manage_service(self, state): if state is None: raise exception.IllegalArgumentException( message=_("The target state is not defined")) nova = nova_helper.NovaHelper(osc=self.osc) if state is True: return nova.enable_service_nova_compute(self.host) else: return nova.disable_service_nova_compute(self.host)
def _node_manage_power(self, state): if state is None: raise exception.IllegalArgumentException( message=_("The target state is not defined")) result = False ironic_client = self.osc.ironic() nova_client = self.osc.nova() if state == NodeState.POWEROFF.value: node_info = ironic_client.node.get(self.node_uuid).to_dict() compute_node_id = node_info['extra']['compute_node_id'] compute_node = nova_client.hypervisors.get(compute_node_id) compute_node = compute_node.to_dict() if (compute_node['running_vms'] == 0): result = ironic_client.node.set_power_state( self.node_uuid, state) else: result = ironic_client.node.set_power_state(self.node_uuid, state) return result
def add_change_node_state_actions(self, nodes, status): if status not in (element.ServiceState.DISABLED.value, element.ServiceState.ENABLED.value): raise exception.IllegalArgumentException( message=_("The node status is not defined")) changed_nodes = [] for node in nodes: if node.status != status: parameters = {'state': status, 'resource_name': node.hostname} if status == element.ServiceState.DISABLED.value: parameters['disabled_reason'] = self.REASON_FOR_DISABLE self.solution.add_action( action_type=self.CHANGE_NOVA_SERVICE_STATE, resource_id=node.uuid, input_parameters=parameters) node.status = status changed_nodes.append(node) return changed_nodes
def _nova_manage_service(self, state): if state is None: raise exception.IllegalArgumentException( message=_("The target state is not defined")) nova = nova_helper.NovaHelper(osc=self.osc) if state == element.ServiceState.ENABLED.value: return nova.enable_service_nova_compute(self.host) elif state == element.ServiceState.DISABLED.value: return nova.disable_service_nova_compute(self.host, 'watcher_disabled') elif state == element.ServiceState.MAINTAINING.value: return nova.disable_service_nova_compute(self.host, 'watcher_maintaining') # update disable reason if power-on or power-off one compute node, # for power saving elif state == element.ServiceState.POWERON.value: return nova.disable_service_nova_compute(self.host, 'watcher_poweron') elif state == element.ServiceState.POWEROFF.value: return nova.disable_service_nova_compute(self.host, 'watcher_poweroff')
def assert_node(obj): if not isinstance(obj, element.IronicNode): raise exception.IllegalArgumentException( message=_("'obj' argument type is not valid: %s") % type(obj))
def assert_instance(obj): if not isinstance(obj, element.Instance): raise exception.IllegalArgumentException( message=_("'obj' argument type is not valid"))
def assert_vm(self, obj): if not isinstance(obj, vm.VM): raise exception.IllegalArgumentException( message=_("'obj' argument type is not valid"))
def assert_hypervisor(self, obj): if not isinstance(obj, hypervisor.Hypervisor): raise exception.IllegalArgumentException( message=_("'obj' argument type is not valid"))
def assert_node(self, obj): if not isinstance(obj, element.ComputeNode): raise exception.IllegalArgumentException( message=_("'obj' argument type is not valid"))