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

时间:2012-01-16 11:55:28

标签: cloud rackspace-cloud

如何从服务器本身中找到有关Rackspace Cloud服务器的信息?

亚马逊AWS拥有它,并在此处记录:http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html?r=7479

2 个答案:

答案 0 :(得分:0)

您可以使用Rackspace Cloud Server API:http://www.rackspace.com/cloud/cloud_hosting_products/servers/api/

这里有一个python实现:http://packages.python.org/python-cloudservers/

或命令行工具也非常有用:http://jsquaredconsulting.com/blog/2010/11/rscurl-a-rackspace-cloud-server-command-line-tool/

这是最实用的链接/ \

答案 1 :(得分:0)

从您的应用程序代码中,您可以使用此处描述的技术(对于C#)找到本地服务器自己的外部IP地址:https://stackoverflow.com/a/1069113/12484

然后,一旦获得IP地址,就可以使用Rackspace Cloud API查询所有活动服务器的列表,并获取具有匹配IP地址的服务器的信息。示例代码(C#,使用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;       
    }
}
上述代码中的

USERNAMEAPI_KEYREGION应替换为您自己的Rackspace Cloud帐户的实际值。