Common: Fix aws_instance.py formatting

This commit is contained in:
vakarisz 2022-04-28 11:48:06 +03:00
parent 946c394c74
commit f63bc77df0
1 changed files with 14 additions and 16 deletions

View File

@ -2,7 +2,7 @@ import json
import logging import logging
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import Tuple, Optional from typing import Optional, Tuple
import requests import requests
@ -29,6 +29,7 @@ class AwsInstance(CloudInstance):
""" """
Class which gives useful information about the current instance you're on. Class which gives useful information about the current instance you're on.
""" """
__metaclass__ = Singleton __metaclass__ = Singleton
def __init__(self): def __init__(self):
@ -45,20 +46,19 @@ class AwsInstance(CloudInstance):
def _fetch_instance_info() -> Tuple[bool, AwsInstanceInfo]: def _fetch_instance_info() -> Tuple[bool, AwsInstanceInfo]:
try: try:
response = requests.get( response = requests.get(
AWS_LATEST_METADATA_URI_PREFIX + "meta-data/instance-id", AWS_LATEST_METADATA_URI_PREFIX + "meta-data/instance-id",
timeout=AWS_TIMEOUT, timeout=AWS_TIMEOUT,
) )
if not response: if not response:
return False, AwsInstanceInfo() return False, AwsInstanceInfo()
info = AwsInstanceInfo() info = AwsInstanceInfo()
info.instance_id = response.text if response else False info.instance_id = response.text if response else False
info.region = AwsInstance._parse_region( info.region = AwsInstance._parse_region(
requests.get( requests.get(
AWS_LATEST_METADATA_URI_PREFIX + AWS_LATEST_METADATA_URI_PREFIX + "meta-data/placement/availability-zone",
"meta-data/placement/availability-zone", timeout=AWS_TIMEOUT,
timeout=AWS_TIMEOUT, ).text
).text
) )
except (requests.RequestException, IOError) as e: except (requests.RequestException, IOError) as e:
logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e)) logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e))
@ -66,16 +66,14 @@ class AwsInstance(CloudInstance):
try: try:
info.account_id = AwsInstance._extract_account_id( info.account_id = AwsInstance._extract_account_id(
requests.get( requests.get(
AWS_LATEST_METADATA_URI_PREFIX + AWS_LATEST_METADATA_URI_PREFIX + "dynamic/instance-identity/document",
"dynamic/instance-identity/document", timeout=AWS_TIMEOUT,
timeout=AWS_TIMEOUT, ).text
).text
) )
except (requests.RequestException, json.decoder.JSONDecodeError, IOError) as e: except (requests.RequestException, json.decoder.JSONDecodeError, IOError) as e:
logger.debug( logger.debug(
"Failed init of AwsInstance while getting dynamic instance data: {}".format( "Failed init of AwsInstance while getting dynamic instance data: {}".format(e)
e)
) )
return False, AwsInstanceInfo() return False, AwsInstanceInfo()