Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SoftLayer API:getNasNetworkStorage返回null_Api_Ibm Cloud Infrastructure - Fatal编程技术网

SoftLayer API:getNasNetworkStorage返回null

SoftLayer API:getNasNetworkStorage返回null,api,ibm-cloud-infrastructure,Api,Ibm Cloud Infrastructure,我正在检查以获取NAS存储列表 我测试了两种方法,一种是使用BAP id,另一种是直接帐户id 首先 使用BAP id,获取帐户列表 使用帐户id获取NAS存储列表。 ==>我没有列出NAS存储列表 第二 使用直接帐户id获取NAS存储列表 =>成功获取NAS存储列表 我不明白这两种方法的区别 我附上了第一个测试代码, “getNasNetworkStorageCount”方法返回NAS存储量计数,但“getNasNetworkStorage”返回“null” 公开无效测试(){ St

我正在检查以获取NAS存储列表

我测试了两种方法,一种是使用BAP id,另一种是直接帐户id

  • 首先

  • 使用BAP id,获取帐户列表
  • 使用帐户id获取NAS存储列表。 ==>我没有列出NAS存储列表
  • 第二

  • 使用直接帐户id获取NAS存储列表 =>成功获取NAS存储列表
我不明白这两种方法的区别

我附上了第一个测试代码, “getNasNetworkStorageCount”方法返回NAS存储量计数,但“getNasNetworkStorage”返回“null”


公开无效测试(){

String userId=“ibmxxx”;
字符串apiKey=“xxxxx”;
client=new RestApiClient();
Account.Service accountService=Account.Service(客户端);
List brandList=accountService.getOwnedBrands();
用于(品牌:品牌列表){
Brand.Service brandService=Brand.asService(客户);
Account.Mask Mask=新Account.Mask();
mask.id();
mask.companyName();
mask.accountStatusId();
mask.email();
mask.hardwareCount();
mask.hardware();
mask.virtualGuestCount();
mask.virtualGuests();
mask.nasNetworkStorage();
mask.nasNetworkStorageCount();
brandService.clearMask();
brandService.setMask(mask);
List accountList=accountList=brandService.getOwnedAccounts();
for(帐户:accountList){
if(account.getNasNetworkStorageCount()!=0){
System.out.print(account.getNasNetworkStorageCount()+“=”;
System.out.println(account.getNasNetworkStorage().size());
}                
}
System.out.println(accountList.size());
}
}

您的结果可能是这些,因为当您运行SoftLayer_Brand::getOwnedAccounts方法时,它只返回当前用户(即调用API的用户)的帐户

您可以运行这个Java示例,看到品牌有效地为用户调用者检索正确的帐户,然后检索属于它的所有NAS网络存储

package SoftLayer_Java_Scripts.Examples;

import com.google.gson.Gson;
import com.softlayer.api.*;
import com.softlayer.api.service.Account;
import com.softlayer.api.service.Brand;
import com.softlayer.api.service.network.Storage;
import java.util.List;

public class GetNasNetworkStorage
{
  public static void main( String[] args )
  {
    String user = "set me";
    String apiKey = "set me";

    long brandId = 2L;

    ApiClient client = new RestApiClient().withCredentials(user, apiKey);
    Brand.Service brandService = Brand.service(client, brandId);

    try
    {
      List<Account> accountsList = brandService.getOwnedAccounts();
      Gson gson = new Gson();
      for (Account account : accountsList) {
        Account.Service accountService = account.asService(client);
        List<Storage> nasStorageList = accountService.getNasNetworkStorage();
        for (Storage storage : nasStorageList) {
          System.out.println(gson.toJson(storage));
        }
      }
    }
    catch(Exception e)
    {
      System.out.println("Script failed, review the next message for further details: " + e.getMessage()); 
    }
  }
}
package SoftLayer\u Java\u Scripts.Examples;
导入com.google.gson.gson;
导入com.softlayer.api.*;
导入com.softlayer.api.service.Account;
导入com.softlayer.api.service.Brand;
导入com.softlayer.api.service.network.Storage;
导入java.util.List;
公共类GetNasNetworkStorage
{
公共静态void main(字符串[]args)
{
String user=“设置我”;
String apiKey=“设置我”;
长布兰迪=2L;
ApiClient client=new RestApiClient()。带有凭据(用户,apiKey);
Brand.Service brandService=Brand.Service(客户,brandId);
尝试
{
List accountsList=brandService.getOwnedAccounts();
Gson Gson=新的Gson();
for(帐户:accountsList){
Account.Service accountService=Account.asService(客户端);
List-nasStorageList=accountService.getNasNetworkStorage();
用于(存储:nasStorageList){
System.out.println(gson.toJson(存储));
}
}
}
捕获(例外e)
{
System.out.println(“脚本失败,请查看下一条消息以了解更多详细信息:”+e.getMessage());
}
}
}

您的结果可能是这些,因为当您运行SoftLayer_Brand::getOwnedAccounts方法时,它只返回当前用户(即调用API的用户)的帐户

您可以运行这个Java示例,看到品牌有效地为用户调用者检索正确的帐户,然后检索属于它的所有NAS网络存储

package SoftLayer_Java_Scripts.Examples;

import com.google.gson.Gson;
import com.softlayer.api.*;
import com.softlayer.api.service.Account;
import com.softlayer.api.service.Brand;
import com.softlayer.api.service.network.Storage;
import java.util.List;

public class GetNasNetworkStorage
{
  public static void main( String[] args )
  {
    String user = "set me";
    String apiKey = "set me";

    long brandId = 2L;

    ApiClient client = new RestApiClient().withCredentials(user, apiKey);
    Brand.Service brandService = Brand.service(client, brandId);

    try
    {
      List<Account> accountsList = brandService.getOwnedAccounts();
      Gson gson = new Gson();
      for (Account account : accountsList) {
        Account.Service accountService = account.asService(client);
        List<Storage> nasStorageList = accountService.getNasNetworkStorage();
        for (Storage storage : nasStorageList) {
          System.out.println(gson.toJson(storage));
        }
      }
    }
    catch(Exception e)
    {
      System.out.println("Script failed, review the next message for further details: " + e.getMessage()); 
    }
  }
}
package SoftLayer\u Java\u Scripts.Examples;
导入com.google.gson.gson;
导入com.softlayer.api.*;
导入com.softlayer.api.service.Account;
导入com.softlayer.api.service.Brand;
导入com.softlayer.api.service.network.Storage;
导入java.util.List;
公共类GetNasNetworkStorage
{
公共静态void main(字符串[]args)
{
String user=“设置我”;
String apiKey=“设置我”;
长布兰迪=2L;
ApiClient client=new RestApiClient()。带有凭据(用户,apiKey);
Brand.Service brandService=Brand.Service(客户,brandId);
尝试
{
List accountsList=brandService.getOwnedAccounts();
Gson Gson=新的Gson();
for(帐户:accountsList){
Account.Service accountService=Account.asService(客户端);
List-nasStorageList=accountService.getNasNetworkStorage();
用于(存储:nasStorageList){
System.out.println(gson.toJson(存储));
}
}
}
捕获(例外e)
{
System.out.println(“脚本失败,请查看下一条消息以了解更多详细信息:”+e.getMessage());
}
}
}

区别在于,品牌服务是管理品牌账户,而直接使用账户服务是管理有关特定账户的所有信息

目前,您使用的对象掩码可能存在问题,但使用品牌服务的问题在于,该服务仅用于显示属于该品牌的所有帐户的基本信息,而不是用于显示相关帐户的所有信息(即使您使用对象掩码)。我将向softlayer报告对象掩码的问题,我指的是与nasNetworkStorage返回null相关的问题,但我已经报告了类似的问题,并且他们没有修复它,因为正如我告诉您的,这不是该服务的主要用途

您还可以尝试将对象掩码设置为一个字符串,这可能会起作用,例如

brandService.setMask("mask[id,companyName,accountStatusId,email,hardwareCount,hardware,virtualGuestCount,VirtualGuest,nasNetworkStorage,nasNetworkStorageCount]");
无论如何,获取与品牌相关的账户信息最可靠的方法是使用每个账户的主用户,我的意思是使用账户服务;即使是softlayer代理门户也使用主帐户来获取有关particu的更多信息