-
Notifications
You must be signed in to change notification settings - Fork 26
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
Comments
This can be a bit confusing at first. The current implementation of makes this mask work only for 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. |
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. |
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. |
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 |
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? |
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. |
@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()
);
} |
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);
The text was updated successfully, but these errors were encountered: