    class WindowsError(Exception):
    class x_wmi(Exception):
    class x_wmi_timed_out(x_wmi):
class OSWinException(Exception):
class NotFound(OSWinException):
class PciDeviceNotFound(NotFound):
class HyperVException(OSWinException):
class VHDResizeException(HyperVException):
class HyperVAuthorizationException(HyperVException):
class HyperVVMNotFoundException(NotFound, HyperVException):
class HyperVPortNotFoundException(NotFound, HyperVException):
class HyperVvNicNotFound(NotFound, HyperVException):
class HyperVvSwitchNotFound(NotFound, HyperVException):
class Invalid(OSWinException):
class UnsupportedOperation(Invalid):
class InvalidParameterValue(Invalid):
class InvalidVMVersion(Invalid):
class SMBException(OSWinException):
class Win32Exception(OSWinException):
class VHDException(OSWinException):
class VHDWin32APIException(VHDException, Win32Exception):
class FCException(OSWinException):
class FCWin32Exception(FCException, Win32Exception):
class WMIException(OSWinException):
class WqlException(OSWinException):
class ISCSITargetException(OSWinException):
class ISCSITargetWMIException(ISCSITargetException, WMIException):
class ISCSIInitiatorAPIException(Win32Exception):
class ISCSILunNotAvailable(ISCSITargetException):
class Win32IOException(Win32Exception):
class DiskNotFound(NotFound):
class HyperVRemoteFXException(HyperVException):
class HyperVClusterException(HyperVException):
class DNSException(OSWinException):
class Timeout(OSWinException):
class DNSZoneNotFound(NotFound, DNSException):
class DNSZoneAlreadyExists(DNSException):
class WMIJobFailed(HyperVException):
class JobTerminateFailed(HyperVException):
class ClusterException(OSWinException):
class ClusterObjectNotFound(NotFound, ClusterException):
class ClusterWin32Exception(ClusterException, Win32Exception):
class ClusterGroupMigrationFailed(ClusterException):
class ClusterGroupMigrationTimeOut(ClusterGroupMigrationFailed):
class ClusterPropertyRetrieveFailed(ClusterException):
class ClusterPropertyListEntryNotFound(ClusterPropertyRetrieveFailed):
class ClusterPropertyListParsingError(ClusterPropertyRetrieveFailed):
class SCSIPageParsingError(Invalid):
class SCSIIdDescriptorParsingError(Invalid):
class ResourceUpdateError(OSWinException):
class DiskUpdateError(OSWinException):
        def __init__(self, winerror=None):
        def __init__(self, info='', com_error=None):
    def __init__(self, message=None, **kwargs):
    def __init__(self, message=None, wmi_exc=None):
    def __init__(self, message=None, **kwargs): class TestingException(Exception):
class FakeWMIExc(exceptions.x_wmi):
class BaseTestCase(base.BaseTestCase):
class OsWinBaseTestCase(BaseTestCase):
    def __init__(self, hresult=None):
    def setUp(self):
    def _patch_autospec_classes(self):
    def setUp(self): CONF = os_win.conf.CONF
LOG = logging.getLogger(__name__)
    _MSCLUSTER_NODE = 'MSCluster_Node'
    _MSCLUSTER_RES = 'MSCluster_Resource'
    _VM_BASE_NAME = 'Virtual Machine %s'
    _VM_TYPE = 'Virtual Machine'
    _MS_CLUSTER_NAMESPACE = '//%s/root/MSCluster'
    _LIVE_MIGRATION_TYPE = 4
    _IGNORE_LOCKED = 1
    _DESTROY_GROUP = 1
    _FAILBACK_WINDOW_MIN = 0
    _FAILBACK_WINDOW_MAX = 23
    _WMI_EVENT_TIMEOUT_MS = 100
    _WMI_EVENT_CHECK_INTERVAL = 2
    _NOTIF_KEY_GROUP_STATE = 0
    _NOTIF_KEY_GROUP_COMMON_PROP = 1
class ClusterUtils(baseutils.BaseUtils):
class _ClusterEventListener(object):
class _ClusterGroupStateChangeListener(_ClusterEventListener):
class _ClusterGroupOwnerChangeListener(_ClusterEventListener):
    def __init__(self, host='.', timeout=CONF.os_win.connect_cluster_timeout):
    def _init_hyperv_conn(self, host, timeout):
        def init():
    def _get_failover_watcher(self):
    def check_cluster_state(self):
    def get_node_name(self):
    def _get_cluster_nodes(self):
    def _get_vm_groups(self):
    def _lookup_vm_group_check(self, vm_name):
    def _lookup_vm_group(self, vm_name):
    def _lookup_res(self, resource_source, res_name):
    def get_cluster_node_names(self):
    def get_vm_host(self, vm_name):
    def list_instances(self):
    def list_instance_uuids(self):
    def add_vm_to_cluster(self, vm_name, max_failover_count=1,
                          failover_period=6, auto_failback=True):
    def bring_online(self, vm_name):
    def take_offline(self, vm_name):
    def delete(self, vm_name):
    def cluster_enum(self, object_type):
    def vm_exists(self, vm_name):
    def live_migrate_vm(self, vm_name, new_host, timeout=None):
    def _migrate_vm(self, vm_name, new_host, migration_type,
                    exp_state_after_migr, timeout):
    def _validate_migration(self, group_handle, group_name,
                            expected_state, expected_node):
    def cancel_cluster_group_migration(self, group_name, expected_state,
                                       timeout=None):
    def _cancel_cluster_group_migration(self, event_listener,
                                        group_name, group_handle,
                                        expected_state,
                                        timeout=None):
    def _is_migration_queued(self, group_status_info):
    def _is_migration_pending(self, group_state, group_status_info,
                              expected_state):
    def _wait_for_cluster_group_migration(self, event_listener,
                                          group_name, group_handle,
                                          expected_state,
                                          timeout=None):
    def get_cluster_node_name(self, node_id):
    def get_cluster_group_type(self, group_name):
    def get_cluster_group_state_info(self, group_name):
    def _get_cluster_group_state(self, group_handle):
    def _monitor_vm_failover(self, watcher, callback,
                             event_timeout_ms=_WMI_EVENT_TIMEOUT_MS):
    def get_vm_owner_change_listener(self):
        def listener(callback):
    def get_vm_owner_change_listener_v2(self):
        def listener(callback):
    def __init__(self, cluster_handle, stop_on_error=True):
    def __enter__(self):
    def _get_notif_key_dw(self, notif_key):
    def _add_filter(self, notif_filter, notif_key=0):
    def _setup_notif_port(self):
    def _setup(self):
    def __exit__(self, exc_type, exc_value, traceback):
    def _signal_stopped(self):
    def stop(self):
    def _listen(self):
    def _process_event(self, event):
    def get(self, timeout=None):
    def _ensure_listener_running(self):
    def __init__(self, cluster_handle, group_name=None, **kwargs):
    def _process_event(self, event): LOG = logging.getLogger(__name__)
    _STORAGE_ALLOC_SETTING_DATA_CLASS = 'Msvm_StorageAllocationSettingData'
    _CIM_RES_ALLOC_SETTING_DATA_CLASS = 'CIM_ResourceAllocationSettingData'
    _MIGRATION_TYPE_VIRTUAL_SYSTEM = 32768
    _MIGRATION_TYPE_VIRTUAL_SYSTEM_AND_STORAGE = 32771
    _MIGRATION_TYPE_STAGED = 32770
