return;
}
String group = prefix + "-vlan";
String vlanId = "2";
Network network = null;
Set<? extends NodeMetadata> nodes = null;
try {
assert view.getComputeService().listAssignableLocations().size() > 0;
Template template = view.getComputeService().templateBuilder().build();
// get the zone we are launching into
String zoneId = template.getLocation().getId();
// cleanup before running the test
deleteNetworksInZoneWithVlanId(zoneId, vlanId);
// find a network offering that supports vlans in our zone
String offeringId = get(
cloudStackContext.getApi().getOfferingApi().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId();
// create an arbitrary network
network = domainAdminClient
.getNetworkApi()
// startIP/endIP/netmask/gateway must be specified together
.createNetworkInZone(zoneId, offeringId, group, group,
vlan(vlanId).startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
// set options to specify this network id
template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId());
// launch the VM
nodes = view.getComputeService().createNodesInGroup(group, 1, template);
assert nodes.size() > 0;
} catch (RunNodesException e) {
Logger.getAnonymousLogger().log(Level.SEVERE, "error creating nodes", e);
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
} finally {
if (nodes != null)
view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
if (network != null)
domainAdminClient.getNetworkApi().deleteNetwork(network.getId());
}
}