# Path: networking_vsphere/_i18n.py
# _LE = _translators.log_error
# 
# Path: networking_vsphere/utils/cache.py
# class VCCache(object):
#     def get_esx_hostname_for_vm(cls, vm_uuid):
#     def add_esx_hostname_for_vm(cls, vm_uuid, hostname):
#     def get_cluster_mor_for_vm(cls, vm_uuid):
#     def add_cluster_mor_for_vm(cls, vm_uuid, clus_mor):
#     def get_cluster_path_for_id(cls, cluster_id):
#     def add_path_for_cluster_id(cls, cluster_id, cluster_path):
#     def get_vm_mor_for_uuid(cls, uuid):
#     def add_vm_mor_for_uuid(cls, uuid, vm_mor):
#     def get_vm_model_for_uuid(cls, uuid):
#     def add_vm_model_for_uuid(cls, uuid, vm):
#     def get_switch_for_cluster_path(cls, cluster_path):
#     def add_switch_for_cluster_path(cls, cluster_path, switch_name):
#     def get_vmuuid_for_moid(cls, moid):
#     def remove_vm_for_uuid(cls, uuid):
#     def remove_cluster_path(cls, cluster_path):
#     def remove_cluster_id(cls, cluster_id):
#     def get_cluster_id_for_path(cls, cluster_path):
#     def get_cluster_switch_mapping(cls):
#     def reset(cls):


from oslo_log import log
from networking_vsphere._i18n import _LE
from networking_vsphere.utils import cache
from networking_vsphere.utils import common_util
from networking_vsphere.utils import vim_util
    vm_mors = session._call_method(
        vim_util, "get_objects", "VirtualMachine", ["name"])
    for vm_mor in vm_mors:
        propset_dict = common_util.convert_propset_to_dict(vm_mor.propSet)
        if propset_dict['name'] == vm_name:
            return vm_mor.obj
    return None


def set_vm_poweroff(session, vm_mor):
    """Power off the VM."""

    try:
        task_ref = session._call_method(
            session._get_vim(), "PowerOffVM_Task", vm_mor)
        session.wait_for_task(task_ref)
    except Exception as e:
        LOG.exception(_LE("%s"), e)
        raise Exception(e)


def set_host_into_maintenance_mode(session, host_mor):
    """Put ESX host into maintenance mode."""

    try:
        task_ref = session._call_method(
            session._get_vim(), "EnterMaintenanceMode_Task", host_mor,
            timeout=0, evacuatePoweredOffVms=False)
        session.wait_for_task(task_ref)
    except Exception as e:

# Path: networking_vsphere/_i18n.py
# _LE = _translators.log_error
# 
# Path: networking_vsphere/utils/cache.py
# class VCCache(object):
#     def get_esx_hostname_for_vm(cls, vm_uuid):
#     def add_esx_hostname_for_vm(cls, vm_uuid, hostname):
#     def get_cluster_mor_for_vm(cls, vm_uuid):
#     def add_cluster_mor_for_vm(cls, vm_uuid, clus_mor):
#     def get_cluster_path_for_id(cls, cluster_id):
#     def add_path_for_cluster_id(cls, cluster_id, cluster_path):
#     def get_vm_mor_for_uuid(cls, uuid):
#     def add_vm_mor_for_uuid(cls, uuid, vm_mor):
#     def get_vm_model_for_uuid(cls, uuid):
#     def add_vm_model_for_uuid(cls, uuid, vm):
#     def get_switch_for_cluster_path(cls, cluster_path):
#     def add_switch_for_cluster_path(cls, cluster_path, switch_name):
#     def get_vmuuid_for_moid(cls, moid):
#     def remove_vm_for_uuid(cls, uuid):
#     def remove_cluster_path(cls, cluster_path):
#     def remove_cluster_id(cls, cluster_id):
#     def get_cluster_id_for_path(cls, cluster_path):
#     def get_cluster_switch_mapping(cls):
#     def reset(cls):


# Path: networking_vsphere/utils/resource_util.py
from oslo_log import log
from networking_vsphere._i18n import _LE
from networking_vsphere.utils import cache
from networking_vsphere.utils import common_util
from networking_vsphere.utils import vim_util

    vm_mors = session._call_method(
        vim_util, "get_objects", "VirtualMachine", ["name"])
    for vm_mor in vm_mors:
        propset_dict = common_util.convert_propset_to_dict(vm_mor.propSet)
        if propset_dict['name'] == vm_name:
            return vm_mor.obj
    return None


def set_vm_poweroff(session, vm_mor):
    """Power off the VM."""

    try:
        task_ref = session._call_method(
            session._get_vim(), "PowerOffVM_Task", vm_mor)
        session.wait_for_task(task_ref)
    except Exception as e:
        LOG.exception(_LE("%s"), e)
        raise Exception(e)


def set_host_into_maintenance_mode(session, host_mor):
    """Put ESX host into maintenance mode."""

    try:
        task_ref = session._call_method(
            session._get_vim(), "EnterMaintenanceMode_Task", host_mor,
            timeout=0, evacuatePoweredOffVms=False)
        session.wait_for_task(task_ref)
    except Exception as e:

        LOG.exception(_LE("%s"), e)