Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ec2metadata equivalent for Azure virtual machines

Tags:

cloud

azure

Is there something similar to ec2metadata in Azure virtual machines?

I need to extract data like the the public hostname or the instance id. In Amazon EC2 instances, I can do this:

$ ec2metadata --instance-id
i-3a1dcfa3
$ ec2metadata --public-hostname
ec2-54-91-124-63.compute-1.amazonaws.com
like image 798
Ayose Avatar asked Jan 16 '15 14:01

Ayose


People also ask

Which service is the same as Azure VM or is an equivalent to it?

Azure Functions is the primary equivalent of AWS Lambda in providing serverless, on-demand code. AWS Lambda functionality also overlaps with Azure WebJobs, which let you schedule or continuously run background tasks.

Does Azure have Linux VMs?

Azure supports common Linux distributions including Red Hat, SUSE, Ubuntu, CentOS, Debian, Oracle Linux, and Flatcar Linux. Create your own Linux virtual machines (VMs), deploy and run containers in Kubernetes, or choose from hundreds of pre-configured images and Linux workloads available in Azure Marketplace.

What virtualization software does Azure use?

The Azure hypervisor system is based on Windows Hyper-V.


1 Answers

It seems this question was asked a long time ago, so maybe you already found the answer. If not, though, then have you tried Azure Instance Metadata? (https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-instancemetadataservice-overview) You can do an http request like this:

curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"

The response looks like this:

{
  "compute": {
    "location": "westcentralus",
    "name": "IMDSSample",
    "offer": "UbuntuServer",
    "osType": "Linux",
    "platformFaultDomain": "0",
    "platformUpdateDomain": "0",
    "publisher": "Canonical",
    "sku": "16.04.0-LTS",
    "version": "16.04.201610200",
    "vmId": "5d33a910-a7a0-4443-9f01-6a807801b29b",
    "vmSize": "Standard_A1"
  },
  "network": {
    "interface": [
      {
        "ipv4": {
          "ipAddress": [
            {
              "privateIpAddress": "10.1.0.4",
              "publicIpAddress": "X.X.X.X"
            }
          ],
          "subnet": [
            {
              "address": "10.1.0.0",
              "prefix": "24"
            }
          ]
        },
        "ipv6": {
          "ipAddress": []
        },
        "macAddress": "000D3AF806EC"
      }
    ]
  }
}

Hope this helps! :)

like image 119
Neil Sant Gat Avatar answered Oct 01 '22 06:10

Neil Sant Gat