class LiveMigrationUtils(migrationutils.MigrationUtils):
    def __init__(self):
    def _get_conn_v2(self, host='localhost'):
    def check_live_migration_config(self):
    def _get_vm(self, conn_v2, vm_name):
    def _create_planned_vm(self, conn_v2_local, conn_v2_remote,
                           vm, ip_addr_list, dest_host):
    def _get_disk_data(self, vm_name, vmutils_remote, disk_path_mapping):
    def _update_planned_vm_disk_resources(self, conn_v2_local,
                                          planned_vm, vm_name,
                                          disk_paths_remote):
    def _get_vhd_setting_data(self, vm):
    def _live_migrate_vm(self, conn_v2_local, vm, planned_vm, rmt_ip_addr_list,
                         new_resource_setting_data, dest_host, migration_type):
    def _get_ip_address_list(self, conn_v2, hostname):
    def live_migrate_vm(self, vm_name, dest_host, migrate_disks=True):
    def create_planned_vm(self, vm_name, src_host, disk_path_mapping): LOG = logging.getLogger(__name__)
class MigrationUtils(baseutils.BaseUtilsVirt):
    def __init__(self):
    def _get_export_setting_data(self, vm_name):
    def export_vm(self, vm_name, export_path,
                  copy_snapshots_config=constants.EXPORT_CONFIG_SNAPSHOTS_ALL,
                  copy_vm_storage=False, create_export_subdir=False):
    def import_vm_definition(self, export_config_file_path,
                             snapshot_folder_path,
                             new_uuid=False):
    def realize_vm(self, vm_name):
    def _get_planned_vm(self, vm_name, conn_v2=None, fail_if_not_found=False):
    def planned_vm_exists(self, vm_name):
    def _destroy_planned_vm(self, planned_vm):
    def destroy_existing_planned_vm(self, vm_name): class RDPConsoleUtils(baseutils.BaseUtilsVirt):
    def get_rdp_console_port(self): LOG = logging.getLogger(__name__)
    _PHYS_DISK_RES_SUB_TYPE = 'Microsoft:Hyper-V:Physical Disk Drive'
    _DISK_DRIVE_RES_SUB_TYPE = 'Microsoft:Hyper-V:Synthetic Disk Drive'
    _DVD_DRIVE_RES_SUB_TYPE = 'Microsoft:Hyper-V:Synthetic DVD Drive'
    _HARD_DISK_RES_SUB_TYPE = 'Microsoft:Hyper-V:Virtual Hard Disk'
    _DVD_DISK_RES_SUB_TYPE = 'Microsoft:Hyper-V:Virtual CD/DVD Disk'
    _IDE_CTRL_RES_SUB_TYPE = 'Microsoft:Hyper-V:Emulated IDE Controller'
    _SCSI_CTRL_RES_SUB_TYPE = 'Microsoft:Hyper-V:Synthetic SCSI Controller'
    _SERIAL_PORT_RES_SUB_TYPE = 'Microsoft:Hyper-V:Serial Port'
    _SETTINGS_DEFINE_STATE_CLASS = 'Msvm_SettingsDefineState'
    _VIRTUAL_SYSTEM_SETTING_DATA_CLASS = 'Msvm_VirtualSystemSettingData'
    _RESOURCE_ALLOC_SETTING_DATA_CLASS = 'Msvm_ResourceAllocationSettingData'
    _PROCESSOR_SETTING_DATA_CLASS = 'Msvm_ProcessorSettingData'
    _MEMORY_SETTING_DATA_CLASS = 'Msvm_MemorySettingData'
    _SERIAL_PORT_SETTING_DATA_CLASS = _RESOURCE_ALLOC_SETTING_DATA_CLASS
    _STORAGE_ALLOC_SETTING_DATA_CLASS = 'Msvm_StorageAllocationSettingData'
    _SYNTHETIC_ETHERNET_PORT_SETTING_DATA_CLASS = (
        'Msvm_SyntheticEthernetPortSettingData')
    _AFFECTED_JOB_ELEMENT_CLASS = "Msvm_AffectedJobElement"
    _CIM_RES_ALLOC_SETTING_DATA_CLASS = 'Cim_ResourceAllocationSettingData'
    _COMPUTER_SYSTEM_CLASS = "Msvm_ComputerSystem"
    _LOGICAL_IDENTITY_CLASS = 'Msvm_LogicalIdentity'
    _VIRTUAL_SYSTEM_SNAP_ASSOC_CLASS = 'Msvm_SnapshotOfVirtualSystem'
    _S3_DISP_CTRL_RES_SUB_TYPE = 'Microsoft:Hyper-V:S3 Display Controller'
    _SYNTH_DISP_CTRL_RES_SUB_TYPE = ('Microsoft:Hyper-V:Synthetic Display '
                                     'Controller')
    _REMOTEFX_DISP_CTRL_RES_SUB_TYPE = ('Microsoft:Hyper-V:Synthetic 3D '
                                        'Display Controller')
    _SYNTH_DISP_ALLOCATION_SETTING_DATA_CLASS = (
        'Msvm_SyntheticDisplayControllerSettingData')
    _REMOTEFX_DISP_ALLOCATION_SETTING_DATA_CLASS = (
        'Msvm_Synthetic3DDisplayControllerSettingData')
    _VIRTUAL_SYSTEM_SUBTYPE = 'VirtualSystemSubType'
    _VIRTUAL_SYSTEM_TYPE_REALIZED = 'Microsoft:Hyper-V:System:Realized'
    _VIRTUAL_SYSTEM_TYPE_PLANNED = 'Microsoft:Hyper-V:System:Planned'
    _VIRTUAL_SYSTEM_SUBTYPE_GEN2 = 'Microsoft:Hyper-V:SubType:2'
    _SNAPSHOT_FULL = 2
    _VM_ENABLED_STATE_PROP = "EnabledState"
    _SHUTDOWN_COMPONENT = "Msvm_ShutdownComponent"
    _VIRTUAL_SYSTEM_CURRENT_SETTINGS = 3
    _AUTOMATIC_STARTUP_ACTION_NONE = 2
    _DISP_CTRL_ADDRESS_DX_11 = "02C1,00000000,01"
    _DISP_CTRL_ADDRESS = "5353,00000000,00"
    _DEFAULT_EVENT_CHECK_TIMEFRAME = 60  # seconds
