我在软层帐户中有一个正在运行的虚拟服务器。但我无法找到我需要传递下面代码的ID。
int serverId = 6558971;
Hardware_API.SoftLayer_Hardware_ServerService hardwareServerService = new Hardware_API.SoftLayer_Hardware_ServerService();
Hardware_API.SoftLayer_Hardware_ServerInitParameters hardwareServerInitParameters = new Hardware_API.SoftLayer_Hardware_ServerInitParameters();
hardwareServerInitParameters.id = serverId;
hardwareServerService.SoftLayer_Hardware_ServerInitParametersValue = hardwareServerInitParameters;
hardwareServerService.authenticateValue = HW_authenticate;
Hardware_API.SoftLayer_Hardware_Server server = hardwareServerService.getObject();
有些身体可以帮助我吗?谢谢!!!
答案 0 :(得分:0)
initParameter是您要使用的对象的ID,在这种情况下您需要服务器的ID,您可以使用SoftLayer_Account::getHardware列出您帐户中的所有服务器,然后您可以选择您想要的服务器的ID,并在您的代码中使用它。
这里使用C sharp
的例子//-----------------------------------------------------------------------
// <copyright file="ListServers.cs" company="Softlayer">
// SoftLayer Technologies, Inc.
// </copyright>
// <license>
// http://sldn.softlayer.com/article/License
// </license>
//-----------------------------------------------------------------------
namespace ListServersNamespace
{
using System;
using System.Collections.Generic;
class ListServers
{
/// <summary>
/// List Bare Metal servers.
/// The script retrieves a list of all bare metal servers in your
/// account. it makes a single call to the Softlayer_Account::getHardware
/// method for more information see below.
/// </summary>
/// <manualPages>
/// https://sldn.softlayer.com/reference/services/SoftLayer_Account
/// https://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
/// https://sldn.softlayer.com/reference/datatype/SoftLayer_Hardware/
/// </manualPages>
static void Main(string[] args)
{
// Your SoftLayer API username.
string username = "set me";
// Your SoftLayer API key.
string apiKey = "set me";
// Creating a connection to the SoftLayer_Account API service and
// bind our API username and key to it.
authenticate authenticate = new authenticate();
authenticate.username = username;
authenticate.apiKey = apiKey;
SoftLayer_AccountService accountService = new SoftLayer_AccountService();
accountService.authenticateValue = authenticate;
try
{
// getHardware will get all bare metal servers that an account has
List<SoftLayer_Hardware> hardawareList = accountService.getHardware().ToList();
foreach (var item in hardawareList)
{
Console.WriteLine("hostname : " + item.hostname); //replace this with item.id to get the id of the servers
}
}
catch (Exception e)
{
Console.WriteLine("unable to list the servers: " + e.Message);
}
}
}
}
此致