2017-02-23 92 views
0

我有一个运行在软层帐户的虚拟服务器。但我无法找到我需要传递下面的代码的ID。我在哪里可以得到在SoftLayer_Hardware_ServerInitParameters中传递的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

initParameter是您要使用的对象的ID,在这种情况下您需要服务器的ID,您可以使用SoftLayer_Account::getHardware列出您的帐户中的所有服务器,然后您可以选择服务器,你想要在代码中使用它。

这里用C尖锐

//----------------------------------------------------------------------- 
// <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); 
      } 
     } 
    } 
} 

问候示例

相关问题