0

I created VM Scale Set using

az vmss create -n XXX -g XXX --image XXX --public-ip-per-vm --vm-domain-name myvmss --vm-sku Standard_B1s --instance-count 1 --admin-password XXX --admin-username XXX--authentication-type password

And then I am able to ssh into that VM using a link from azure portal.

Now I need to configure it and for that I need to know what public DNS record was assigned to VM. How can I do it?

I plan to run the configuration of the VMs using "Custom Script For Linux" extension.

hostname returns the computer name of the VM (e.g. mkvmsa524000001) and I need to have the full DNS name of the public IP, e.g. vm1.myvmss.westeurope.cloudapp.azure.com (myvmss there is the vm-domain-name arg from the command above).

If it helps - I am using Linux based image.

I can get the public IP address of the instance using

curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text"

But how to get its name, e.g. vm-01? I could add the suffix manually then

JoeBloggs
  • 89
  • 7

1 Answers1

-1

Found an option based on this post - https://msftstack.wordpress.com/2017/05/10/figuring-out-azure-vm-scale-set-machine-names/

From the hostname of the VM it is possible to get the index of it in the Scale Set:

def hostname_to_vmid(hostname):
    # get last 6 characters and remove leading zeroes
    hexatrig = hostname[-6:].lstrip('0')
    multiplier = 1
    vmid = 0
    # reverse string and process each char
    for x in hexatrig[::-1]:
        if x.isdigit():
            vmid += int(x) * multiplier
        else:
            # convert letter to corresponding integer
            vmid += (ord(x) - 55) * multiplier
        multiplier *= 36
    return vmid

Host name can be found using $(hostname) and then build DNS name as

vm{index}.{vm-domain-name}.{region}.cloudapp.azure.com
JoeBloggs
  • 89
  • 7