class VMUtils(baseutils.BaseUtilsVirt):
class VMUtils6_3(VMUtils):
    def __init__(self, host='.'):
    def list_instance_notes(self):
    def list_instances(self):
    def get_vm_summary_info(self, vm_name):
    def get_vm_state(self, vm_name):
    def _lookup_vm_check(self, vm_name, as_vssd=True, for_update=False):
    def _lookup_vm(self, vm_name, as_vssd=True, for_update=False):
    def vm_exists(self, vm_name):
    def get_vm_id(self, vm_name):
    def get_vm_memory_info(self, vm_name):
    def _get_vm_memory(self, vmsetting):
    def _set_vm_memory(self, vmsetting, memory_mb, memory_per_numa_node,
                       dynamic_memory_ratio):
    def _set_vm_vcpus(self, vmsetting, vcpus_num, vcpus_per_numa_node,
                      limit_cpu_features):
    def set_nested_virtualization(self, vm_name, state):
    def update_vm(self, vm_name, memory_mb, memory_per_numa_node, vcpus_num,
                  vcpus_per_numa_node, limit_cpu_features, dynamic_mem_ratio,
                  configuration_root_dir=None, snapshot_dir=None,
                  host_shutdown_action=None, vnuma_enabled=None,
                  snapshot_type=None,
                  is_planned_vm=False,
                  chassis_asset_tag=None):
    def check_admin_permissions(self):
    def create_vm(self, vm_name, vnuma_enabled, vm_gen, instance_path,
                  notes=None):
    def _modify_virtual_system(self, vmsetting):
    def get_vm_scsi_controller(self, vm_name):
    def _get_vm_scsi_controller(self, vmsettings):
    def _get_vm_disk_controllers(self, vmsettings, ctrl_res_sub_type):
    def _get_vm_ide_controller(self, vmsettings, ctrller_addr):
    def get_vm_ide_controller(self, vm_name, ctrller_addr):
    def _get_disk_ctrl_addr(self, controller_path):
    def get_attached_disks(self, scsi_controller_path):
    def _get_attached_disks_query_string(self, scsi_controller_path):
    def _get_new_setting_data(self, class_name):
    def _get_new_resource_setting_data(self, resource_sub_type,
                                       class_name=None):
    def attach_scsi_drive(self, vm_name, path, drive_type=constants.DISK):
    def attach_ide_drive(self, vm_name, path, ctrller_addr, drive_addr,
                         drive_type=constants.DISK):
    def attach_drive(self, vm_name, path, ctrller_path, drive_addr,
                     drive_type=constants.DISK):
    def get_disk_attachment_info(self, attached_disk_path=None,
                                 is_physical=True, serial=None):
    def _get_disk_controller_type(self, controller_path):
    def create_scsi_controller(self, vm_name):
    def attach_volume_to_controller(self, vm_name, controller_path, address,
                                    mounted_disk_path, serial=None):
    def get_vm_physical_disk_mapping(self, vm_name, is_planned_vm=False):
    def _get_disk_resource_address(self, disk_resource):
    def set_disk_host_res(self, disk_res_path, mounted_disk_path):
    def _get_nic_data_by_name(self, name):
    def create_nic(self, vm_name, nic_name, mac_address=None):
    def destroy_nic(self, vm_name, nic_name):
    def _get_vm_nics(self, vm_name):
    def get_vm_nic_names(self, vm_name):
    def soft_shutdown_vm(self, vm_name):
    def set_vm_state(self, vm_name, req_state):
    def _get_disk_resource_disk_path(self, disk_resource):
    def get_vm_config_root_dir(self, vm_name):
    def get_vm_storage_paths(self, vm_name, is_planned_vm=False):
    def get_vm_disks(self, vm_name, is_planned_vm=False):
    def _get_vm_disks(self, vmsettings):
    def destroy_vm(self, vm_name):
    def take_vm_snapshot(self, vm_name, snapshot_name=None):
    def get_vm_snapshots(self, vm_name, snapshot_name=None):
    def remove_vm_snapshot(self, snapshot_path):
    def get_vm_dvd_disk_paths(self, vm_name):
    def is_disk_attached(self, disk_path, is_physical=True):
    def detach_vm_disk(self, vm_name, disk_path=None, is_physical=True,
                       serial=None):
    def _get_mounted_disk_resource_from_path(self, disk_path, is_physical,
                                             serial=None):
    def get_mounted_disk_by_drive_number(self, device_number):
    def get_controller_volume_paths(self, controller_path):
    def get_free_controller_slot(self, scsi_controller_path):
    def _get_vm_serial_ports(self, vmsettings):
    def set_vm_serial_port_connection(self, vm_name, port_number, pipe_path):
    def get_vm_serial_port_connections(self, vm_name):
    def get_active_instances(self):
    def get_vm_power_state_change_listener(
            self, timeframe=_DEFAULT_EVENT_CHECK_TIMEFRAME,
            event_timeout=constants.DEFAULT_WMI_EVENT_TIMEOUT_MS,
            filtered_states=None, get_handler=False):
        def _handle_events(callback):
    def _get_event_wql_query(self, cls, field,
                             timeframe, filtered_states=None):
    def _get_instance_notes(self, vm_name):
    def get_instance_uuid(self, vm_name):
    def get_vm_power_state(self, vm_enabled_state):
    def get_vm_generation(self, vm_name):
    def stop_vm_jobs(self, vm_name, timeout=None):
    def enable_secure_boot(self, vm_name, msft_ca_required):
    def _set_secure_boot(self, vs_data, msft_ca_required):
    def set_disk_qos_specs(self, disk_path, max_iops=None, min_iops=None):
    def _drive_to_boot_source(self, drive_path):
    def set_boot_order(self, vm_name, device_boot_order):
    def _set_boot_order_gen1(self, vm_name, device_boot_order):
    def _set_boot_order_gen2(self, vm_name, device_boot_order):
    def vm_gen_supports_remotefx(self, vm_gen):
    def _validate_remotefx_params(self, monitor_count, max_resolution,
                                  vram_bytes=None):
    def _set_remotefx_display_controller(self, vm, remotefx_disp_ctrl_res,
                                         monitor_count, max_resolution,
                                         vram_bytes=None):
    def _set_remotefx_vram(self, remotefx_disp_ctrl_res, vram_bytes):
    def enable_remotefx_video_adapter(self, vm_name, monitor_count,
                                      max_resolution, vram_bytes=None):
    def disable_remotefx_video_adapter(self, vm_name):
    def _vm_has_s3_controller(self, vm_name):
    def is_secure_vm(self, instance_name):
    def update_vm_disk_path(self, disk_path, new_disk_path, is_physical=True):
    def add_pci_device(self, vm_name, vendor_id, product_id):
    def remove_pci_device(self, vm_name, vendor_id, product_id):
    def remove_all_pci_devices(self, vm_name):
    def _set_vm_snapshot_type(self, vmsettings, snapshot_type):
    def populate_fsk(self, fsk_filepath, fsk_pairs):
    def add_vtpm(self, vm_name, pdk_filepath, shielded):
    def provision_vm(self, vm_name, fsk_filepath, pdk_filepath):
    def set_disk_qos_specs(self, disk_path, max_iops=None, min_iops=None): LOG = logging.getLogger(__name__)
    _DNS_NAMESPACE = '//%s/root/MicrosoftDNS'
        SOA = zone_soatype[0].SerialNumber
