From 406ca1d8f902ab7b03003996fa214d3c11d16f62 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 3 May 2022 11:40:15 +0000 Subject: [PATCH] Admin - Move internal EC2 models (#5090) --- moto/batch/models.py | 4 +- moto/cloudformation/parsing.py | 2 +- moto/ec2/{models.py => models/__init__.py} | 66 +++++++++---------- moto/ec2/{_models => models}/amis.py | 0 .../availability_zones_and_regions.py | 0 .../{_models => models}/carrier_gateways.py | 0 moto/ec2/{_models => models}/core.py | 2 +- .../{_models => models}/customer_gateways.py | 0 moto/ec2/{_models => models}/dhcp_options.py | 0 .../elastic_block_store.py | 0 .../elastic_ip_addresses.py | 0 .../elastic_network_interfaces.py | 0 moto/ec2/{_models => models}/flow_logs.py | 0 .../iam_instance_profile.py | 0 .../ec2/{_models => models}/instance_types.py | 0 moto/ec2/{_models => models}/instances.py | 0 .../{_models => models}/internet_gateways.py | 0 moto/ec2/{_models => models}/key_pairs.py | 0 .../{_models => models}/launch_templates.py | 0 .../{_models => models}/managed_prefixes.py | 0 moto/ec2/{_models => models}/nat_gateways.py | 0 moto/ec2/{_models => models}/network_acls.py | 0 moto/ec2/{_models => models}/route_tables.py | 0 .../{_models => models}/security_groups.py | 0 moto/ec2/{_models => models}/spot_requests.py | 0 moto/ec2/{_models => models}/subnets.py | 0 moto/ec2/{_models => models}/tags.py | 0 .../{_models => models}/transit_gateway.py | 0 .../transit_gateway_attachments.py | 0 .../transit_gateway_route_tables.py | 0 .../vpc_peering_connections.py | 0 .../vpc_service_configuration.py | 0 moto/ec2/{_models => models}/vpcs.py | 3 +- .../{_models => models}/vpn_connections.py | 0 moto/ec2/{_models => models}/vpn_gateway.py | 0 tests/test_ec2/test_amis.py | 2 +- 36 files changed, 39 insertions(+), 40 deletions(-) rename moto/ec2/{models.py => models/__init__.py} (81%) rename moto/ec2/{_models => models}/amis.py (100%) rename moto/ec2/{_models => models}/availability_zones_and_regions.py (100%) rename moto/ec2/{_models => models}/carrier_gateways.py (100%) rename moto/ec2/{_models => models}/core.py (96%) rename moto/ec2/{_models => models}/customer_gateways.py (100%) rename moto/ec2/{_models => models}/dhcp_options.py (100%) rename moto/ec2/{_models => models}/elastic_block_store.py (100%) rename moto/ec2/{_models => models}/elastic_ip_addresses.py (100%) rename moto/ec2/{_models => models}/elastic_network_interfaces.py (100%) rename moto/ec2/{_models => models}/flow_logs.py (100%) rename moto/ec2/{_models => models}/iam_instance_profile.py (100%) rename moto/ec2/{_models => models}/instance_types.py (100%) rename moto/ec2/{_models => models}/instances.py (100%) rename moto/ec2/{_models => models}/internet_gateways.py (100%) rename moto/ec2/{_models => models}/key_pairs.py (100%) rename moto/ec2/{_models => models}/launch_templates.py (100%) rename moto/ec2/{_models => models}/managed_prefixes.py (100%) rename moto/ec2/{_models => models}/nat_gateways.py (100%) rename moto/ec2/{_models => models}/network_acls.py (100%) rename moto/ec2/{_models => models}/route_tables.py (100%) rename moto/ec2/{_models => models}/security_groups.py (100%) rename moto/ec2/{_models => models}/spot_requests.py (100%) rename moto/ec2/{_models => models}/subnets.py (100%) rename moto/ec2/{_models => models}/tags.py (100%) rename moto/ec2/{_models => models}/transit_gateway.py (100%) rename moto/ec2/{_models => models}/transit_gateway_attachments.py (100%) rename moto/ec2/{_models => models}/transit_gateway_route_tables.py (100%) rename moto/ec2/{_models => models}/vpc_peering_connections.py (100%) rename moto/ec2/{_models => models}/vpc_service_configuration.py (100%) rename moto/ec2/{_models => models}/vpcs.py (99%) rename moto/ec2/{_models => models}/vpn_connections.py (100%) rename moto/ec2/{_models => models}/vpn_gateway.py (100%) diff --git a/moto/batch/models.py b/moto/batch/models.py index 4e9662cdb..62a70553c 100644 --- a/moto/batch/models.py +++ b/moto/batch/models.py @@ -25,8 +25,8 @@ from .utils import ( lowercase_first_key, ) from moto.ec2.exceptions import InvalidSubnetIdError -from moto.ec2._models.instance_types import INSTANCE_TYPES as EC2_INSTANCE_TYPES -from moto.ec2._models.instance_types import INSTANCE_FAMILIES as EC2_INSTANCE_FAMILIES +from moto.ec2.models.instance_types import INSTANCE_TYPES as EC2_INSTANCE_TYPES +from moto.ec2.models.instance_types import INSTANCE_FAMILIES as EC2_INSTANCE_FAMILIES from moto.iam.exceptions import IAMNotFoundException from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID from moto.core.utils import unix_time_millis, BackendDict diff --git a/moto/cloudformation/parsing.py b/moto/cloudformation/parsing.py index 300c6137d..0b5fc7f6a 100644 --- a/moto/cloudformation/parsing.py +++ b/moto/cloudformation/parsing.py @@ -23,7 +23,7 @@ from moto.cloudwatch import models # noqa # pylint: disable=all from moto.datapipeline import models # noqa # pylint: disable=all from moto.dynamodb import models # noqa # pylint: disable=all from moto.ec2 import models as ec2_models -from moto.ec2._models.core import TaggedEC2Resource +from moto.ec2.models.core import TaggedEC2Resource from moto.ecr import models # noqa # pylint: disable=all from moto.ecs import models # noqa # pylint: disable=all from moto.efs import models # noqa # pylint: disable=all diff --git a/moto/ec2/models.py b/moto/ec2/models/__init__.py similarity index 81% rename from moto/ec2/models.py rename to moto/ec2/models/__init__.py index c4f4cbc61..82e5f159f 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models/__init__.py @@ -1,54 +1,54 @@ from moto.core import ACCOUNT_ID from moto.core import BaseBackend from moto.core.utils import BackendDict -from .exceptions import ( +from ..exceptions import ( EC2ClientError, InvalidID, MissingParameterError, MotoNotImplementedError, ) -from ._models.amis import AmiBackend -from ._models.carrier_gateways import CarrierGatewayBackend -from ._models.customer_gateways import CustomerGatewayBackend -from ._models.dhcp_options import DHCPOptionsSetBackend -from ._models.elastic_block_store import EBSBackend -from ._models.elastic_ip_addresses import ElasticAddressBackend -from ._models.elastic_network_interfaces import NetworkInterfaceBackend -from ._models.flow_logs import FlowLogsBackend -from ._models.key_pairs import KeyPairBackend -from ._models.launch_templates import LaunchTemplateBackend -from ._models.managed_prefixes import ManagedPrefixListBackend -from ._models.iam_instance_profile import IamInstanceProfileAssociationBackend -from ._models.internet_gateways import ( +from .amis import AmiBackend +from .carrier_gateways import CarrierGatewayBackend +from .customer_gateways import CustomerGatewayBackend +from .dhcp_options import DHCPOptionsSetBackend +from .elastic_block_store import EBSBackend +from .elastic_ip_addresses import ElasticAddressBackend +from .elastic_network_interfaces import NetworkInterfaceBackend +from .flow_logs import FlowLogsBackend +from .key_pairs import KeyPairBackend +from .launch_templates import LaunchTemplateBackend +from .managed_prefixes import ManagedPrefixListBackend +from .iam_instance_profile import IamInstanceProfileAssociationBackend +from .internet_gateways import ( InternetGatewayBackend, EgressOnlyInternetGatewayBackend, ) -from ._models.instances import InstanceBackend -from ._models.instance_types import InstanceTypeBackend, InstanceTypeOfferingBackend -from ._models.nat_gateways import NatGatewayBackend -from ._models.network_acls import NetworkAclBackend -from ._models.availability_zones_and_regions import RegionsAndZonesBackend -from ._models.route_tables import RouteBackend, RouteTableBackend -from ._models.security_groups import SecurityGroupBackend -from ._models.spot_requests import ( +from .instances import InstanceBackend +from .instance_types import InstanceTypeBackend, InstanceTypeOfferingBackend +from .nat_gateways import NatGatewayBackend +from .network_acls import NetworkAclBackend +from .availability_zones_and_regions import RegionsAndZonesBackend +from .route_tables import RouteBackend, RouteTableBackend +from .security_groups import SecurityGroupBackend +from .spot_requests import ( SpotRequestBackend, SpotPriceBackend, SpotFleetBackend, ) -from ._models.subnets import SubnetBackend, SubnetRouteTableAssociationBackend -from ._models.tags import TagBackend -from ._models.transit_gateway import TransitGatewayBackend -from ._models.transit_gateway_route_tables import ( +from .subnets import SubnetBackend, SubnetRouteTableAssociationBackend +from .tags import TagBackend +from .transit_gateway import TransitGatewayBackend +from .transit_gateway_route_tables import ( TransitGatewayRelationsBackend, TransitGatewayRouteTableBackend, ) -from ._models.transit_gateway_attachments import TransitGatewayAttachmentBackend -from ._models.vpn_gateway import VpnGatewayBackend -from ._models.vpn_connections import VPNConnectionBackend -from ._models.vpcs import VPCBackend -from ._models.vpc_peering_connections import VPCPeeringConnectionBackend -from ._models.vpc_service_configuration import VPCServiceConfigurationBackend -from .utils import ( +from .transit_gateway_attachments import TransitGatewayAttachmentBackend +from .vpn_gateway import VpnGatewayBackend +from .vpn_connections import VPNConnectionBackend +from .vpcs import VPCBackend +from .vpc_peering_connections import VPCPeeringConnectionBackend +from .vpc_service_configuration import VPCServiceConfigurationBackend +from ..utils import ( EC2_RESOURCE_TO_PREFIX, is_valid_resource_id, get_prefix, diff --git a/moto/ec2/_models/amis.py b/moto/ec2/models/amis.py similarity index 100% rename from moto/ec2/_models/amis.py rename to moto/ec2/models/amis.py diff --git a/moto/ec2/_models/availability_zones_and_regions.py b/moto/ec2/models/availability_zones_and_regions.py similarity index 100% rename from moto/ec2/_models/availability_zones_and_regions.py rename to moto/ec2/models/availability_zones_and_regions.py diff --git a/moto/ec2/_models/carrier_gateways.py b/moto/ec2/models/carrier_gateways.py similarity index 100% rename from moto/ec2/_models/carrier_gateways.py rename to moto/ec2/models/carrier_gateways.py diff --git a/moto/ec2/_models/core.py b/moto/ec2/models/core.py similarity index 96% rename from moto/ec2/_models/core.py rename to moto/ec2/models/core.py index 8941321bc..c4d9445cb 100644 --- a/moto/ec2/_models/core.py +++ b/moto/ec2/models/core.py @@ -4,7 +4,7 @@ from ..exceptions import FilterNotImplementedError class TaggedEC2Resource(BaseModel): - def get_tags(self, *args, **kwargs): + def get_tags(self): tags = [] if self.id: tags = self.ec2_backend.describe_tags(filters={"resource-id": [self.id]}) diff --git a/moto/ec2/_models/customer_gateways.py b/moto/ec2/models/customer_gateways.py similarity index 100% rename from moto/ec2/_models/customer_gateways.py rename to moto/ec2/models/customer_gateways.py diff --git a/moto/ec2/_models/dhcp_options.py b/moto/ec2/models/dhcp_options.py similarity index 100% rename from moto/ec2/_models/dhcp_options.py rename to moto/ec2/models/dhcp_options.py diff --git a/moto/ec2/_models/elastic_block_store.py b/moto/ec2/models/elastic_block_store.py similarity index 100% rename from moto/ec2/_models/elastic_block_store.py rename to moto/ec2/models/elastic_block_store.py diff --git a/moto/ec2/_models/elastic_ip_addresses.py b/moto/ec2/models/elastic_ip_addresses.py similarity index 100% rename from moto/ec2/_models/elastic_ip_addresses.py rename to moto/ec2/models/elastic_ip_addresses.py diff --git a/moto/ec2/_models/elastic_network_interfaces.py b/moto/ec2/models/elastic_network_interfaces.py similarity index 100% rename from moto/ec2/_models/elastic_network_interfaces.py rename to moto/ec2/models/elastic_network_interfaces.py diff --git a/moto/ec2/_models/flow_logs.py b/moto/ec2/models/flow_logs.py similarity index 100% rename from moto/ec2/_models/flow_logs.py rename to moto/ec2/models/flow_logs.py diff --git a/moto/ec2/_models/iam_instance_profile.py b/moto/ec2/models/iam_instance_profile.py similarity index 100% rename from moto/ec2/_models/iam_instance_profile.py rename to moto/ec2/models/iam_instance_profile.py diff --git a/moto/ec2/_models/instance_types.py b/moto/ec2/models/instance_types.py similarity index 100% rename from moto/ec2/_models/instance_types.py rename to moto/ec2/models/instance_types.py diff --git a/moto/ec2/_models/instances.py b/moto/ec2/models/instances.py similarity index 100% rename from moto/ec2/_models/instances.py rename to moto/ec2/models/instances.py diff --git a/moto/ec2/_models/internet_gateways.py b/moto/ec2/models/internet_gateways.py similarity index 100% rename from moto/ec2/_models/internet_gateways.py rename to moto/ec2/models/internet_gateways.py diff --git a/moto/ec2/_models/key_pairs.py b/moto/ec2/models/key_pairs.py similarity index 100% rename from moto/ec2/_models/key_pairs.py rename to moto/ec2/models/key_pairs.py diff --git a/moto/ec2/_models/launch_templates.py b/moto/ec2/models/launch_templates.py similarity index 100% rename from moto/ec2/_models/launch_templates.py rename to moto/ec2/models/launch_templates.py diff --git a/moto/ec2/_models/managed_prefixes.py b/moto/ec2/models/managed_prefixes.py similarity index 100% rename from moto/ec2/_models/managed_prefixes.py rename to moto/ec2/models/managed_prefixes.py diff --git a/moto/ec2/_models/nat_gateways.py b/moto/ec2/models/nat_gateways.py similarity index 100% rename from moto/ec2/_models/nat_gateways.py rename to moto/ec2/models/nat_gateways.py diff --git a/moto/ec2/_models/network_acls.py b/moto/ec2/models/network_acls.py similarity index 100% rename from moto/ec2/_models/network_acls.py rename to moto/ec2/models/network_acls.py diff --git a/moto/ec2/_models/route_tables.py b/moto/ec2/models/route_tables.py similarity index 100% rename from moto/ec2/_models/route_tables.py rename to moto/ec2/models/route_tables.py diff --git a/moto/ec2/_models/security_groups.py b/moto/ec2/models/security_groups.py similarity index 100% rename from moto/ec2/_models/security_groups.py rename to moto/ec2/models/security_groups.py diff --git a/moto/ec2/_models/spot_requests.py b/moto/ec2/models/spot_requests.py similarity index 100% rename from moto/ec2/_models/spot_requests.py rename to moto/ec2/models/spot_requests.py diff --git a/moto/ec2/_models/subnets.py b/moto/ec2/models/subnets.py similarity index 100% rename from moto/ec2/_models/subnets.py rename to moto/ec2/models/subnets.py diff --git a/moto/ec2/_models/tags.py b/moto/ec2/models/tags.py similarity index 100% rename from moto/ec2/_models/tags.py rename to moto/ec2/models/tags.py diff --git a/moto/ec2/_models/transit_gateway.py b/moto/ec2/models/transit_gateway.py similarity index 100% rename from moto/ec2/_models/transit_gateway.py rename to moto/ec2/models/transit_gateway.py diff --git a/moto/ec2/_models/transit_gateway_attachments.py b/moto/ec2/models/transit_gateway_attachments.py similarity index 100% rename from moto/ec2/_models/transit_gateway_attachments.py rename to moto/ec2/models/transit_gateway_attachments.py diff --git a/moto/ec2/_models/transit_gateway_route_tables.py b/moto/ec2/models/transit_gateway_route_tables.py similarity index 100% rename from moto/ec2/_models/transit_gateway_route_tables.py rename to moto/ec2/models/transit_gateway_route_tables.py diff --git a/moto/ec2/_models/vpc_peering_connections.py b/moto/ec2/models/vpc_peering_connections.py similarity index 100% rename from moto/ec2/_models/vpc_peering_connections.py rename to moto/ec2/models/vpc_peering_connections.py diff --git a/moto/ec2/_models/vpc_service_configuration.py b/moto/ec2/models/vpc_service_configuration.py similarity index 100% rename from moto/ec2/_models/vpc_service_configuration.py rename to moto/ec2/models/vpc_service_configuration.py diff --git a/moto/ec2/_models/vpcs.py b/moto/ec2/models/vpcs.py similarity index 99% rename from moto/ec2/_models/vpcs.py rename to moto/ec2/models/vpcs.py index 235f1ff61..b5cd04d0a 100644 --- a/moto/ec2/_models/vpcs.py +++ b/moto/ec2/models/vpcs.py @@ -472,8 +472,7 @@ class VPCBackend(object): self.delete_route(route_table.id, response.get("cidr_block")) if response: return response - else: - raise InvalidVpcCidrBlockAssociationIdError(association_id) + raise InvalidVpcCidrBlockAssociationIdError(association_id) def associate_vpc_cidr_block( self, vpc_id, cidr_block, amazon_provided_ipv6_cidr_block diff --git a/moto/ec2/_models/vpn_connections.py b/moto/ec2/models/vpn_connections.py similarity index 100% rename from moto/ec2/_models/vpn_connections.py rename to moto/ec2/models/vpn_connections.py diff --git a/moto/ec2/_models/vpn_gateway.py b/moto/ec2/models/vpn_gateway.py similarity index 100% rename from moto/ec2/_models/vpn_gateway.py rename to moto/ec2/models/vpn_gateway.py diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index 422ac7115..d93c8ce32 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -7,7 +7,7 @@ import random from moto import mock_ec2 from moto.ec2.models import OWNER_ID -from moto.ec2._models.amis import AMIS +from moto.ec2.models.amis import AMIS from moto.core import ACCOUNT_ID from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_PARAVIRTUAL from uuid import uuid4