简体   繁体   English

如何从自身内部找出Rackspace Cloud服务器信息(ID,IP等)?

[英]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? 如何从服务器本身内部找到有关Rackspace Cloud服务器的信息?

Amazon AWS has it, and its documented here: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html?r=7479 Amazon AWS拥有它,并在此处提供了记录: 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 从您的应用程序代码中,您可以使用类似于此处描述的技术(针对C#)找到本地服务器自己的外部IP地址: 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. 然后,一旦有了IP地址,就可以使用Rackspace Cloud API查询所有活动服务器的列表,并获取具有匹配IP地址的服务器的信息。 Sample code (C#, using the OpenStack.net SDK ): 示例代码(使用OpenStack.net SDK的 C#):

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. 上面代码中的USERNAMEAPI_KEYREGION应该替换为您自己的Rackspace Cloud帐户的实际值。

You could use the Rackspace Cloud Server API: http://www.rackspace.com/cloud/cloud_hosting_products/servers/api/ 您可以使用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/ 这里有一个python实现: 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/ 或命令行工具也确实非常有用: http//jsquaredconsulting.com/blog/2010/11/rscurl-a-rackspace-cloud-server-command-line-tool/

That's the most practical link /\\ 那是最实用的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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