class DNSUtils(baseutils.BaseUtils):
    def __init__(self, host='.'):
    def _dns_manager(self):
    def _get_zone(self, zone_name, ignore_missing=True):
    def zone_list(self):
    def zone_exists(self, zone_name):
    def get_zone_properties(self, zone_name):
    def zone_create(self, zone_name, zone_type, ds_integrated,
                    data_file_name=None, ip_addrs=None,
                    admin_email_name=None):
    def zone_delete(self, zone_name):
    def zone_modify(self, zone_name, allow_update=None, disable_wins=None,
                    notify=None, reverse=None, secure_secondaries=None):
    def zone_update(self, zone_name):
    def get_zone_serial(self, zone_name): LOG = logging.getLogger(__name__)
    _MSVM_PROCESSOR = 'Msvm_Processor'
    _MSVM_MEMORY = 'Msvm_Memory'
    _MSVM_NUMA_NODE = 'Msvm_NumaNode'
    _CENTRAL_PROCESSOR = 'Central Processor'
    _HOST_FORCED_REBOOT = 6
    _HOST_FORCED_SHUTDOWN = 12
    _DEFAULT_VM_GENERATION = constants.IMAGE_PROP_VM_GEN_1
    FEATURE_RDS_VIRTUALIZATION = 322
    FEATURE_MPIO = 57
class HostUtils(baseutils.BaseUtilsVirt):
    def __init__(self, host='.'):
    def _netutils(self):
    def get_cpus_info(self):
    def is_cpu_feature_present(self, feature_key):
    def get_memory_info(self):
    def get_volume_info(self, drive):
    def check_min_windows_version(self, major, minor, build=0):
    def get_windows_version(self):
    def get_local_ips(self):
    def get_host_tick_count64(self):
    def host_power_action(self, action):
    def get_supported_vm_types(self):
    def get_default_vm_generation(self):
    def check_server_feature(self, feature_id):
    def get_nic_sriov_vfs(self):
    def get_nic_hardware_offload_info(self):
    def _get_nic_hw_offload_info(self, vswitch_sd, hw_offload_sd):
    def get_numa_nodes(self):
    def _get_numa_memory_info(self, numa_node_assoc, system_memory):
    def _get_numa_cpu_info(self, numa_node_assoc, processors):
    def get_remotefx_gpu_info(self):
    def verify_host_remotefx_capability(self):
    def is_host_guarded(self):
    def supports_nested_virtualization(self):
    def get_pci_passthrough_devices(self): LOG = logging.getLogger(__name__)
