Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.Zone


      }
   }

   @Test(enabled = true)
   public void testCreateTemplate() throws Exception {
      Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
      assertNotNull(zone);
      Iterable<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
      networks = Iterables.filter(networks, new Predicate<Network>() {
         @Override
         public boolean apply(Network network) {
            return network != null && network.getState().equals("Implemented");
         }
View Full Code Here


      assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri);
   }

   @Test(enabled = true)
   public void testRegisterTemplate() throws Exception {
      Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
      assertNotNull(zone);
      Iterable<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
      networks = Iterables.filter(networks, new Predicate<Network>() {
         @Override
         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.getGuestOSClient().listOSTypes();
      OSType osType = Iterables.getFirst(osTypes, null);

      // Register a template
      RegisterTemplateOptions options = RegisterTemplateOptions.Builder.bits(32).isExtractable(true);
      TemplateMetadata templateMetadata = TemplateMetadata.builder().name(prefix+"-registerTemplate").osTypeId(osType.getId()).displayText("jclouds live testRegisterTemplate").build();
      Set<Template> templates = client.getTemplateClient().registerTemplate(templateMetadata, "VHD", "XenServer", IMPORT_VHD_URL, zone.getId(), options);
      registeredTemplate = Iterables.getOnlyElement(templates, null);
      assertNotNull(registeredTemplate);

      // Ensure it is available
      final String zoneId = zone.getId();
      Predicate<Template> templateReadyPredicate = new Predicate<Template>() {
         @Override
         public boolean apply(Template template) {
            if (template == null) return false;
            Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId);
View Full Code Here

      Set<Zone> response = client.getZoneClient().listZones();
      assert null != response;
      long zoneCount = response.size();
      assertTrue(zoneCount >= 0);
      for (Zone zone : response) {
         Zone newDetails = Iterables.getOnlyElement(client.getZoneClient().listZones(
               ListZonesOptions.Builder.id(zone.getId())));
         assertEquals(zone, newDetails);
         assertEquals(zone, client.getZoneClient().getZone(zone.getId()));
         assert zone.getId() != null : zone;
         assert zone.getName() != null : zone;
View Full Code Here

   @Test
   public void testCreateUpdateDeleteZone() {
      skipIfNotGlobalAdmin();

      Zone zone = null;
      String zoneName = prefix + "-zone";
      try {
         zone = globalAdminClient.getZoneClient().createZone(zoneName,
            NetworkType.BASIC, "8.8.8.8", "10.10.10.10");

         assertNotNull(zone);
         assertEquals(zone, globalAdminClient.getZoneClient().getZone(zone.getId()));
         assertEquals(zone.getNetworkType(), NetworkType.BASIC);
         assertEquals(zone.getDNS(), ImmutableList.of("8.8.8.8"));
         assertEquals(zone.getInternalDNS(), ImmutableList.of("10.10.10.10"));

         Zone updated = globalAdminClient.getZoneClient().updateZone(zone.getId(),
            name(zoneName + "-2").externalDns(ImmutableList.of("8.8.4.4")));
         assertEquals(updated.getId(), zone.getId());
         assertEquals(updated.getDNS(), ImmutableList.of("8.8.4.4"));

      } finally {
         if (zone != null) {
            globalAdminClient.getZoneClient().deleteZone(zone.getId());
         }
View Full Code Here

   @Test
   public void testCreateVlanIPRange() {
      skipIfNotGlobalAdmin();

      final Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
      final NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(),
         NetworkOfferingPredicates.supportsGuestVirtualNetworks());

      if (offering != null) {
         Set<Network> suitableNetworks = Sets.filter(client.getNetworkClient().listNetworks(
                 zoneId(zone.getId()).isSystem(false).trafficType(TrafficType.GUEST)),
                 new Predicate<Network>() {
            @Override
            public boolean apply(Network network) {
               return network.getNetworkOfferingId().equals(offering.getId());
            }
         });

         if (suitableNetworks.size() > 0) {
            network = Iterables.get(suitableNetworks, 0);
            usingExistingNetwork = true;

         } else if (network == null) {
            network = client.getNetworkClient().createNetworkInZone(zone.getId(),
                    offering.getId(), "net-" + prefix, "jclouds test " + prefix);
            usingExistingNetwork = false;
         }

         range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder
View Full Code Here

      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getIngressRules()).andReturn(ImmutableSet.<IngressRule> of());
      expect(group.getId()).andReturn("sec-1234").anyTimes();
      expect(zone.isSecurityGroupsEnabled()).andReturn(true);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();
View Full Code Here

      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getId()).andReturn("sec-1234").anyTimes();
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
View Full Code Here

      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(zone.isSecurityGroupsEnabled()).andReturn(false);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();
View Full Code Here

   @Override
   public SecurityGroup apply(ZoneSecurityGroupNamePortsCidrs input) {
      checkNotNull(input, "input");

      String zoneId = input.getZone();
      Zone zone = zoneIdToZone.get().getUnchecked(zoneId);

      checkArgument(supportsSecurityGroups().apply(zone),
                    "Security groups are required, but the zone %s does not support security groups", zoneId);
      logger.debug(">> creating securityGroup %s", input);
      try {
View Full Code Here

         "options class %s should have been assignable from CloudStackTemplateOptions", template.getOptions()
         .getClass());
      Map<String, Network> networks = networkSupplier.get();

      final String zoneId = template.getLocation().getId();
      Zone zone = zoneIdToZone.get().getUnchecked(zoneId);

      CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);

      checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s", zone.getNetworkType());
      DeployVirtualMachineOptions options = displayName(name).name(name);
      if (templateOptions.getAccount() != null) {
          options.accountInDomain(templateOptions.getAccount(), templateOptions.getDomainId());
      } else if (templateOptions.getDomainId() != null) {
          options.domainId(templateOptions.getDomainId());
      }
     
      OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType());
      options = optionsConverter.apply(templateOptions, networks, zoneId, options);

      if (templateOptions.getIpOnDefaultNetwork() != null) {
         options.ipOnDefaultNetwork(templateOptions.getIpOnDefaultNetwork());
      }

      if (templateOptions.getIpsToNetworks().size() > 0) {
         options.ipsToNetworks(templateOptions.getIpsToNetworks());
      }

      if (templateOptions.getKeyPair() != null) {
         SshKeyPair keyPair = null;
         if (templateOptions.getLoginPrivateKey() != null) {
            String pem = templateOptions.getLoginPrivateKey();
            keyPair = SshKeyPair.builder().name(templateOptions.getKeyPair())
               .fingerprint(fingerprintPrivateKey(pem)).privateKey(pem).build();
            keyPairCache.asMap().put(keyPair.getName(), keyPair);
            options.keyPair(keyPair.getName());
         } else if (client.getSSHKeyPairClient().getSSHKeyPair(templateOptions.getKeyPair()) != null) {
            keyPair = client.getSSHKeyPairClient().getSSHKeyPair(templateOptions.getKeyPair());
         }
         if (keyPair != null) {
            keyPairCache.asMap().put(keyPair.getName(), keyPair);
            options.keyPair(keyPair.getName());
         }
      } else if (templateOptions.shouldGenerateKeyPair()) {
         SshKeyPair keyPair = keyPairCache.getUnchecked(namingConvention.create()
                                                        .sharedNameForGroup(group));
         keyPairCache.asMap().put(keyPair.getName(), keyPair);
         templateOptions.keyPair(keyPair.getName());
         options.keyPair(keyPair.getName());
      }

      if (supportsSecurityGroups().apply(zone)) {
         List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());

         if (templateOptions.getSecurityGroupIds().size() == 0
             && inboundPorts.size() > 0
             && templateOptions.shouldGenerateSecurityGroup()) {
            String securityGroupName = namingConvention.create().sharedNameForGroup(group);
            SecurityGroup sg = securityGroupCache.getUnchecked(ZoneSecurityGroupNamePortsCidrs.builder()
                                                               .zone(zone.getId())
                                                               .name(securityGroupName)
                                                               .ports(ImmutableSet.copyOf(inboundPorts))
                                                               .cidrs(ImmutableSet.<String> of()).build());
            options.securityGroupId(sg.getId());
         }
View Full Code Here

TOP

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

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.