public T fromNetwork(Network in) { return this .id(in.getId()) .account(in.getAccount()) .broadcastDomainType(in.getBroadcastDomainType()) .broadcastURI(in.getBroadcastURI()) .displayText(in.getDisplayText()) .DNS(in.getDNS()) .domain(in.getDomain()) .domainId(in.getDomainId()) .endIP(in.getEndIP()) .gateway(in.getGateway()) .isDefault(in.isDefault()) .isShared(in.isShared()) .isSystem(in.isSystem()) .netmask(in.getNetmask()) .networkDomain(in.getNetworkDomain()) .networkOfferingAvailability(in.getNetworkOfferingAvailability()) .networkOfferingDisplayText(in.getNetworkOfferingDisplayText()) .networkOfferingId(in.getNetworkOfferingId()) .networkOfferingName(in.getNetworkOfferingName()) .related(in.getRelated()) .startIP(in.getStartIP()) .name(in.getName()) .state(in.getState()) .guestIPType(in.getGuestIPType()) .VLAN(in.getVLAN()) .trafficType(in.getTrafficType()) .zoneId(in.getZoneId()) .tags(in.getTags())
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
@Override public boolean apply(Network network) { return network.isDefault() && !network.isSecurityGroupEnabled() && !network.isSystem() && network.getAccount().equals(user.getName()); } }));
private void checkNetwork(Network network) { assert network.getId() != null : network; assert network.getName() != null : network; assert network.getDNS().size() != 0 : network; assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network; assert network.getBroadcastDomainType() != null : network; assert network.getDisplayText() != null : network; assert network.getNetworkOfferingAvailability() != null : network; assert network.getNetworkOfferingDisplayText() != null : network; assert network.getNetworkOfferingId() != null : network; assert network.getNetworkOfferingName() != null : network; assert network.getRelated() != null : network; assert network.getServices().size() != 0 : network; assert network.getState() != null : network; assert network.getTrafficType() != null : network; assert network.getZoneId() != null : network; assert network.getDomain() != null : network; switch (network.getGuestIPType()) { case VIRTUAL: assert network.getNetmask() == null : network; assert network.getGateway() == null : network; assert network.getVLAN() == null : network; assert network.getStartIP() == null : network; assert network.getEndIP() == null : network; break; case DIRECT: assert network.getNetmask() != null : network; assert network.getGateway() != null : network;
@Override public String apply(Network arg0) { return arg0.getId(); } });
ListNetworksOptions.Builder.zoneId(template.getZoneId()).isSystem(false)); for(Network net : allSafeNetworksInZone) { if(net.getName().equals(prefix + "-ip-network")) { logger.info("Deleting VMs in network: " + net); ListVirtualMachinesOptions.Builder.networkId(net.getId())); adminClient.getNetworkClient().deleteNetwork(net.getId())), net.toString()); ipsToNetworks.put(ipAddress, network.getId()); if (nic.getNetworkId() == network.getId()) { hasStaticIpNic = true; assertEquals(nic.getIPAddress(), ipAddress); String jobId = adminClient.getNetworkClient().deleteNetwork(network.getId()); adminJobComplete.apply(jobId); network = null;
@Override public boolean apply(Network network) { return network.isDefault() && !network.isSecurityGroupEnabled() && network.getAccount().equals(user.getAccount()); } }));
@Test public void testAdvancedWhenNoNetworkEligible() { AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); Network unsuitableNetwork = Network.builder() .id("25").zoneId(ZONE_ID) .build(); boolean exceptionThrown = false; try { converter.apply(CloudStackTemplateOptions.NONE, ImmutableMap.of(unsuitableNetwork.getId(), unsuitableNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE); } catch(IllegalArgumentException e) { exceptionThrown = true; } assertTrue(exceptionThrown); } }
for (Network nwi : nws) { try { if (nwi.getName().matches(regex)) { LOG.debug("deleting " + nwi); String job = client.getNetworkClient().deleteNetwork(nwi.getId()); LOG.debug("deleting " + nwi + " - job " + job); if (job != null) jobs.add(job); nws = client.getNetworkClient().listNetworks(); for (Network nw : nws) { match |= nw.getName().matches(regex);
String displayText = name+" subnet"; Network network = client.getNetworkClient().createNetworkInZone(zoneId, nwOfferingId, name, displayText, options); String networkId = network.getId(); if (subnetCidr == null) { subnetCidr = new Cidr(network.getGateway()+"/"+24);
protected void deleteNetworksInZoneWithVlanId(String zoneId, String vlanId) { Set<Network> networks = domainAdminClient.getNetworkClient().listNetworks( ListNetworksOptions.Builder .isDefault(false) .isSystem(false) .zoneId(zoneId) .trafficType(TrafficType.GUEST) ); // Warning: the vlan id is not set in the response - using an workaround URI broadcastUri = URI.create("vlan://" + vlanId); for (Network net : networks) { if (broadcastUri.equals(net.getBroadcastURI())) { String jobId = domainAdminClient.getNetworkClient().deleteNetwork(net.getId()); adminJobComplete.apply(jobId); } } }
@Override public boolean apply(Network input) { return input.getName().equals(networkName); } });
public Network findPrivateNetwork(String accountName, String domainId) { // note: listNetworks includes networks with "null" account Set<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.accountInDomain(accountName, domainId).isShared(false)); for (Network network : networks) { if (accountName.equals(network.getAccount())) { LOG.debug("Found private network in {} for account {} in domain {}: {}", new Object[] {loc, accountName, domainId, network}); return network; } } LOG.debug("No private network found in {} for account {} in domain {}: contenders {}", new Object[] {loc, accountName, domainId, networks}); return null; }
private void checkNetwork(Network network) { assert network.getId() != null : network; assert network.getName() != null : network; assert network.getDNS().size() != 0 : network; assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network; assert network.getBroadcastDomainType() != null : network; assert network.getDisplayText() != null : network; assert network.getNetworkOfferingAvailability() != null : network; assert network.getNetworkOfferingDisplayText() != null : network; assert network.getNetworkOfferingId() != null : network; assert network.getNetworkOfferingName() != null : network; assert network.getRelated() != null : network; assert network.getServices().size() != 0 : network; assert network.getState() != null : network; assert network.getTrafficType() != null : network; assert network.getZoneId() != null : network; assert network.getDomain() != null : network; switch (network.getGuestIPType()) { case VIRTUAL: assert network.getNetmask() == null : network; assert network.getGateway() == null : network; assert network.getVLAN() == null : network; assert network.getStartIP() == null : network; assert network.getEndIP() == null : network; break; case DIRECT: assert network.getNetmask() != null : network; assert network.getGateway() != null : network;
@Override public String apply(Network arg0) { return arg0.getId(); } });
@Override public boolean apply(Network network) { return network.isDefault() && !network.isSecurityGroupEnabled() && !network.isSystem() && network.getAccount().equals(user.getName()); } }));
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackApi client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressApi().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
ListNetworksOptions.Builder.zoneId(template.getZoneId()).isSystem(false)); for (Network net : allSafeNetworksInZone) { if (net.getName().equals(prefix + "-ip-network")) { logger.info("Deleting VMs in network: " + net); ListVirtualMachinesOptions.Builder.networkId(net.getId())); adminClient.getNetworkApi().deleteNetwork(net.getId())), net.toString()); ipsToNetworks.put(ipAddress, network.getId()); if (Objects.equal(nic.getNetworkId(), network.getId())) { hasStaticIpNic = true; assertEquals(nic.getIPAddress(), ipAddress); String jobId = adminClient.getNetworkApi().deleteNetwork(network.getId()); adminJobComplete.apply(jobId); network = null;
@Override public boolean apply(Network network) { return network.isDefault() && !network.isSecurityGroupEnabled() && network.getAccount().equals(user.getAccount()); } }));
@Test public void testAdvancedAutoDetectNetwork() { AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); Network eligibleNetwork = Network.builder() .id("25").zoneId(ZONE_ID).isDefault(true).services(ImmutableSet.of(firewallServiceWithStaticNat)) .build(); DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.NONE, ImmutableMap.of(eligibleNetwork.getId(), eligibleNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE); DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("25"); assertEquals(optionsActual, optionsExpected); }