WAIT_PIPE_DEFAULT_TIMEOUT = 5  # seconds
WAIT_IO_COMPLETION_TIMEOUT = 2 * units.k
WAIT_INFINITE_TIMEOUT = 0xFFFFFFFF
IO_QUEUE_TIMEOUT = 2
IO_QUEUE_BURST_TIMEOUT = 0.05
class IOUtils(object):
class IOQueue(Queue.Queue, object):
    def __init__(self):
    def _run_and_check_output(self, *args, **kwargs):
    def create_pipe(self, security_attributes=None, size=0,
                    inherit_handle=False):
    def wait_named_pipe(self, pipe_name, timeout=WAIT_PIPE_DEFAULT_TIMEOUT):
    def open(self, path, desired_access=0, share_mode=0,
             creation_disposition=0, flags_and_attributes=0):
    def close_handle(self, handle):
    def cancel_io(self, handle, overlapped_structure=None,
                  ignore_invalid_handle=False):
    def _wait_io_completion(self, event):
    def set_event(self, event):
    def _reset_event(self, event):
    def _create_event(self, event_attributes=None, manual_reset=True,
                      initial_state=False, name=None):
    def get_completion_routine(self, callback=None):
        def _completion_routine(error_code, num_bytes, lpOverLapped):
    def get_new_overlapped_structure(self):
    def read(self, handle, buff, num_bytes,
             overlapped_structure, completion_routine):
    def read_file(self, handle, buff, num_bytes, overlapped_structure=None):
    def write(self, handle, buff, num_bytes,
              overlapped_structure, completion_routine):
    def write_file(self, handle, buff, num_bytes, overlapped_structure=None):
    def get_buffer(cls, buff_size, data=None):
    def get_buffer_data(buff, num_bytes):
    def write_buffer_data(buff, data):
    def __init__(self, client_connected):
    def get(self, timeout=IO_QUEUE_TIMEOUT, continue_on_timeout=True):
    def put(self, item, timeout=IO_QUEUE_TIMEOUT):
    def get_burst(self, timeout=IO_QUEUE_TIMEOUT,
                  burst_timeout=IO_QUEUE_BURST_TIMEOUT,
                  max_size=constants.SERIAL_CONSOLE_BUFFER_SIZE): CONF = conf.CONF
LOG = logging.getLogger(__name__)
_PORT_PROFILE_ATTR_MAP = {
    "profile_id": "ProfileId",
    "profile_data": "ProfileData",
    "profile_name": "ProfileName",
    "net_cfg_instance_id": "NetCfgInstanceId",
    "cdn_label_id": "CdnLabelId",
    "cdn_label_string": "CdnLabelString",
    "vendor_id": "VendorId",
    "vendor_name": "VendorName",
}
    EVENT_TYPE_CREATE = "__InstanceCreationEvent"
    EVENT_TYPE_DELETE = "__InstanceDeletionEvent"
    _VNIC_SET_DATA = 'Msvm_SyntheticEthernetPortSettingData'
    _EXTERNAL_PORT = 'Msvm_ExternalEthernetPort'
    _ETHERNET_SWITCH_PORT = 'Msvm_EthernetSwitchPort'
    _PORT_ALLOC_SET_DATA = 'Msvm_EthernetPortAllocationSettingData'
    _PORT_VLAN_SET_DATA = 'Msvm_EthernetSwitchPortVlanSettingData'
    _PORT_PROFILE_SET_DATA = 'Msvm_EthernetSwitchPortProfileSettingData'
    _PORT_SECURITY_SET_DATA = 'Msvm_EthernetSwitchPortSecuritySettingData'
    _PORT_HW_OFFLOAD_SET_DATA = 'Msvm_EthernetSwitchPortOffloadSettingData'
    _PORT_ALLOC_ACL_SET_DATA = 'Msvm_EthernetSwitchPortAclSettingData'
    _PORT_BANDWIDTH_SET_DATA = 'Msvm_EthernetSwitchPortBandwidthSettingData'
    _PORT_EXT_ACL_SET_DATA = _PORT_ALLOC_ACL_SET_DATA
    _LAN_ENDPOINT = 'Msvm_LANEndpoint'
    _STATE_DISABLED = 3
    _VIRTUAL_SYSTEM_SETTING_DATA = 'Msvm_VirtualSystemSettingData'
    _VM_SUMMARY_ENABLED_STATE = 100
    _HYPERV_VM_STATE_ENABLED = 2
    _OFFLOAD_ENABLED = 100
    _OFFLOAD_DISABLED = 0
    _ACL_DIR_IN = 1
    _ACL_DIR_OUT = 2
    _ACL_TYPE_IPV4 = 2
    _ACL_TYPE_IPV6 = 3
    _ACL_ACTION_ALLOW = 1
    _ACL_ACTION_DENY = 2
    _ACL_ACTION_METER = 3
    _ACL_APPLICABILITY_LOCAL = 1
    _ACL_APPLICABILITY_REMOTE = 2
    _ACL_DEFAULT = 'ANY'
    _IPV4_ANY = '0.0.0.0/0'
    _IPV6_ANY = '::/0'
    _TCP_PROTOCOL = 'tcp'
    _UDP_PROTOCOL = 'udp'
    _ICMP_PROTOCOL = '1'
    _ICMPV6_PROTOCOL = '58'
    _MAX_WEIGHT = 65500
    _REJECT_ACLS_COUNT = 4
    _VNIC_LISTENER_TIMEOUT_MS = 2000
    _PORT_EXT_ACL_SET_DATA = 'Msvm_EthernetSwitchPortExtendedAclSettingData'
    _MAX_WEIGHT = 65500
    _REJECT_ACLS_COUNT = 16
