From 875cf3318d4a6373922c99ba6f58a88d0af1b234 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Wed, 8 Jan 2020 12:21:38 +0200 Subject: [PATCH] Fixed circular import --- monkey/common/cloud/all_instances.py | 11 +++++++++++ monkey/common/cloud/instance.py | 17 +++++------------ .../collectors/environment_collector.py | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 monkey/common/cloud/all_instances.py diff --git a/monkey/common/cloud/all_instances.py b/monkey/common/cloud/all_instances.py new file mode 100644 index 000000000..986bf1a80 --- /dev/null +++ b/monkey/common/cloud/all_instances.py @@ -0,0 +1,11 @@ +from typing import List + +from common.cloud.aws.aws_instance import AwsInstance +from common.cloud.azure.azure_instance import AzureInstance +from common.cloud.instance import CloudInstance + +all_cloud_instances = [AwsInstance(), AzureInstance()] + + +def get_all_cloud_instances() -> List[CloudInstance]: + return all_cloud_instances diff --git a/monkey/common/cloud/instance.py b/monkey/common/cloud/instance.py index 2e702b867..61ab4c734 100644 --- a/monkey/common/cloud/instance.py +++ b/monkey/common/cloud/instance.py @@ -1,18 +1,11 @@ -from typing import List - -from common.cloud.aws.aws_instance import AwsInstance -from common.cloud.azure.azure_instance import AzureInstance - - class CloudInstance(object): + """ + This is an abstract class which represents a cloud instance. + + The current machine can be a cloud instance (for example EC2 instance or Azure VM). + """ def is_instance(self) -> bool: raise NotImplementedError() def get_cloud_provider_name(self) -> str: raise NotImplementedError() - - all_cloud_instances = [AwsInstance(), AzureInstance()] - - @staticmethod - def get_all_cloud_instances() -> List['CloudInstance']: - return CloudInstance.all_cloud_instances diff --git a/monkey/infection_monkey/system_info/collectors/environment_collector.py b/monkey/infection_monkey/system_info/collectors/environment_collector.py index 56df5906b..c679e04f7 100644 --- a/monkey/infection_monkey/system_info/collectors/environment_collector.py +++ b/monkey/infection_monkey/system_info/collectors/environment_collector.py @@ -1,3 +1,4 @@ +from common.cloud.all_instances import get_all_cloud_instances from common.cloud.aws.aws_instance import AwsInstance from common.cloud.azure.azure_instance import AzureInstance from common.cloud.environment_names import ON_PREMISE, AZURE, AWS @@ -7,7 +8,7 @@ from infection_monkey.system_info.system_info_collector import SystemInfoCollect def get_monkey_environment() -> str: env = ON_PREMISE - for instance in CloudInstance.get_all_cloud_instances(): + for instance in get_all_cloud_instances(): if instance.is_instance(): env = instance.get_cloud_provider_name() return env