def get_info(self, instance_name): """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 """ LOG.debug("get_info") instance_id = self._instance_name_to_id(instance_name) bmm = db.bmm_get_by_instance_id(None, instance_id) status = PowerManager(bmm["ipmi_ip"]).status() if status == "on": inst_power_state = power_state.RUNNING else: inst_power_state = power_state.SHUTOFF return {'state': inst_power_state, 'max_mem': 0, 'mem': 0, 'num_cpu': 2, 'cpu_time': 0}
def get_info(self, instance_name): """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 """ LOG.debug("get_info") instance_id = self._instance_name_to_id(instance_name) bmm = db.bmm_get_by_instance_id(None, instance_id) status = PowerManager(bmm["ipmi_ip"]).status() if status == "on": inst_power_state = power_state.RUNNING else: inst_power_state = power_state.SHUTOFF return { 'state': inst_power_state, 'max_mem': 0, 'mem': 0, 'num_cpu': 2, 'cpu_time': 0 }
def destroy(self, context, instance, network_info, cleanup=True): """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 instance: Instance object as returned by DB layer. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param cleanup: """ LOG.debug("destroy") bmm = db.bmm_get_by_instance_id(context, instance["id"]) db.bmm_update(context, bmm["id"], {"status": "processing"}) mac = self._get_pxe_mac(bmm) # update ofc self._update_ofc_for_destroy(context, bmm) db.bmm_update(context, bmm["id"], { "vlan_id": None, "availability_zone": "resource_pool" }) # begin to delete os self._cp_template( "delete.sh", self._get_cobbler_instance_path(instance, "delete.sh"), { "INSTANCE_ID": instance["id"], "COBBLER": FLAGS.cobbler, "MONITOR_PORT": FLAGS.dodai_monitor_port }) self._cp_template( "pxeboot_action", self._get_pxe_boot_file(mac), { "INSTANCE_ID": instance["id"], "COBBLER": FLAGS.cobbler, "PXE_MAC": bmm["pxe_mac"], "ACTION": "delete" }) self._reboot_or_power_on(bmm["ipmi_ip"]) # wait until starting to delete os while self._get_state(context, instance) != "deleted": greenthread.sleep(20) LOG.debug("Wait until data of instance %s was deleted." % instance["id"]) utils.execute("rm", "-rf", self._get_cobbler_instance_path(instance)) # update db db.bmm_update(context, bmm["id"], { "instance_id": None, "service_ip": None }) return db.bmm_get(context, bmm["id"])
def reboot(self, instance, network_info): """Reboot the specified instance. :param instance: Instance object as returned by DB layer. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` """ LOG.debug("reboot") bmm = db.bmm_get_by_instance_id(None, instance["id"]) PowerManager(bmm["ipmi_ip"]).reboot()
def destroy(self, context, instance, network_info, cleanup=True): """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 instance: Instance object as returned by DB layer. :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param cleanup: """ LOG.debug("destroy") bmm = db.bmm_get_by_instance_id(context, instance["id"]) db.bmm_update(context, bmm["id"], {"status": "processing"}) mac = self._get_pxe_mac(bmm) # update ofc self._update_ofc_for_destroy(context, bmm) db.bmm_update(context, bmm["id"], {"vlan_id": None, "availability_zone": "resource_pool"}) # begin to delete os self._cp_template("delete.sh", self._get_cobbler_instance_path(instance, "delete.sh"), {"INSTANCE_ID": instance["id"], "COBBLER": FLAGS.cobbler, "MONITOR_PORT": FLAGS.dodai_monitor_port}) self._cp_template("pxeboot_action", self._get_pxe_boot_file(mac), {"INSTANCE_ID": instance["id"], "COBBLER": FLAGS.cobbler, "PXE_MAC": bmm["pxe_mac"], "ACTION": "delete"}) self._reboot_or_power_on(bmm["ipmi_ip"]) # wait until starting to delete os while self._get_state(context, instance) != "deleted": greenthread.sleep(20) LOG.debug("Wait until data of instance %s was deleted." % instance["id"]) utils.execute("rm", "-rf", self._get_cobbler_instance_path(instance)); # update db db.bmm_update(context, bmm["id"], {"instance_id": None, "service_ip": None}) return db.bmm_get(context, bmm["id"])
def start(self, context, instance): LOG.debug("start") bmm = db.bmm_get_by_instance_id(context, instance["id"]) PowerManager(bmm["ipmi_ip"]).on()