class NetworkUtils(baseutils.BaseUtilsVirt):
class NetworkUtilsR2(NetworkUtils):
    def __init__(self):
    def init_caches(self):
    def update_cache(self):
    def clear_port_sg_acls_cache(self, switch_port_name):
    def get_vswitch_id(self, vswitch_name):
    def get_vswitch_extensions(self, vswitch_name):
    def get_vswitch_external_network_name(self, vswitch_name):
    def _get_vswitch(self, vswitch_name):
    def _get_vswitch_external_port(self, vswitch_name):
    def vswitch_port_needed(self):
    def get_switch_ports(self, vswitch_name):
    def get_port_by_id(self, port_id, vswitch_name):
    def vnic_port_exists(self, port_id):
    def get_vnic_ids(self):
    def get_vnic_mac_address(self, switch_port_name):
    def _get_vnic_settings(self, vnic_name):
    def get_vnic_event_listener(self, event_type):
        def _poll_events(callback):
    def _get_event_wql_query(self, cls, event_type, timeframe=2, **where):
    def connect_vnic_to_vswitch(self, vswitch_name, switch_port_name):
    def _get_vm_from_res_setting_data(self, res_setting_data):
    def remove_switch_port(self, switch_port_name, vnic_deleted=False):
    def set_vswitch_port_profile_id(self, switch_port_name, profile_id,
                                    profile_data, profile_name, vendor_name,
                                    **kwargs):
    def set_vswitch_port_vlan_id(self, vlan_id=None, switch_port_name=None,
                                 **kwargs):
    def _prepare_profile_sd(self, **kwargs):
    def _prepare_vlan_sd_access_mode(self, vlan_settings, vlan_id):
    def _prepare_vlan_sd_trunk_mode(self, vlan_settings, vlan_id, trunk_vlans):
    def set_vswitch_port_vsid(self, vsid, switch_port_name):
    def set_vswitch_port_mac_spoofing(self, switch_port_name, state):
    def _set_switch_port_security_settings(self, switch_port_name, **kwargs):
    def set_vswitch_port_sriov(self, switch_port_name, enabled):
    def set_vswitch_port_offload(self, switch_port_name, sriov_enabled=None,
                                 iov_queues_requested=None, vmq_enabled=None,
                                 offloaded_sa=None):
    def _get_profile_setting_data_from_port_alloc(self, port_alloc):
    def _get_vlan_setting_data_from_port_alloc(self, port_alloc):
    def _get_security_setting_data_from_port_alloc(self, port_alloc):
    def _get_hw_offload_sd_from_port_alloc(self, port_alloc):
    def _get_bandwidth_setting_data_from_port_alloc(self, port_alloc):
    def _get_setting_data_from_port_alloc(self, port_alloc, cache, data_class):
    def _get_switch_port_allocation(self, switch_port_name, create=False,
                                    expected=True):
    def _get_setting_data(self, class_name, element_name, create=True):
    def _get_default_setting_data(self, class_name):
    def _create_default_setting_data(self, class_name):
    def _get_first_item(self, obj):
    def add_metrics_collection_acls(self, switch_port_name):
    def is_metrics_collection_allowed(self, switch_port_name):
    def _is_port_vm_started(self, port):
    def create_security_rules(self, switch_port_name, sg_rules):
    def remove_security_rules(self, switch_port_name, sg_rules):
    def remove_all_security_rules(self, switch_port_name):
    def _bind_security_rules(self, port, sg_rules):
    def _get_port_security_acls(self, port):
    def _create_acl(self, direction, acl_type, action):
    def _create_security_acl(self, sg_rule, weight):
    def _filter_acls(self, acls, action, direction, acl_type, remote_addr=""):
    def _filter_security_acls(self, sg_rule, acls):
    def _get_new_weights(self, sg_rules, existent_acls):
    def set_port_qos_rule(self, port_id, qos_rule):
    def remove_port_qos_rule(self, port_id):
    def _create_security_acl(self, sg_rule, weight):
    def _get_new_weights(self, sg_rules, existent_acls): CONF = os_win.conf.CONF
LOG = logging.getLogger(__name__)
class PathUtils(object):
    def __init__(self):
    def open(self, path, mode):
    def exists(self, path):
    def makedirs(self, path):
    def remove(self, path):
    def rename(self, src, dest):
    def copy_dir(self, src, dest):
    def copyfile(self, src, dest):
    def copy(self, src, dest, fail_if_exists=True):
    def copy_folder_files(self, src_dir, dest_dir):
    def move_folder_files(self, src_dir, dest_dir):
    def rmtree(self, path):
    def check_create_dir(self, path):
    def check_remove_dir(self, path):
    def is_symlink(self, path):
    def create_sym_link(self, link, target, target_is_dir=True):
    def create_temporary_file(self, suffix=None, *args, **kwargs):
    def temporary_file(self, suffix=None, *args, **kwargs):
    def add_acl_rule(self, path, trustee_name,
                     access_rights, access_mode,
                     inheritance_flags=0):
    def copy_acls(self, source_path, dest_path):
    def is_same_file(self, path_a, path_b):
    def get_file_id(self, path): LOG = logging.getLogger(__name__)
class ProcessUtils(object):
class Mutex(object):
    def __init__(self):
    def _run_and_check_output(self, *args, **kwargs):
    def create_job_object(self, name=None):
    def set_information_job_object(self, job_handle, job_object_info_class,
                                   job_object_info):
    def assign_process_to_job_object(self, job_handle, process_handle):
    def open_process(self, pid, desired_access, inherit_handle=False):
    def kill_process_on_job_close(self, pid):
    def wait_for_multiple_processes(self, pids, wait_all=True,
                                    milliseconds=w_const.INFINITE):
    def create_mutex(self, name=None, initial_owner=False,
                     security_attributes=None):
    def release_mutex(self, handle):
    def __init__(self, name=None):
    def acquire(self, timeout_ms=w_const.INFINITE):
    def release(self):
    def close(self):
    def __enter__(self):
    def __exit__(self, exc_type, exc_val, exc_tb): LOG = logging.getLogger(__name__)
