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

发布于 2024-12-27 08:51:24 字数 288 浏览 0 评论 0原文

如何从服务器本身查找有关 Rackspace 云服务器的信息?

亚马逊 AWS 有它,其记录如下: http ://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html?r=7479

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人 2025-01-03 08:51:24

您可以使用 Rackspace 云服务器 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/

这是最实用的链接/\

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 /\

对不⑦ 2025-01-03 08:51:24

从您的应用程序代码中,您可以使用此处描述的技术(对于 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;       
    }
}

USERNAME, 上述代码中的 API_KEYREGION 应替换为您自己的 Rackspace 云帐户的实际值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文