PSS
PSS

Reputation: 51

How to set some unique identifier to each Windows Azure Virtual Machine operating system

I have some Virtual machine running with same configuration. On those VMs I have installed my application.

I want to set some custom unique identifier in my VM , so that I know that if particular (from my application) request is coming from which VM that request is coming(or that application is running in which VM). As same application is running inside all VM, so to differentiate each request , I want to setup some unique custom identifier at the time of creation of Virtual machine.

I want to setup some system properties/Environment variable at the time of creation of virtual machine.

I am using Windows Azure Rest API and Java to create and manage Virtual machine on Windows Azure Portal. I want to achieve this by using Java programing language.

Please let me know if you have nay information about same.

Upvotes: 2

Views: 985

Answers (2)

Sandrino Di Mattia
Sandrino Di Mattia

Reputation: 24895

Each instance should have a different SID because the machines are sysprepped with the generalize option (the same applies when you want to provide a custom image). You can get the SID using the code in this question, and use that as identifier:

        string domainName;
        Helper.SID_NAME_USE accountType;
        SecurityIdentifier machineSID = 
                Helper.LookupAccountName("", Environment.MachineName, out domainName, out accountType);

Note: even though it says domainName in the code, your machine doesn't need to be in a domain for this to work.

To set a "custom identifier" on your VM you can use environment variables. Since you're using Java the easiest way to set these is probably the setx.exe command line tool (download). You can call the tool like this:

setx.exe VmIdentifier 123 -m

Then you should be able to read it using System:

System.getenv("VmIdentifier")

It's not really clear to me if you're using Virtual Machines (IaaS) or Cloud Services (PaaS). If you're using Virtual Machines, it will be up to you to deploy the application, and while doing so, you can also execute setx.exe.

Now, if you're using Cloud Services, you actually upload a package which gets deployed on your instances. And you get support for startup tasks (which run before your application starts): How to Define Startup Tasks for a Role. You can use a startup tasks to run setx.exe, but make sure you run it with executionContext set to elevated .

Upvotes: 2

Jude Fisher
Jude Fisher

Reputation: 11294

You can connect to your VM with remote desktop services, so it should be trivial to connect and add a setting to your application's web.config file which identifies the deployment, or, if you want your web.config files to be identical, then you could upload a small text file.

Alternatively, your server must already have a unique name. I assume you're running a .Net application? If so then you should be able to use Server.MachineName (http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.machinename%28v=vs.71%29.aspx) to get the unique name of the box your code is running on.

Upvotes: 0

Related Questions