PDEVICE_ID_VPD_PAGE = ctypes.POINTER(DEVICE_ID_VPD_PAGE)
PIDENTIFICATION_DESCRIPTOR = ctypes.POINTER(IDENTIFICATION_DESCRIPTOR)
SCSI_ID_ASSOC_TYPE_DEVICE = 0
SCSI_ID_CODE_SET_BINARY = 1
SCSI_ID_CODE_SET_ASCII = 2
BUS_FILE_BACKED_VIRTUAL = 15
_RESCAN_LOCK = threading.Lock()
class DEVICE_ID_VPD_PAGE(ctypes.BigEndianStructure):
class IDENTIFICATION_DESCRIPTOR(ctypes.Structure):
class DiskUtils(baseutils.BaseUtils):
    def __init__(self):
    def _get_disk_by_number(self, disk_number, msft_disk_cls=True):
    def _get_disks_by_unique_id(self, unique_id, unique_id_format):
    def get_attached_virtual_disk_files(self):
    def is_virtual_disk_file_attached(self, path):
    def get_disk_numbers_by_unique_id(self, unique_id, unique_id_format):
    def get_disk_uid_and_uid_type(self, disk_number):
    def is_mpio_disk(self, disk_number):
    def refresh_disk(self, disk_number):
    def get_device_name_by_device_number(self, device_number):
    def get_device_number_from_device_name(self, device_name):
    def rescan_disks(self, merge_requests=False):
    def _rescan_disks(self):
    def get_disk_capacity(self, path, ignore_errors=False):
    def get_disk_size(self, disk_number):
    def _parse_scsi_page_83(self, buff,
                            select_supported_identifiers=False):
    def _parse_scsi_id_desc(self, id_desc_addr, buff_sz):
    def _select_supported_scsi_identifiers(self, identifiers):
    def get_new_disk_policy(self):
    def set_new_disk_policy(self, policy):
    def set_disk_online(self, disk_number):
    def set_disk_offline(self, disk_number):
    def set_disk_readonly_status(self, disk_number, read_only): LOG = logging.getLogger(__name__)
    _DEFAULT_RESCAN_ATTEMPTS = 3
    _MS_IQN_PREFIX = "iqn.1991-05.com.microsoft"
    _DEFAULT_ISCSI_PORT = 3260
def _get_buff(size, item_type):
def ensure_buff_and_retrieve_items(struct_type,
                                   func_requests_buff_sz=True,
                                   parse_output=True):
    def wrapper(f):
        def inner(*args, **kwargs):
def _get_items_from_buff(buff, item_type, element_count):
    def __init__(self):
    def _run_and_check_output(self, *args, **kwargs):
    def _get_iscsi_persistent_logins(self, buff=None, buff_size=None,
                                     element_count=None):
    def get_targets(self, forced_update=False, buff=None,
                    buff_size=None, element_count=None):
    def get_iscsi_initiator(self):
    def get_iscsi_initiators(self, buff=None, buff_size=None,
                             element_count=None):
    def _parse_string_list(buff, element_count):
    def _login_iscsi_target(self, target_name, portal=None, login_opts=None,
                            is_persistent=True, initiator_name=None):
    def _get_iscsi_sessions(self, buff=None, buff_size=None,
                            element_count=None):
    def _get_iscsi_target_sessions(self, target_name, connected_only=True):
    def _get_iscsi_session_devices(self, session_id,
                                   buff=None, buff_size=None,
                                   element_count=None):
    def _get_iscsi_session_disk_luns(self, session_id):
    def _get_iscsi_device_from_session(self, session_id, target_lun):
    def get_device_number_for_target(self, target_name, target_lun,
                                     fail_if_not_found=False):
    def get_device_number_and_path(self, target_name, target_lun,
                                   fail_if_not_found=False,
                                   retry_attempts=10,
                                   retry_interval=0.1,
                                   rescan_disks=False,
                                   ensure_mpio_claimed=False):
    def get_target_luns(self, target_name):
    def get_target_lun_count(self, target_name):
    def _logout_iscsi_target(self, session_id):
    def _add_static_target(self, target_name, is_persistent=True):
    def _remove_static_target(self, target_name):
    def _get_login_opts(self, auth_username=None, auth_password=None,
                        auth_type=None, login_flags=0):
    def _session_on_path_exists(self, target_sessions, portal_addr,
                                portal_port, initiator_name):
    def _new_session_required(self, target_iqn, portal_addr, portal_port,
                              initiator_name, mpio_enabled):
    def login_storage_target(self, target_lun, target_iqn, target_portal,
                             auth_username=None, auth_password=None,
                             auth_type=None,
                             mpio_enabled=False,
                             ensure_lun_available=True,
                             initiator_name=None,
                             rescan_attempts=_DEFAULT_RESCAN_ATTEMPTS):
    def ensure_lun_available(self, target_iqn, target_lun,
                             rescan_attempts=_DEFAULT_RESCAN_ATTEMPTS,
                             retry_interval=0,
                             rescan_disks=True,
                             ensure_mpio_claimed=False):
    def logout_storage_target(self, target_iqn):
    def _remove_target_persistent_logins(self, target_iqn):
    def _remove_persistent_login(self, persistent_login):
class ISCSIInitiatorUtils(object): LOG = logging.getLogger(__name__)
class SMBUtils(baseutils.BaseUtils):
    def __init__(self):
    def check_smb_mapping(self, share_path, remove_unavailable_mapping=False):
    def mount_smb_share(self, share_path, username=None, password=None):
    def unmount_smb_share(self, share_path, force=False):
    def get_smb_share_path(self, share_name):
    def is_local_share(self, share_path): LOG = logging.getLogger(__name__)
