From 81b44f0ebbe7bc8d8ac70fd24178cae2ae420771 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Wed, 1 Jan 2020 17:01:06 +0200 Subject: [PATCH] WIP - created azure instance class --- monkey/common/cloud/azure/__init__.py | 0 monkey/common/cloud/azure/azure_instance.py | 27 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 monkey/common/cloud/azure/__init__.py create mode 100644 monkey/common/cloud/azure/azure_instance.py diff --git a/monkey/common/cloud/azure/__init__.py b/monkey/common/cloud/azure/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/common/cloud/azure/azure_instance.py b/monkey/common/cloud/azure/azure_instance.py new file mode 100644 index 000000000..2c949aa2c --- /dev/null +++ b/monkey/common/cloud/azure/azure_instance.py @@ -0,0 +1,27 @@ +import requests + +AZURE_METADATA_SERVICE_URL = "http://169.254.169.254/metadata/instance?api-version=2019-06-04" + + +class AzureInstance(object): + """ + Access to useful information about the current machine if it's an Azure VM. + """ + + def __init__(self): + try: + response = requests.get(AZURE_METADATA_SERVICE_URL, headers={"Metadata": "true"}) + if response: + self.on_azure = True + self.try_parse_response(response) + else: + self.on_azure = False + except ConnectionError: + self.on_azure = False + + def try_parse_response(self, response): + # TODO implement - get fields from metadata like region etc. + pass + + def is_azure_instance(self): + return self.on_azure