2017-02-23 8 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を使用してアカウントのすべてのサーバーを一覧表示し、そのIDを選択できます。あなたが望むコードをあなたのコードで使ってください。ここで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); 
      } 
     } 
    } 
} 

よろしくを用いた例

関連する問題