def _get_notif_key_dw(self, notif_key):
     notif_key_dw = self._notif_keys.get(notif_key)
     if notif_key_dw is None:
         notif_key_dw = wintypes.DWORD(notif_key)
         # We have to make sure those addresses are preserved.
         self._notif_keys[notif_key] = notif_key_dw
     return notif_key_dw
Exemple #2
0
 def write_file(self, handle, buff, num_bytes, overlapped_structure=None):
     # Similar to IOUtils.write, but intended for synchronous operations.
     num_bytes_written = wintypes.DWORD(0)
     overlapped_structure_ref = (ctypes.byref(overlapped_structure)
                                 if overlapped_structure else None)
     self._run_and_check_output(kernel32.WriteFile, handle, buff, num_bytes,
                                ctypes.byref(num_bytes_written),
                                overlapped_structure_ref)
     return num_bytes_written.value
    def _migrate_vm(self, vm_name, new_host, migration_type,
                    exp_state_after_migr, timeout):
        syntax = w_const.CLUSPROP_SYNTAX_LIST_VALUE_DWORD
        migr_type = wintypes.DWORD(migration_type)

        prop_entries = [
            self._clusapi_utils.get_property_list_entry(
                w_const.CLUS_RESTYPE_NAME_VM, syntax, migr_type),
            self._clusapi_utils.get_property_list_entry(
                w_const.CLUS_RESTYPE_NAME_VM_CONFIG, syntax, migr_type)
        ]
        prop_list = self._clusapi_utils.get_property_list(prop_entries)

        flags = (w_const.CLUSAPI_GROUP_MOVE_RETURN_TO_SOURCE_NODE_ON_ERROR
                 | w_const.CLUSAPI_GROUP_MOVE_QUEUE_ENABLED
                 | w_const.CLUSAPI_GROUP_MOVE_HIGH_PRIORITY_START)

        with self._cmgr.open_cluster() as cluster_handle, \
                self._cmgr.open_cluster_group(
                    vm_name,
                    cluster_handle=cluster_handle) as group_handle, \
                self._cmgr.open_cluster_node(
                    new_host,
                    cluster_handle=cluster_handle) as dest_node_handle, \
                _ClusterGroupStateChangeListener(cluster_handle,
                                                 vm_name) as listener:
            self._clusapi_utils.move_cluster_group(group_handle,
                                                   dest_node_handle, flags,
                                                   prop_list)
            try:
                self._wait_for_cluster_group_migration(listener, vm_name,
                                                       group_handle,
                                                       exp_state_after_migr,
                                                       timeout)
            except exceptions.ClusterGroupMigrationTimeOut:
                with excutils.save_and_reraise_exception() as ctxt:
                    self._cancel_cluster_group_migration(
                        listener, vm_name, group_handle, exp_state_after_migr,
                        timeout)

                    # This is rather unlikely to happen but we're
                    # covering it out.
                    try:
                        self._validate_migration(group_handle, vm_name,
                                                 exp_state_after_migr,
                                                 new_host)
                        LOG.warning('Cluster group migration completed '
                                    'successfuly after cancel attempt. '
                                    'Suppressing timeout exception.')
                        ctxt.reraise = False
                    except exceptions.ClusterGroupMigrationFailed:
                        pass
            else:
                self._validate_migration(group_handle, vm_name,
                                         exp_state_after_migr, new_host)
Exemple #4
0
    def get_cluster_group_state(self, group_handle):
        node_name_len = wintypes.DWORD(w_const.MAX_PATH)
        node_name_buff = (ctypes.c_wchar * node_name_len.value)()

        group_state = self._run_and_check_output(
            clusapi.GetClusterGroupState,
            group_handle,
            node_name_buff,
            ctypes.byref(node_name_len),
            error_ret_vals=[constants.CLUSTER_GROUP_STATE_UNKNOWN],
            error_on_nonzero_ret_val=False,
            ret_val_is_err_code=False)

        return {'state': group_state, 'owner_node': node_name_buff.value}
    def _get_fake_prop_list(self):
        syntax = w_const.CLUSPROP_SYNTAX_LIST_VALUE_DWORD
        migr_type = wintypes.DWORD(self._LIVE_MIGRATION_TYPE)

        prop_entries = [
            self._clusapi_utils.get_property_list_entry(
                w_const.CLUS_RESTYPE_NAME_VM, syntax, migr_type),
            self._clusapi_utils.get_property_list_entry(
                w_const.CLUS_RESTYPE_NAME_VM_CONFIG, syntax, migr_type),
            self._clusapi_utils.get_property_list_entry(
                w_const.CLUSREG_NAME_GRP_STATUS_INFORMATION,
                w_const.CLUSPROP_SYNTAX_LIST_VALUE_ULARGE_INTEGER,
                ctypes.c_ulonglong(
                    w_const.CLUSGRP_STATUS_WAITING_IN_QUEUE_FOR_MOVE))  # noqa
        ]

        prop_list = self._clusapi_utils.get_property_list(prop_entries)
        return prop_list
    def cluster_enum(self, enum_handle, index):
        item_sz = wintypes.DWORD(0)

        self._run_and_check_output(
            clusapi.ClusterEnumEx,
            enum_handle,
            index,
            None,
            ctypes.byref(item_sz),
            ignored_error_codes=[w_const.ERROR_MORE_DATA])

        item_buff = (ctypes.c_ubyte * item_sz.value)()

        self._run_and_check_output(
            clusapi.ClusterEnumEx,
            enum_handle,
            index,
            ctypes.byref(item_buff),
            ctypes.byref(item_sz))

        return ctypes.cast(item_buff,
                           clusapi_def.PCLUSTER_ENUM_ITEM).contents