From d844fc597a03001fe0ca34aa7138c333b4031eed Mon Sep 17 00:00:00 2001 From: Dan King Date: Fri, 1 Sep 2023 15:26:53 -0400 Subject: [PATCH 1/3] [batch] delete unnecessary backwards compatibility code --- batch/batch/cloud/gcp/instance_config.py | 30 ++---------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/batch/batch/cloud/gcp/instance_config.py b/batch/batch/cloud/gcp/instance_config.py index 4a74aaf34a7..3d86de745b3 100644 --- a/batch/batch/cloud/gcp/instance_config.py +++ b/batch/batch/cloud/gcp/instance_config.py @@ -118,7 +118,6 @@ def from_dict(data: dict) -> 'GCPSlimInstanceConfig': data['instance']['type'], data['instance']['cores'], ) - instance_family = data['instance']['family'] else: machine_type = data['machine_type'] preemptible = data['preemptible'] @@ -127,33 +126,8 @@ def from_dict(data: dict) -> 'GCPSlimInstanceConfig': boot_disk_size_gb = data['boot_disk_size_gb'] job_private = data['job_private'] - machine_type_parts = gcp_machine_type_to_parts(machine_type) - assert machine_type_parts is not None, machine_type - instance_family = machine_type_parts.machine_family - - resources = data.get('resources') - if resources is None: - assert data['version'] < 5, data - - preemptible_str = 'preemptible' if preemptible else 'nonpreemptible' - - if local_ssd_data_disk: - data_disk_resource = GCPStaticSizedDiskResource('disk/local-ssd/1', data_disk_size_gb) - else: - data_disk_resource = GCPStaticSizedDiskResource('disk/pd-ssd/1', data_disk_size_gb) - - # hard coded product versions "/1" are for backwards compatibility - resources = [ - GCPComputeResource(f'compute/{instance_family}-{preemptible_str}/1'), - GCPMemoryResource(f'memory/{instance_family}-{preemptible_str}/1'), - GCPStaticSizedDiskResource('disk/pd-ssd/1', boot_disk_size_gb), - data_disk_resource, - GCPDynamicSizedDiskResource('disk/pd-ssd/1'), - GCPIPFeeResource('service-fee/1'), - GCPServiceFeeResource('ip-fee/1024/1'), - ] - else: - resources = [gcp_resource_from_dict(data) for data in resources] + assert 'resources' in data and data['resources'] is not None + resources = [gcp_resource_from_dict(data) for data in data['resources']] return GCPSlimInstanceConfig( machine_type, From f5f9a17a69510419ff045dadc86151e420929aa3 Mon Sep 17 00:00:00 2001 From: Dan King Date: Fri, 1 Sep 2023 15:40:00 -0400 Subject: [PATCH 2/3] delete more things --- .../cloud/azure/driver/resource_manager.py | 3 -- .../cloud/gcp/driver/resource_manager.py | 3 -- batch/batch/cloud/gcp/instance_config.py | 30 +++++-------------- batch/batch/driver/resource_manager.py | 4 --- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/batch/batch/cloud/azure/driver/resource_manager.py b/batch/batch/cloud/azure/driver/resource_manager.py index 67109dcfb4e..6d9200391c6 100644 --- a/batch/batch/cloud/azure/driver/resource_manager.py +++ b/batch/batch/cloud/azure/driver/resource_manager.py @@ -131,9 +131,6 @@ def instance_config( location, ) - def instance_config_from_dict(self, data: dict) -> AzureSlimInstanceConfig: - return AzureSlimInstanceConfig.from_dict(data) - async def create_vm( self, file_store: FileStore, diff --git a/batch/batch/cloud/gcp/driver/resource_manager.py b/batch/batch/cloud/gcp/driver/resource_manager.py index b144be3fd78..8407620d73f 100644 --- a/batch/batch/cloud/gcp/driver/resource_manager.py +++ b/batch/batch/cloud/gcp/driver/resource_manager.py @@ -105,9 +105,6 @@ def instance_config( location, ) - def instance_config_from_dict(self, data: dict) -> GCPSlimInstanceConfig: - return GCPSlimInstanceConfig.from_dict(data) - async def create_vm( self, file_store: FileStore, diff --git a/batch/batch/cloud/gcp/instance_config.py b/batch/batch/cloud/gcp/instance_config.py index 3d86de745b3..147f528d70f 100644 --- a/batch/batch/cloud/gcp/instance_config.py +++ b/batch/batch/cloud/gcp/instance_config.py @@ -103,28 +103,14 @@ def region_for(self, location: str) -> str: @staticmethod def from_dict(data: dict) -> 'GCPSlimInstanceConfig': - if data['version'] < 4: - disks = data['disks'] - assert len(disks) == 2, data - assert disks[0]['boot'] - boot_disk_size_gb = disks[0]['size'] - assert not disks[1]['boot'] - local_ssd_data_disk = disks[1]['type'] == 'local-ssd' - data_disk_size_gb = disks[1]['size'] - job_private = data['job-private'] - preemptible = data['instance']['preemptible'] - machine_type = family_worker_type_cores_to_gcp_machine_type( - data['instance']['family'], - data['instance']['type'], - data['instance']['cores'], - ) - else: - machine_type = data['machine_type'] - preemptible = data['preemptible'] - local_ssd_data_disk = data['local_ssd_data_disk'] - data_disk_size_gb = data['data_disk_size_gb'] - boot_disk_size_gb = data['boot_disk_size_gb'] - job_private = data['job_private'] + assert data['version'] == GCP_INSTANCE_CONFIG_VERSION + + machine_type = data['machine_type'] + preemptible = data['preemptible'] + local_ssd_data_disk = data['local_ssd_data_disk'] + data_disk_size_gb = data['data_disk_size_gb'] + boot_disk_size_gb = data['boot_disk_size_gb'] + job_private = data['job_private'] assert 'resources' in data and data['resources'] is not None resources = [gcp_resource_from_dict(data) for data in data['resources']] diff --git a/batch/batch/driver/resource_manager.py b/batch/batch/driver/resource_manager.py index 9e4957029b3..38c6c2bbe95 100644 --- a/batch/batch/driver/resource_manager.py +++ b/batch/batch/driver/resource_manager.py @@ -84,10 +84,6 @@ def instance_config( ) -> InstanceConfig: raise NotImplementedError - @abc.abstractmethod - def instance_config_from_dict(self, data: dict) -> InstanceConfig: - raise NotImplementedError - @abc.abstractmethod async def create_vm( self, From 4c21888010980ffd23a1846e1b184ca6d64e98c4 Mon Sep 17 00:00:00 2001 From: Dan King Date: Fri, 1 Sep 2023 18:45:14 -0400 Subject: [PATCH 3/3] lint --- batch/batch/cloud/gcp/instance_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batch/batch/cloud/gcp/instance_config.py b/batch/batch/cloud/gcp/instance_config.py index 147f528d70f..3eb8b314a5f 100644 --- a/batch/batch/cloud/gcp/instance_config.py +++ b/batch/batch/cloud/gcp/instance_config.py @@ -2,7 +2,7 @@ from ...driver.billing_manager import ProductVersions from ...instance_config import InstanceConfig -from .resource_utils import family_worker_type_cores_to_gcp_machine_type, gcp_machine_type_to_parts +from .resource_utils import gcp_machine_type_to_parts from .resources import ( GCPComputeResource, GCPDynamicSizedDiskResource,