<s> """<STR_LIT>""" <EOL> import collections <EOL> import json <EOL> import logging <EOL> import threading <EOL> from perfkitbenchmarker import disk <EOL> from perfkitbenchmarker import flags <EOL> from perfkitbenchmarker import linux_virtual_machine <EOL> from perfkitbenchmarker import os_types <EOL> from perfkitbenchmarker import virtual_machine <EOL> from perfkitbenchmarker import windows_virtual_machine <EOL> FLAGS = flags . FLAGS <EOL> class StaticVmSpec ( virtual_machine . BaseVmSpec ) : <EOL> """<STR_LIT>""" <EOL> CLOUD = '<STR_LIT>' <EOL> def __init__ ( self , component_full_name , ip_address = None , user_name = None , <EOL> ssh_private_key = None , internal_ip = None , ssh_port = <NUM_LIT> , <EOL> password = None , disk_specs = None , os_type = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( StaticVmSpec , self ) . __init__ ( component_full_name , ** kwargs ) <EOL> self . ip_address = ip_address <EOL> self . user_name = user_name <EOL> self . ssh_private_key = ssh_private_key <EOL> self . internal_ip = internal_ip <EOL> self . ssh_port = ssh_port <EOL> self . password = password <EOL> self . os_type = os_type <EOL> self . disk_specs = [ <EOL> disk . BaseDiskSpec ( <EOL> '<STR_LIT>' . format ( component_full_name , i ) , ** disk_spec ) <EOL> for i , disk_spec in enumerate ( disk_specs or ( ) ) ] <EOL> class StaticDisk ( disk . BaseDisk ) : <EOL> """<STR_LIT>""" <EOL> def _Create ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _Delete ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def Attach ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def Detach ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class StaticVirtualMachine ( virtual_machine . BaseVirtualMachine ) : <EOL> """<STR_LIT>""" <EOL> CLOUD = '<STR_LIT>' <EOL> is_static = True <EOL> vm_pool = collections . deque ( ) <EOL> vm_pool_lock = threading . Lock ( ) <EOL> def __init__ ( self , vm_spec ) : <EOL> """<STR_LIT>""" <EOL> super ( StaticVirtualMachine , self ) . __init__ ( vm_spec ) <EOL> self . ip_address = vm_spec . ip_address <EOL> self . user_name = vm_spec . user_name <EOL> self . ssh_private_key = vm_spec . ssh_private_key <EOL> self . internal_ip = vm_spec . internal_ip <EOL> self . zone = self . zone or ( '<STR_LIT>' % ( self . user_name , <EOL> self . ip_address ) ) <EOL> self . ssh_port = vm_spec . ssh_port <EOL> self . password = vm_spec . password <EOL> self . disk_specs = vm_spec . disk_specs <EOL> self . from_pool = False <EOL> def _Create ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _Delete ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . from_pool : <EOL> with self . vm_pool_lock : <EOL> self . vm_pool . appendleft ( self ) <EOL> def CreateScratchDisk ( self , disk_spec ) : <EOL> """<STR_LIT>""" <EOL> spec = self . disk_specs [ len ( self . scratch_disks ) ] <EOL> self . scratch_disks . append ( StaticDisk ( spec ) ) <EOL> def DeleteScratchDisks ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def GetLocalDisks ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ disk_spec . device_path <EOL> for disk_spec in self . disk_specs if disk_spec . device_path ] <EOL> @ classmethod <EOL> def ReadStaticVirtualMachineFile ( cls , file_obj ) : <EOL> """<STR_LIT>""" <EOL> vm_arr = json . load ( file_obj ) <EOL> if not isinstance ( vm_arr , list ) : <EOL> raise ValueError ( '<STR_LIT>' % <EOL> type ( vm_arr ) ) <EOL> required_keys = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> linux_required_keys = required_keys | frozenset ( [ '<STR_LIT>' ] ) <EOL> required_keys_by_os = { <EOL> os_types . WINDOWS : required_keys | frozenset ( [ '<STR_LIT:password>' ] ) , <EOL> os_types . DEBIAN : linux_required_keys , <EOL> os_types . RHEL : linux_required_keys , <EOL> os_types . UBUNTU_CONTAINER : linux_required_keys , <EOL> } <EOL> required_keys = required_keys_by_os [ FLAGS . os_type ] <EOL> optional_keys = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> allowed_keys = required_keys | optional_keys <EOL> def VerifyItemFormat ( item ) : <EOL> """<STR_LIT>""" <EOL> item_keys = frozenset ( item ) <EOL> extra_keys = sorted ( item_keys - allowed_keys ) <EOL> missing_keys = required_keys - item_keys <EOL> if extra_keys : <EOL> raise ValueError ( '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( extra_keys ) ) ) <EOL> elif missing_keys : <EOL> raise ValueError ( '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( missing_keys ) ) ) <EOL> for item in vm_arr : <EOL> VerifyItemFormat ( item ) <EOL> ip_address = item [ '<STR_LIT>' ] <EOL> user_name = item [ '<STR_LIT>' ] <EOL> keyfile_path = item . get ( '<STR_LIT>' ) <EOL> internal_ip = item . get ( '<STR_LIT>' ) <EOL> zone = item . get ( '<STR_LIT>' ) <EOL> local_disks = item . get ( '<STR_LIT>' , [ ] ) <EOL> password = item . get ( '<STR_LIT:password>' ) <EOL> if not isinstance ( local_disks , list ) : <EOL> raise ValueError ( '<STR_LIT>' . format ( <EOL> local_disks ) ) <EOL> scratch_disk_mountpoints = item . get ( '<STR_LIT>' , [ ] ) <EOL> if not isinstance ( scratch_disk_mountpoints , list ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( <EOL> scratch_disk_mountpoints ) ) <EOL> ssh_port = item . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> os_type = item . get ( '<STR_LIT>' ) <EOL> install_packages = item . get ( '<STR_LIT>' , True ) <EOL> if ( ( os_type == os_types . WINDOWS and FLAGS . os_type != os_types . WINDOWS ) or <EOL> ( os_type != os_types . WINDOWS and FLAGS . os_type == os_types . WINDOWS ) ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> disk_kwargs_list = [ ] <EOL> for path in scratch_disk_mountpoints : <EOL> disk_kwargs_list . append ( { '<STR_LIT>' : path } ) <EOL> for local_disk in local_disks : <EOL> disk_kwargs_list . append ( { '<STR_LIT>' : local_disk } ) <EOL> vm_spec = StaticVmSpec ( <EOL> '<STR_LIT>' , ip_address = ip_address , user_name = user_name , <EOL> ssh_port = ssh_port , install_packages = install_packages , <EOL> ssh_private_key = keyfile_path , internal_ip = internal_ip , zone = zone , <EOL> disk_specs = disk_kwargs_list , password = password ) <EOL> vm_class = GetStaticVmClass ( os_type ) <EOL> vm = vm_class ( vm_spec ) <EOL> cls . vm_pool . append ( vm ) <EOL> @ classmethod <EOL> def GetStaticVirtualMachine ( cls ) : <EOL> """<STR_LIT>""" <EOL> with cls . vm_pool_lock : <EOL> if cls . vm_pool : <EOL> vm = cls . vm_pool . popleft ( ) <EOL> vm . from_pool = True <EOL> return vm <EOL> else : <EOL> return None <EOL> def GetStaticVmClass ( os_type ) : <EOL> """<STR_LIT>""" <EOL> class_dict = { <EOL> os_types . DEBIAN : DebianBasedStaticVirtualMachine , <EOL> os_types . RHEL : RhelBasedStaticVirtualMachine , <EOL> os_types . WINDOWS : WindowsBasedStaticVirtualMachine , <EOL> os_types . UBUNTU_CONTAINER : ContainerizedStaticVirtualMachine , <EOL> } <EOL> if os_type in class_dict : <EOL> return class_dict [ os_type ] <EOL> else : <EOL> logging . warning ( '<STR_LIT>' ) <EOL> return DebianBasedStaticVirtualMachine <EOL> class ContainerizedStaticVirtualMachine ( <EOL> StaticVirtualMachine , linux_virtual_machine . ContainerizedDebianMixin ) : <EOL> pass <EOL> class DebianBasedStaticVirtualMachine ( StaticVirtualMachine , <EOL> linux_virtual_machine . DebianMixin ) : <EOL> pass <EOL> class RhelBasedStaticVirtualMachine ( StaticVirtualMachine , <EOL> linux_virtual_machine . RhelMixin ) : <EOL> pass <EOL> class WindowsBasedStaticVirtualMachine ( StaticVirtualMachine , <EOL> windows_virtual_machine . WindowsMixin ) : <EOL> pass </s>
