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

Add logic to fetch the latest azure metadata version #1427

Merged
merged 5 commits into from
Mar 3, 2020

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Jan 30, 2020

This is inspired by the way we do this in EC2, but it's different in
many ways since Azure presents the latest version in a different way.

Additional values exposed by this:

      "azEnvironment": "AzurePublicCloud",
      "customData": "",
      "plan": {
        "name": "",
        "product": "",
        "publisher": ""
      },
      "provider": "Microsoft.Compute",
      "publicKeys": [
        {
          "keyData": "ssh-rsa 123",
          "path": "/home/tsmith/.ssh/authorized_keys"
        }
      ],
      "resourceId": "/subscriptions/123/resourceGroups/tsmith/providers/Microsoft.Compute/virtualMachines/timtest",
    "storageProfile": {
        "dataDisks": [

        ],
        "imageReference": {
          "id": "",
          "offer": "UbuntuServer",
          "publisher": "Canonical",
          "sku": "18.04-LTS",
          "version": "latest"
        },
        "osDisk": {
          "caching": "ReadWrite",
          "createOption": "FromImage",
          "diffDiskSettings": {
            "option": ""
          },
          "diskSizeGB": "30",
          "encryptionSettings": {
            "enabled": "false"
          },
          "image": {
            "uri": ""
          },
          "managedDisk": {
            "id": "/subscriptions/123/resourceGroups/tsmith/providers/Microsoft.Compute/disks/timtest_OsDisk_1_f68c8aee869f4668aff1f12e449be5ac",
            "storageAccountType": "Premium_LRS"
          },
          "name": "timtest_OsDisk_1_f68c8aee869f4668aff1f12e449be5ac",
          "osType": "Linux",
          "vhd": {
            "uri": ""
          },
          "writeAcceleratorEnabled": "false"
        }
      },
      "tagsList": [

      ],
      "vmScaleSetName": "",
      "zone": ""

Signed-off-by: Tim Smith tsmith@chef.io

This is inspired by the way we do this in EC2, but it's different in
many ways since Azure presents the latest version in a different way.

Signed-off-by: Tim Smith <tsmith@chef.io>
@tas50 tas50 changed the title WIP: Add logic to fetch the latest azure metadata version Add logic to fetch the latest azure metadata version Mar 2, 2020
From review

Signed-off-by: Tim Smith <tsmith@chef.io>
This way it doesn't blow up if azure changes the response

Signed-off-by: Tim Smith <tsmith@chef.io>
logger.trace("Mixin AzureMetadata: Received HTTP 404 from metadata server while determining API version, assuming #{AZURE_SUPPORTED_VERSIONS.last}")
return AZURE_SUPPORTED_VERSIONS.last
elsif response.code != "400" # 400 is actually what we want
raise "Mixin AzureMetadata: Unable to determine Azure metadata version (returned #{response.code} response)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really unfamiliar with the conventions of this project, but should this return a specific error type rather than the generic error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most places in Ohai are just generic errors

Copy link
Contributor

@phiggins phiggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some code-style suggestions but overall this is good 👍

Updates from review

Signed-off-by: Tim Smith <tsmith@chef.io>
No need for this

Signed-off-by: Tim Smith <tsmith@chef.io>
@tas50 tas50 merged commit 9931325 into master Mar 3, 2020
@chef-expeditor chef-expeditor bot deleted the new_azure_versions branch March 3, 2020 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants