Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.Network


      assert supportsStaticNAT().apply(network);
      assert !supportsPortForwarding().apply(network);
   }

   public void testNoSupport() {
      Network network = Network.builder().id("204")
            .services(ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities(
                  ImmutableMap.<String, String> of()).build())).build();

      assert !hasLoadBalancerService().apply(network);
      assert !supportsStaticNAT().apply(network);
View Full Code Here


      assert !supportsStaticNAT().apply(network);
      assert !supportsPortForwarding().apply(network);
   }

   public void testSupportsPortForwardingFindsWhenFirewallHasPortForwardingFeature() {
      Network network = Network
            .builder()
            .id("204")
            .services(
                  ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities(
                        ImmutableMap.<String, String> of("PortForwarding", "true")).build())).build();
View Full Code Here

      assert !supportsStaticNAT().apply(network);
      assert supportsPortForwarding().apply(network);
   }

   public void testSupportsPortForwardingAndStaticNATWhenFirewallHasFeatures() {
      Network network = Network
            .builder()
            .id("204")
            .services(
                  ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities(
                        ImmutableMap.<String, String> of("StaticNat", "true", "PortForwarding", "true")).build())).build();
View Full Code Here

      assert !hasLoadBalancerService().apply(network);

   }

   public void testDefaultNetworkInZone() {
      Network defaultInZone = Network.builder().id("42-1").isDefault(true).zoneId("42").build();
      Network defaultNotInZone = Network.builder().id("200-1").isDefault(true).zoneId("200").build();
      Network notDefaultInZone = Network.builder().id("42-2").isDefault(false).zoneId("42").build();
      Network notDefaultNotInZone = Network.builder().id("200-2").isDefault(false).zoneId("200").build();

      Predicate<Network> predicate = defaultNetworkInZone("42");
      assertTrue(predicate.apply(defaultInZone));
      assertFalse(predicate.apply(defaultNotInZone));
      assertFalse(predicate.apply(notDefaultInZone));
View Full Code Here

         public boolean apply(Network network) {
            return network != null && network.getState().equals("Implemented");
         }
      });
      assertTrue(Iterables.size(networks) >= 1);
      Network network = Iterables.get(networks, 0);
      assertNotNull(network);

      // Create a VM and stop it
      String defaultTemplate = template != null ? template.getImageId() : null;
      vmForCreation = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network, defaultTemplate, client, jobComplete, virtualMachineRunning);
View Full Code Here

         public boolean apply(Network network) {
            return network != null && network.getName().equals("Virtual Network");
         }
      });
      assertEquals(Iterables.size(networks), 1);
      Network network = Iterables.getOnlyElement(networks, null);
      assertNotNull(network);
      Set<OSType> osTypes = client.getGuestOSApi().listOSTypes();
      OSType osType = Iterables.getFirst(osTypes, null);

      // Register a template
View Full Code Here

   public static VirtualMachine createVirtualMachine(CloudStackApi client, String defaultTemplate,
         Predicate<String> jobComplete, Predicate<VirtualMachine> virtualMachineRunning) {
      Set<Network> networks = client.getNetworkApi().listNetworks(isDefault(true));
      if (networks.size() > 0) {
         Network network = get(filter(networks, new Predicate<Network>() {
            @Override
            public boolean apply(Network network) {
               return network != null && network.getState().equals("Implemented");
            }
         }), 0);
         return createVirtualMachineInNetwork(network,
               defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
               virtualMachineRunning);
      } else {
         String zoneId = find(client.getZoneApi().listZones(), new Predicate<Zone>() {

            @Override
View Full Code Here

   @Test
   public void testCreateVirtualMachineWithSpecificIp() throws Exception {
      skipIfNotGlobalAdmin();

      String defaultTemplate = template != null ? template.getImageId() : null;
      Network network = null;

      try {
         Template template = getOnlyElement(
            client.getTemplateApi().listTemplates(ListTemplatesOptions.Builder.id(defaultTemplate)));
         logger.info("Using template: " + template);

         Set<Network> allSafeNetworksInZone = adminClient.getNetworkApi().listNetworks(
            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);

               Set<VirtualMachine> machinesInNetwork = adminClient.getVirtualMachineApi().listVirtualMachines(
                  ListVirtualMachinesOptions.Builder.networkId(net.getId()));

               for (VirtualMachine machine : machinesInNetwork) {
                  if (machine.getState().equals(VirtualMachine.State.RUNNING)) {
                     logger.info("Deleting VM: " + machine);
                     destroyMachine(machine);
                  }
               }

               assertTrue(adminJobComplete.apply(
                  adminClient.getNetworkApi().deleteNetwork(net.getId())), net.toString());
            }
         }

         NetworkOffering offering = getFirst(
            client.getOfferingApi().listNetworkOfferings(
               ListNetworkOfferingsOptions.Builder.zoneId(template.getZoneId()).specifyVLAN(true)), null);
         checkNotNull(offering, "No network offering found");
         logger.info("Using network offering: " + offering);

         network = adminClient.getNetworkApi().createNetworkInZone(
            template.getZoneId(), offering.getId(), prefix + "-ip-network", "",
            CreateNetworkOptions.Builder.startIP("192.168.0.1").endIP("192.168.0.5")
               .netmask("255.255.255.0").gateway("192.168.0.1").vlan("21"));
         logger.info("Created network: " + network);

         Network requiredNetwork = getOnlyElement(filter(adminClient.getNetworkApi().listNetworks(
            ListNetworksOptions.Builder.zoneId(template.getZoneId())), new Predicate<Network>() {
            @Override
            public boolean apply(Network network) {
               return network.isDefault() &&
                  network.getGuestIPType() == GuestIPType.VIRTUAL;
View Full Code Here

         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).networks(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());
      }
   }
View Full Code Here

         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().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId();

         // create an arbitrary network
         network = domainAdminClient
            .getNetworkClient()
               // 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.getNetworkClient().deleteNetwork(network.getId());
      }
   }
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.domain.Network

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.