Esempio n. 1
0
    def get_vm(self, vm_id):
        """Get the vm reference on a host.
        :param vm_id: The name of the vm.
        :rtype A vim vm reference.
        """
        vm = self._find_by_inventory_path(VM_FOLDER_NAME, vm_id)
        if not vm:
            raise VmNotFoundException("VM '%s' not found on host." % vm_id)

        return vm
Esempio n. 2
0
    def get_location_id(self, vm_id):
        """Get the locationId of the vm

        :param vm_id: VM ID as a string.
        :return: location id as a string.
        """
        vm = self.vim_client.get_vm_in_cache(vm_id)
        if not vm:
            raise VmNotFoundException("Vm %s not found in cache" % vm_id)
        if not vm.location_id:
            self._logger.debug("Vm %s does not have location_id" % vm_id)

        return vm.location_id
Esempio n. 3
0
    def get_used_memory_mb(self):
        vms = self.vim_client.get_vms_in_cache()
        if not vms:
            return 0

        memory = 0
        for vm in vms:
            # Vms in cache might include half updated record, e.g. with
            # None memory_mb, for a short time windows. Those Vms in cache
            # could be excluded from total used memory.
            if vm.memory_mb:
                memory += vm.memory_mb

        # This indicates that no values were retrieved from the cache.
        if memory == 0:
            raise VmNotFoundException("No valid VMs were found")

        return memory
Esempio n. 4
0
    def get_configured_cpu_count(self):
        """
        Returns the total number of vCPUs across all VMs
        :return: number of vCPUs - int
        """
        vms = self.vim_client.get_vms_in_cache()
        if not vms:
            return 0

        cpu_count = 0
        for vm in vms:
            if vm.num_cpu:
                cpu_count += vm.num_cpu

        # This indicates that no values were retrieved from the cache.
        if cpu_count == 0:
            raise VmNotFoundException("No valid VMs were found")

        return cpu_count