简体   繁体   中英

How to find out Rackspace Cloud server info (id, IP, etc.) from within itself?

How can I find information about a Rackspace Cloud server from within the server itself?

Amazon AWS has it, and its documented here: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html?r=7479

From your application code, you can find the local server's own external IP address using a technique like the one described here (for C#): https://stackoverflow.com/a/1069113/12484

Then, once you have the IP address, you can use the Rackspace Cloud API to query the list of all active servers, and get the information for the server with the matching IP address. Sample code (C#, using the OpenStack.net SDK ):

CloudIdentity cloudIdentity = new CloudIdentity { APIKey = API_KEY, Username = USERNAME };
CloudServersProvider provider = new CloudServersProvider(cloudIdentity);

IEnumerable<Server> servers = provider.ListServersWithDetails(region: REGION);
foreach (Server server in servers)
{
    if (server.AccessIPv4 == ipAddress)
    {
        Console.Out.WriteLine("Server ID:" + server.Id);
        Console.Out.WriteLine("  Flavor: " + server.Flavor.Name);
        Console.Out.WriteLine("  Image: " + server.Image.Name);
        Console.Out.WriteLine("  PowerState: " + server.PowerState.Name);
        Console.Out.WriteLine("  Status: " + server.Status.Name);
        Console.Out.WriteLine("  UserId: " + server.UserId); 
        break;       
    }
}

USERNAME , API_KEY , and REGION in the above code should be replaced by the actual values for your own Rackspace Cloud account.

You could use the Rackspace Cloud Server API: http://www.rackspace.com/cloud/cloud_hosting_products/servers/api/

There's a python implementation here: http://packages.python.org/python-cloudservers/

or the command line tool is really useful too: http://jsquaredconsulting.com/blog/2010/11/rscurl-a-rackspace-cloud-server-command-line-tool/

That's the most practical link /\\

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM