Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Showing VLANs not working #18

Closed
critix opened this issue Mar 31, 2015 · 7 comments
Closed

[Question] Showing VLANs not working #18

critix opened this issue Mar 31, 2015 · 7 comments
Assignees
Labels

Comments

@critix
Copy link

critix commented Mar 31, 2015

Hi

I tried to print all the public VLANs with the code which is provided on this git. Unfortunately this didn't work for me. I checked the softlayer portal and my account has private and public VLANs. I am able to print the private VLANs/virtual machine. Can someone help me out printing the public VLANs as well.

Here is my code which is able to print the private VLANs but unable to print the public VLANs:

import com.softlayer.api.service.network.Vlan;

service.withMask().virtualGuests().networkVlans().primaryRouter().datacenter().longName();

printvm(client, account);

public static void printVm(ApiClient client, Account account) {
    System.out.format("\n%d virtual servers\n", account.getVirtualGuests()
            .size());
    for (Guest guest : account.getVirtualGuests()) {
        System.out
                .format("Host: %s, IP: %s (%s),Cores: %s,Status %s, OS: %s, vlan %s, public vlan %s\n",
                        guest.getFullyQualifiedDomainName(), guest
                                .getPrimaryIpAddress(), guest
                                .getPrimaryBackendIpAddress(), guest
                                .getStartCpus(), guest.getPowerState()
                                .getName(), guest
                                .getOperatingSystemReferenceCode(), guest
                                .getNetworkComponents().get(0)
                                .getNetworkVlan().getName(), guest.getNetworkVlans().get(0).getPrimaryRouter().getDatacenter().getLongName());
    }
}
@cretz cretz added the question label Mar 31, 2015
@cretz cretz self-assigned this Mar 31, 2015
@cretz
Copy link
Contributor

cretz commented Mar 31, 2015

This can be a bit confusing at first. The current implementation of makes this mask work only for getObject, not for getVirtualGuests. I have opened issue #19 to address this. In the meantime, here is how to fetch this info with getObject:

ApiClient client = new RestApiClient(url).withCredentials(user, apikey).
        withLoggingEnabled();
Account.Service service = Account.service(client);
service.withMask().virtualGuests().networkVlans().primarySubnet().addressSpace();
for (Guest guest : service.getObject().getVirtualGuests()) {
    String publicVlanName = null;
    for (Vlan vlan : guest.getNetworkVlans()) {
        if (vlan.getPrimarySubnet() != null
                && "PUBLIC".equals(vlan.getPrimarySubnet().getAddressSpace())) {
            publicVlanName = vlan.getPrimarySubnet().getNetworkIdentifier() +
                    "/" + vlan.getPrimarySubnet().getCidr();
            if (vlan.getName() != null) {
                publicVlanName += " (" + vlan.getName() + ')';
            }
            break;
        }
    }
    System.out.format("Server: %s, Vlan name: %s\n",
            guest.getFullyQualifiedDomainName(), publicVlanName);
}

Does this help? Also remember these questions can also be asked in the forum at https://forums.softlayer.com/forum/softlayer-developer-network instead of as GitHub issues on the project.

@critix
Copy link
Author

critix commented Apr 1, 2015

Hi, ty for the code. Unfortunatly I get "null" back on every machine. While the machines have a vlan attached. I don't know what's wrong.

@cretz
Copy link
Contributor

cretz commented Apr 1, 2015

Not sure which part is null, the virtual machine, the primary subnet, the VLAN name, etc. Can you open an internal ticket with SoftLayer since this may be specific to your account? Also make sure the user you are has full privileges. I am closing this GitHub issue in favor of the internal ticket since this is not something happening with the Java client specifically.

@cretz cretz closed this as completed Apr 1, 2015
@critix
Copy link
Author

critix commented Apr 2, 2015

I get the virtual machines in a list. but the vlans stay on 'null'. I can't find a way to get this list. I also tried to create subnets but I have to get the right priceid first and I can't figure it all out at all. the whole networking part is a bit confusing to me

@cretz
Copy link
Contributor

cretz commented Apr 2, 2015

By using the code sample I provided, the VLANs do appear normally. This may be due to something specific with your code or the API account. Can you please open an internal ticket with SoftLayer to investigate?

@critix
Copy link
Author

critix commented Apr 3, 2015

I made a ticket with Softlayer and they said that this is right. I got more access to my account but the value is still 'null'. I even tried another softlayer account with full access.

@MiguelHigorre
Copy link

@critix , try updating your code as follow

ApiClient client = new RestApiClient().withCredentials(apiUsername, apiKey);
Account.Service service = Account.service(client);

// Use the following masks to retrieve the information of the virtual instance
service.withMask().virtualGuests().networkVlans().primarySubnet().addressSpace();
service.withMask().virtualGuests().powerState();
service.withMask().virtualGuests().operatingSystemReferenceCode();
service.withMask().virtualGuests().networkComponents().networkVlan();
service.withMask().virtualGuests().networkVlans().primaryRouter().datacenter();

System.out.format("\n%d virtual servers\n", service.getObject().getVirtualGuests().size());
for (Guest guest : service.getObject().getVirtualGuests()) {
    System.out.format("Host: %s, IP: %s (%s),Cores: %s,Status %s, OS: %s, vlan %s, public vlan %s\n",
        guest.getFullyQualifiedDomainName(), 
        guest.getPrimaryIpAddress(), 
        guest.getPrimaryBackendIpAddress(), 
        guest.getStartCpus(), 
        guest.getPowerState().getName(), 
        guest.getOperatingSystemReferenceCode(),
               //Use vlanNumber property since name property is optional 
        guest.getNetworkComponents().get(0).getNetworkVlan().getVlanNumber(),
        guest.getNetworkVlans().get(0).getPrimaryRouter().getDatacenter().getLongName()
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants