@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { if (execution.getVariable(ProcessVariables.NETWORK_ID) != null) { LOG.warn("Network process variable ({}) will be overwritten!", ProcessVariables.NETWORK_ID); } Network network; final String existingNetwork = pool.getNetwork().getOption(NetworkOptions.EXISTING_NETWORK_ID); if (existingNetwork != null) { network = checkNotNull(cloudStackClient.getNetworkClient().getNetwork(existingNetwork), "Network with id " + existingNetwork + " does not exist"); } else { final String networkName = Networks.formatNameFromBusinessKey(execution.getProcessBusinessKey()); final String zoneId = pool.getProvider().getOption(ProviderOptions.ZONE_ID); final String networkOfferingId = pool.getProvider().getOption(ProviderOptions.NETWORK_OFFERING_ID); try { network = Networks.getByName(cloudStackClient, networkName); LOG.info("Network with name {} exists.", networkName); } catch (NoSuchElementException e) { LOG.info(String.format("Creating network %s in zone %s with offering %s", networkName, zoneId, networkOfferingId)); network = cloudStackClient.getNetworkClient().createNetworkInZone(zoneId, networkOfferingId, networkName, networkName, CreateNetworkOptions.NONE); } } LOG.info("Storing network id {} in process variable {}", network.getId(), ProcessVariables.NETWORK_ID); execution.setVariable(ProcessVariables.NETWORK_ID, network.getId()); } }
@Test public void testCreateGuestVirtualNetwork() { if (!networksSupported) return; final NetworkOffering offering; try { offering = find(client.getOfferingClient().listNetworkOfferings(), NetworkOfferingPredicates.supportsGuestVirtualNetworks()); } catch (NoSuchElementException e) { Logger.getAnonymousLogger().log(Level.SEVERE, "guest networks not supported, skipping test"); return; } String name = prefix + "-virtual"; Network network = null; try { network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), name, name); checkNetwork(network); } catch (IllegalStateException e) { Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e); } finally { if (network != null) { String jobId = client.getNetworkClient().deleteNetwork(network.getId()); if (jobId != null) jobComplete.apply(jobId); } } }
.getNetworkClient() .createNetworkInZone(zone.getId(), offering.getId(), name, name, vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1")); checkNetwork(network);
.getNetworkClient() .createNetworkInZone(zoneId, offeringId, group, group, vlan(vlanId).startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
logger.info("Using network offering: " + offering); network = adminClient.getNetworkClient().createNetworkInZone( template.getZoneId(), offering.getId(), prefix + "-ip-network", "", CreateNetworkOptions.Builder.startIP("192.168.0.1").endIP("192.168.0.5")
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), "net-" + prefix, "jclouds test " + prefix); usingExistingNetwork = false;