# 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_mor = get_vm_mor_for_uuid(session, vm_uuid)
    if vm_mor:
        host_mor = session._call_method(
            vim_util, "get_dynamic_property", vm_mor,
            "VirtualMachine", "runtime.host")
        cluster_mor = session._call_method(
            vim_util, "get_dynamic_property", host_mor,
            "HostSystem", "parent")
        cache.VCCache.add_cluster_mor_for_vm(vm_uuid, cluster_mor)
        return cluster_mor
    LOG.debug("Unable to retrieve VM information")
    return None


def get_vm_mor_for_uuid(session, vm_uuid):
    """Return VM mor from VM uuid."""

    vm_mor = cache.VCCache.get_vm_mor_for_uuid(vm_uuid)
    if vm_mor:
        return vm_mor
    # TODO(romilg) : use config.uuid instead of
    # config.extraConfig["nvp.vm-uuid"] once fixed in nova.
    vm_mors = session._call_method(vim_util, "get_objects",
                                   "VirtualMachine",
                                   ['config.extraConfig["nvp.vm-uuid"]'])
    for vm_mor in vm_mors:
        if hasattr(vm_mor, "propSet"):
            propset_dict = common_util.convert_propset_to_dict(vm_mor.propSet)
            if (vm_uuid ==
                    propset_dict['config.extraConfig["nvp.vm-uuid"]'].value):

# 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_mor = get_vm_mor_for_uuid(session, vm_uuid)
    if vm_mor:
        host_mor = session._call_method(
            vim_util, "get_dynamic_property", vm_mor,
            "VirtualMachine", "runtime.host")
        cluster_mor = session._call_method(
            vim_util, "get_dynamic_property", host_mor,
            "HostSystem", "parent")
        cache.VCCache.add_cluster_mor_for_vm(vm_uuid, cluster_mor)
        return cluster_mor
    LOG.debug("Unable to retrieve VM information")
    return None


def get_vm_mor_for_uuid(session, vm_uuid):
    """Return VM mor from VM uuid."""

    vm_mor = cache.VCCache.get_vm_mor_for_uuid(vm_uuid)
    if vm_mor:
        return vm_mor
    # TODO(romilg) : use config.uuid instead of
    # config.extraConfig["nvp.vm-uuid"] once fixed in nova.
    vm_mors = session._call_method(vim_util, "get_objects",
                                   "VirtualMachine",
                                   ['config.extraConfig["nvp.vm-uuid"]'])
    for vm_mor in vm_mors:
        if hasattr(vm_mor, "propSet"):
            propset_dict = common_util.convert_propset_to_dict(vm_mor.propSet)
            if (vm_uuid ==
                    propset_dict['config.extraConfig["nvp.vm-uuid"]'].value):

                cache.VCCache.add_vm_mor_for_uuid(vm_uuid, vm_mor.obj)