Пример #1
0
 def power_off(self, system_id, context):
     """Power off VMware node."""
     power_change = 'off'
     host, username, password, vm_name, uuid, port, protocol = (
         extract_vmware_parameters(context))
     power_control_vmware(host, username, password, vm_name, uuid,
                          power_change, port, protocol)
Пример #2
0
 def test_power_control_missing_server_raises_VMwareVMNotFound(self):
     self.configure_vmomi_api(servers=1,
                              has_instance_uuid=True,
                              has_uuid=True)
     host = factory.make_hostname()
     username = factory.make_username()
     password = factory.make_username()
     with ExpectedException(VMwareVMNotFound):
         vmware.power_control_vmware(host, username, password, None, None,
                                     "on")
Пример #3
0
    def test_power_control(self):
        mock_vmomi_api = self.configure_vmomi_api(servers=100)

        host = factory.make_hostname()
        username = factory.make_username()
        password = factory.make_username()

        servers = vmware.get_vmware_servers(host, username, password)

        # here we're grabbing indexes only available in the private mock object
        search_index = (
            mock_vmomi_api.SmartConnect.return_value.content.searchIndex
        )

        bios_uuids = list(search_index.vms_by_uuid)
        instance_uuids = list(search_index.vms_by_instance_uuid)

        # at least one should have a randomly-invalid state (just checking
        # for coverage, but since it's random, don't want to assert)
        vm_name = None

        for uuid in bios_uuids:
            vmware.power_query_vmware(host, username, password, vm_name, uuid)
        for uuid in instance_uuids:
            vmware.power_query_vmware(host, username, password, vm_name, uuid)
        for vm_name in servers:
            vmware.power_query_vmware(host, username, password, vm_name, None)

        # turn on a set of VMs, then verify they are on
        for uuid in bios_uuids:
            vmware.power_control_vmware(
                host, username, password, vm_name, uuid, "on"
            )

        for uuid in bios_uuids:
            state = vmware.power_query_vmware(
                host, username, password, vm_name, uuid
            )
            self.expectThat(state, Equals("on"))

        # turn off a set of VMs, then verify they are off
        for uuid in instance_uuids:
            vmware.power_control_vmware(
                host, username, password, vm_name, uuid, "off"
            )
        for uuid in instance_uuids:
            state = vmware.power_query_vmware(
                host, username, password, vm_name, uuid
            )
            self.expectThat(state, Equals("off"))

        self.expectThat(servers, Not(Equals({})))
Пример #4
0
 def power_on(self, system_id, context):
     """Power on VMware node."""
     power_change = "on"
     (
         host,
         username,
         password,
         vm_name,
         uuid,
         port,
         protocol,
     ) = extract_vmware_parameters(context)
     power_control_vmware(
         host,
         username,
         password,
         vm_name,
         uuid,
         power_change,
         port,
         protocol,
     )