def delete_platform_instances(self, ptype, hostname): """删除异构平台上的虚拟机在本地的记录 :param ptype: 异构平台的类型 :param vm_info: 虚拟机的信息 """ db_util = NovaDatabaseUtils() plaform_db = "" del_sql = "" if ptype == "cserver": plaform_db = PlatformDatabase(CServerDBConfig) del_sql = db.common.DELETE_CSERVER_UUID_MAP_TABLE_SQL elif ptype == "vcenter": plaform_db = PlatformDatabase(VCenterDBConfig) del_sql = db.common.DELETE_VCENTER_UUID_MAP_TABLE_SQL if not plaform_db: log.logger.info("the platform type is error: %s" % ptype) return local_vm_list = db_util.get_vm_info_list(hostname) for vm in local_vm_list: log.logger.info("Delete local vm: %s, uuid: %s" % (vm["name"], vm["id"])) self._delete_local_instance(ptype, vm) os.system("/usr/local/bin/deletevm.sh %s" % vm["id"]) openstack_uuid = vm["id"] sql = del_sql % openstack_uuid plaform_db.delete(sql) plaform_db.close()
def _delete_instance_db(self, ptype, vm_id): """根据虚拟机的id从数据库中进行删除 :param ptype: 异构平台的类型 :param vm_id: 虚拟机的ID """ os.system("/usr/local/bin/deletevm.sh %s" % vm_id) openstack_uuid = vm_id if ptype == "cserver": cserver_db = PlatformDatabase(CServerDBConfig) sql = db.common.DELETE_CSERVER_UUID_MAP_TABLE_SQL % openstack_uuid cserver_db.delete(sql) cserver_db.close() elif ptype == "vcenter": vcenter_db = PlatformDatabase(VCenterDBConfig) sql = db.common.DELETE_VCENTER_UUID_MAP_TABLE_SQL % openstack_uuid vcenter_db.delete(sql) vcenter_db.close()