HyungJun
HyungJun

Reputation: 21

SoftLayer API : getNasNetworkStorage return null

I am checking to get NAS storage list.

I tested 2 ways, one ways is using BAP id, another way is direct account id

I don't Understand difference between ways.

i attached first test code, "getNasNetworkStorageCount" method returned NAS stroage count, but "getNasNetworkStorage" return "null".


public void test() {

    String userId = "IBMxxxxx";
    String apiKey = "xxxxx";

    client = new RestApiClient().withCredentials(userId, apiKey).withLoggingEnabled();

    Account.Service accountService = Account.service(client);
    List<Brand> brandList = accountService.getOwnedBrands();

    for (Brand brand : brandList) {

        Brand.Service brandService = brand.asService(client);

        Account.Mask mask = new 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<Account> accountList = accountList = brandService.getOwnedAccounts();

        for (Account account : accountList) {
            if(account.getNasNetworkStorageCount() != 0){
                System.out.print(account.getNasNetworkStorageCount() + " == ");
                System.out.println(account.getNasNetworkStorage().size());

            }                
        }
        System.out.println(accountList.size());
    }

}

Upvotes: 1

Views: 73

Answers (2)

The difference is that the Brand service is to manage brand accounts whilts using directly the account service is to manage all the information about a particular account.

Currently it may be an issue with the object mask that you are using, however the problem of use the Brand service is that this service was designed only to display the basic information of the all accounts which belong to the brand it was not designed to display all the information of the related accounts (even if you use object masks). I am going to report the issue of the object mask to softlayer, I mean the one related that the nasNetworkStorage returns null, but I already reported similar issues and they were not fix it, because as I told you that is not the propuse of the service.

You also can try setting the object mask as a string maybe that works e.g.

brandService.setMask("mask[id,companyName,accountStatusId,email,hardwareCount,hardware,virtualGuestCount,VirtualGuest,nasNetworkStorage,nasNetworkStorageCount]");

Anyway the most reliable way to get that information of your accounts associated to the brand is using the master user of each accout, I mean using the account service; even the softlayer agent portal uses the master account to get more information of a particular account in your brand.

Let me know if you have more questions

Regards

Upvotes: 0

Your results might be those because when you run the SoftLayer_Brand::getOwnedAccounts method it only returns the account for the current user (i.e. the user that’s calling the API)

You can run this Java example and see that effectively the brand retrieves the right account for the user caller, and then all NAS Network Storages that belong to it.

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

Upvotes: 0

Related Questions