示例#1
0
    def get_info(self, instance):
        """Get the current status of an instance, by name (not ID!)

        Returns a dict containing:
        :state:           the running state, one of the power_state codes
        :max_mem:         (int) the maximum memory in KBytes allowed
        :mem:             (int) the memory in KBytes used by the domain
        :num_cpu:         (int) the number of virtual CPUs for the domain
        :cpu_time:        (int) the CPU time used in nanoseconds
        """

        node = bm_driver._get_baremetal_node_by_instance_uuid(instance["uuid"])
        macs = self.macs_for_instance(instance)
        nodename = self.xcat.get_xcat_node_name(macs)

        ps = self.xcat.get_node_power_state(nodename)
        if ps == power_states.ON:
            pstate = power_state.RUNNING
        elif ps == power_states.OFF:
            pstate = power_state.SHUTDOWN
        else:
            pstate = power_state.NOSTATE

        return {
            "state": pstate,
            "max_mem": node["memory_mb"],
            "mem": node["memory_mb"],
            "num_cpu": node["cpus"],
            "cpu_time": 0,
        }
示例#2
0
    def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None):
        """Reboot the specified instance.

        After this is called successfully, the instance's state
        goes back to power_state.RUNNING. The virtualization
        platform should ensure that the reboot action has completed
        successfully even in cases in which the underlying domain/vm
        is paused or halted/stopped.

        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param reboot_type: Either a HARD or SOFT reboot
        :param block_device_info: Info pertaining to attached volumes
        :param bad_volumes_callback: Function to handle any bad volumes
            encountered
        """
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(instance["uuid"])
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            self.xcat.reboot_node(nodename)
            bm_driver._update_state(context, node, instance, baremetal_states.RUNNING)
        except xcat_exception.xCATCommandError as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while rebooting instance %(instance)s " "on baremetal node %(node)s: %(error)s")
                    % {"instance": instance["uuid"], "node": node["uuid"], "error": str(e)}
                )
                bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
示例#3
0
    def get_info(self, instance):
        """Get the current status of an instance, by name (not ID!)

        Returns a dict containing:
        :state:           the running state, one of the power_state codes
        :max_mem:         (int) the maximum memory in KBytes allowed
        :mem:             (int) the memory in KBytes used by the domain
        :num_cpu:         (int) the number of virtual CPUs for the domain
        :cpu_time:        (int) the CPU time used in nanoseconds
        """

        node = bm_driver._get_baremetal_node_by_instance_uuid(instance['uuid'])
        macs = self.macs_for_instance(instance)
        nodename = self.xcat.get_xcat_node_name(macs)

        ps = self.xcat.get_node_power_state(nodename)
        if ps == power_states.ON:
            pstate = power_state.RUNNING
        elif ps == power_states.OFF:
            pstate = power_state.SHUTDOWN
        else:
            pstate = power_state.NOSTATE

        return {
            'state': pstate,
            'max_mem': node['memory_mb'],
            'mem': node['memory_mb'],
            'num_cpu': node['cpus'],
            'cpu_time': 0
        }
示例#4
0
文件: driver.py 项目: xcat2/xcat-core
    def destroy(self, instance, network_info, block_device_info=None,
                context=None):
        """Destroy (shutdown and delete) the specified instance.

        If the instance is not found (for example if networking failed), this
        function should still succeed.  It's probably a good idea to log a
        warning in that case.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices that should
                                  be detached from the instance.
        :param destroy_disks: Indicates if disks should be destroyed
        """
 	    #import pdb
	    #pdb.set_trace()
        context = nova_context.get_admin_context()
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(instance['uuid'])

        except exception.InstanceNotFound:
            LOG.warning(_("Destroy function called on a non-existing instance %s")
                        % instance['uuid'])
            return

        try:
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
            fixed_ip=None
            if interfaces and interfaces[0]:
                if CONF.use_ipv6:
                    fixed_ip = interfaces[0].get('address_v6')
                else:
                    fixed_ip = interfaces[0].get('address')
            if fixed_ip:
                self.xcat.cleanup_node(nodename, fixed_ip)
            else:
                self.xcat.cleanup_node(nodename)
        except Exception as e:
            #just log it and move on
            LOG.warning(_("Destroy called with xCAT error:" + str(e)))

        try:
            self._detach_block_devices(instance, block_device_info)
            self._stop_firewall(instance, network_info)
            self._unplug_vifs(instance, network_info)

            bm_driver._update_state(context, node, None, baremetal_states.DELETED)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error occurred while destroying instance %s: %s")
                          % (instance['uuid'], str(e)))
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)
示例#5
0
    def reboot(self,
               context,
               instance,
               network_info,
               reboot_type,
               block_device_info=None,
               bad_volumes_callback=None):
        """Reboot the specified instance.

        After this is called successfully, the instance's state
        goes back to power_state.RUNNING. The virtualization
        platform should ensure that the reboot action has completed
        successfully even in cases in which the underlying domain/vm
        is paused or halted/stopped.

        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param reboot_type: Either a HARD or SOFT reboot
        :param block_device_info: Info pertaining to attached volumes
        :param bad_volumes_callback: Function to handle any bad volumes
            encountered
        """
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(
                instance['uuid'])
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            self.xcat.reboot_node(nodename)
            bm_driver._update_state(context, node, instance,
                                    baremetal_states.RUNNING)
        except xcat_exception.xCATCommandError as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while rebooting instance %(instance)s "
                      "on baremetal node %(node)s: %(error)s") % {
                          'instance': instance['uuid'],
                          'node': node['uuid'],
                          'error': str(e)
                      })
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)
示例#6
0
    def destroy(self,
                instance,
                network_info,
                block_device_info=None,
                context=None):
        """Destroy (shutdown and delete) the specified instance.

        If the instance is not found (for example if networking failed), this
        function should still succeed.  It's probably a good idea to log a
        warning in that case.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices that should
                                  be detached from the instance.
        :param destroy_disks: Indicates if disks should be destroyed
        """
        #import pdb
        #pdb.set_trace()
        context = nova_context.get_admin_context()
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(
                instance['uuid'])

        except exception.InstanceNotFound:
            LOG.warning(
                _("Destroy function called on a non-existing instance %s") %
                instance['uuid'])
            return

        try:
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            interfaces = bm_utils.map_network_interfaces(
                network_info, CONF.use_ipv6)
            fixed_ip = None
            if interfaces and interfaces[0]:
                if CONF.use_ipv6:
                    fixed_ip = interfaces[0].get('address_v6')
                else:
                    fixed_ip = interfaces[0].get('address')
            if fixed_ip:
                self.xcat.cleanup_node(nodename, fixed_ip)
            else:
                self.xcat.cleanup_node(nodename)
        except Exception as e:
            #just log it and move on
            LOG.warning(_("Destroy called with xCAT error:" + str(e)))

        try:
            self._detach_block_devices(instance, block_device_info)
            self._stop_firewall(instance, network_info)
            self._unplug_vifs(instance, network_info)

            bm_driver._update_state(context, node, None,
                                    baremetal_states.DELETED)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occurred while destroying instance %s: %s") %
                    (instance['uuid'], str(e)))
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)