VHD_SIGNATURE = b'conectix'
VHDX_SIGNATURE = b'vhdxfile'
DEVICE_ID_MAP = {
    constants.DISK_FORMAT_VHD: w_const.VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
    constants.DISK_FORMAT_VHDX: w_const.VIRTUAL_STORAGE_TYPE_DEVICE_VHDX,
}
VHD_HEADER_SIZE_FIX = 512
VHD_BAT_ENTRY_SIZE = 4
VHD_DYNAMIC_DISK_HEADER_SIZE = 1024
VHD_HEADER_SIZE_DYNAMIC = 512
VHD_FOOTER_SIZE_DYNAMIC = 512
VHDX_BAT_ENTRY_SIZE = 8
VHDX_HEADER_OFFSETS = [64 * units.Ki, 128 * units.Ki]
VHDX_HEADER_SECTION_SIZE = units.Mi
VHDX_LOG_LENGTH_OFFSET = 68
VHDX_METADATA_SIZE_OFFSET = 64
VHDX_REGION_TABLE_OFFSET = 192 * units.Ki
VHDX_BS_METADATA_ENTRY_OFFSET = 48
VIRTUAL_DISK_DEFAULT_SECTOR_SIZE = 0x200
VIRTUAL_DISK_DEFAULT_PHYS_SECTOR_SIZE = 0x200
CREATE_VIRTUAL_DISK_FLAGS = {
    constants.VHD_TYPE_FIXED:
        w_const.CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION,
}
class VHDUtils(object):
    def __init__(self):
    def _run_and_check_output(self, *args, **kwargs):
    def _open(self, vhd_path,
              open_flag=0,
              open_access_mask=w_const.VIRTUAL_DISK_ACCESS_ALL,
              open_params=None):
    def close(self, handle):
    def create_vhd(self, new_vhd_path, new_vhd_type, src_path=None,
                   max_internal_size=0, parent_path=None, guid=None):
    def create_dynamic_vhd(self, path, max_internal_size):
    def create_differencing_vhd(self, path, parent_path):
    def convert_vhd(self, src, dest,
                    vhd_type=constants.VHD_TYPE_DYNAMIC):
    def get_vhd_format(self, vhd_path):
    def _get_vhd_device_id(self, vhd_path):
    def _get_vhd_format_by_signature(self, vhd_path):
    def get_vhd_info(self, vhd_path, info_members=None,
                     open_parents=False):
    def _get_vhd_info_member(self, vhd_file, info_member):
    def _parse_vhd_info(self, virt_disk_info, info_member):
    def get_vhd_size(self, vhd_path):
    def get_vhd_parent_path(self, vhd_path):
    def get_vhd_type(self, vhd_path):
    def merge_vhd(self, vhd_path, delete_merged_image=True):
    def reconnect_parent_vhd(self, child_path, parent_path):
    def set_vhd_guid(self, vhd_path, guid):
    def resize_vhd(self, vhd_path, new_max_size, is_file_max_size=True,
                   validate_new_size=True):
    def _check_resize_needed(self, vhd_path, new_size):
    def _resize_vhd(self, vhd_path, new_max_size):
    def get_internal_vhd_size_by_file_size(self, vhd_path,
                                           new_vhd_file_size):
    def _get_internal_vhd_size_by_file_size(self, vhd_path,
                                            new_vhd_file_size,
                                            vhd_info):
    def _get_internal_vhdx_size_by_file_size(self, vhd_path,
                                             new_vhd_file_size,
                                             vhd_info):
    def _get_vhdx_current_header_offset(self, vhdx_file):
    def _get_vhdx_log_size(self, vhdx_file):
    def _get_vhdx_metadata_size_and_offset(self, vhdx_file):
    def _get_vhdx_block_size(self, vhdx_file):
    def get_best_supported_vhd_format(self):
    def flatten_vhd(self, vhd_path):
    def attach_virtual_disk(self, vhd_path, read_only=True,
                            detach_on_handle_close=False):
    def detach_virtual_disk(self, vhd_path):
    def get_virtual_disk_physical_path(self, vhd_path):
    def is_virtual_disk_file_attached(self, vhd_path): DEFAULT_MIN_VERSION = 6.2
DEFAULT_MAX_VERSION = None
def _get_class(class_type, *args, **kwargs):
def get_vmutils(host='.'):
def get_vhdutils():
def get_metricsutils():
def get_networkutils():
def get_nvgreutils():
def get_hostutils():
def get_pathutils():
def get_iscsi_initiator_utils():
def get_livemigrationutils():
def get_smbutils():
def get_rdpconsoleutils():
def get_iscsi_target_utils():
def get_named_pipe_handler(*args, **kwargs):
def get_fc_utils():
def get_diskutils():
def get_clusterutils():
def get_dnsutils():
def get_migrationutils():
def get_processutils():
def get_ioutils():
def get_mutex(*args, **kwargs):
import inspect
from unittest import mock
from oslo_config import cfg
from oslo_utils import importutils
from os_win import exceptions
from os_win.tests.unit import test_base
from os_win.utils.compute import clusterutils
from os_win.utils.compute import livemigrationutils
from os_win.utils.compute import migrationutils
from os_win.utils.compute import rdpconsoleutils
from os_win.utils.compute import vmutils
from os_win.utils.dns import dnsutils
from os_win.utils import hostutils
from os_win.utils.io import ioutils
from os_win.utils.network import networkutils
from os_win.utils import pathutils
from os_win.utils import processutils
from os_win.utils.storage import diskutils
from os_win.utils.storage.initiator import iscsi_utils
from os_win.utils.storage import smbutils
from os_win.utils.storage.virtdisk import vhdutils
from os_win import utilsfactory
# Copyright 2014 Cloudbase Solutions SRL
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Unit tests for the Hyper-V utils factory.
"""




CONF = cfg.CONF


class TestHyperVUtilsFactory(test_base.OsWinBaseTestCase):

    @mock.patch.object(utilsfactory.utils, 'get_windows_version')
    def test_get_class_unsupported_win_version(self, mock_get_windows_version):
        mock_get_windows_version.return_value = '5.2'
        self.assertRaises(exceptions.HyperVException, utilsfactory._get_class,
                          'hostutils')

    def test_get_class_unsupported_class_type(self):
        self.assertRaises(exceptions.HyperVException,
                          utilsfactory._get_class,
                          'invalid_class_type')

    @mock.patch.object(utilsfactory.utils, 'get_windows_version')
    def _check_get_class(self, mock_get_windows_version, expected_class,
                         class_type, windows_version='6.2', **kwargs):
        mock_get_windows_version.return_value = windows_version

        method = getattr(utilsfactory, 'get_%s' % class_type)
        instance = method(**kwargs)
        self.assertEqual(expected_class, type(instance))

        return instance

    def test_get_vmutils(self):
        instance = self._check_get_class(expected_class=vmutils.VMUtils,
                                         class_type='vmutils',
                                         host=mock.sentinel.host)
        self.assertEqual(mock.sentinel.host, instance._host)

    def test_get_vhdutils(self):

        self._check_get_class(expected_class=vhdutils.VHDUtils,