Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jhnidek/1.28 cct 384 more azure facts #3393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloud_what/providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AzureCloudProvider(BaseCloudProvider):
# for very long time. It would be good to update the version from time to time,
# because old versions (three years) are deprecated. It would be good to update
# the API version with every minor version of RHEL
API_VERSION = "2021-02-01"
API_VERSION = "2023-07-01"

BASE_CLOUD_PROVIDER_METADATA_URL = "http://169.254.169.254/metadata/instance?api-version="

Expand Down
10 changes: 9 additions & 1 deletion src/rhsmlib/facts/cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ def get_aws_facts(self):

def get_azure_facts(self):
"""
Try to get facts of VM running on Azure public cloud. Returned dictionary has following format:
Try to get facts of VM running on Azure public cloud. Returned dictionary has the following format:
{
"azure_instance_id": some_instance_ID,
"azure_offer": some_offer,
"azure_sku": some_sku,
"azure_subscription_id": some_subscription_ID
"azure_location: azure region the VM is running in
}
:return: dictionary containing Azure facts, when the machine is able to gather metadata
from Azure cloud provider; otherwise returns empty dictionary {}
Expand All @@ -131,6 +132,13 @@ def get_azure_facts(self):
facts['azure_offer'] = values['compute']['offer']
if "subscriptionId" in values["compute"]:
facts["azure_subscription_id"] = values["compute"]["subscriptionId"]
if "location" in values["compute"]:
facts["azure_location"] = values["compute"]["location"]
if "extendedLocation" in values["compute"]:
if "name" in values["compute"]["extendedLocation"]:
facts["azure_extended_location_name"] = values["compute"]["extendedLocation"]["name"]
if "type" in values["compute"]["extendedLocation"]:
facts["azure_extended_location_type"] = values["compute"]["extendedLocation"]["type"]
return facts

def get_gcp_facts(self):
Expand Down
16 changes: 16 additions & 0 deletions test/rhsmlib_test/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
{
"compute": {
"azEnvironment": "AzurePublicCloud",
"extendedLocation": {
"type": "edgeZone",
"name": "microsoftlondon"
},
"customData": "",
"location": "westeurope",
"name": "foo-bar",
Expand Down Expand Up @@ -154,6 +158,12 @@
AZURE_SKU = "8.1-ci"
AZURE_OFFER = "RHEL"
AZURE_SUBSCRIPTION_ID = "01234567-0123-0123-0123-012345679abc"
# There is no list of valid values of locations, extended locations and
# types of extended locations. Value "microsoftlondon" probably does not
# exist at all, and it was added only for testing purpose.
AZURE_LOCATION = "westeurope"
AZURE_EXTENDED_LOCATION_NAME = "microsoftlondon"
AZURE_EXTENDED_LOCATION_TYPE = "edgeZone"


def mock_prepare_request(request):
Expand Down Expand Up @@ -303,6 +313,12 @@ def test_get_azure_facts(self):
self.assertEqual(facts["azure_offer"], AZURE_OFFER)
self.assertIn("azure_subscription_id", facts)
self.assertEqual(facts["azure_subscription_id"], AZURE_SUBSCRIPTION_ID)
self.assertIn("azure_location", facts)
self.assertEqual(facts["azure_location"], AZURE_LOCATION)
self.assertIn("azure_extended_location_name", facts)
self.assertEqual(facts["azure_extended_location_name"], AZURE_EXTENDED_LOCATION_NAME)
self.assertIn("azure_extended_location_type", facts)
self.assertEqual(facts["azure_extended_location_type"], AZURE_EXTENDED_LOCATION_TYPE)

@patch('cloud_what.providers.gcp.GCPCloudProvider._write_token_to_cache_file')
@patch('cloud_what.providers.gcp.GCPCloudProvider._get_metadata_from_cache')
Expand Down
Loading