Package org.jclouds.openstack.nova.v2_0.domain

Examples of org.jclouds.openstack.nova.v2_0.domain.KeyPair


      CreateServerWithKeyPair createServerWithKeyPair = new CreateServerWithKeyPair(args[0], args[1]);
      NodeMetadata node;

      try {
         createServerWithKeyPair.detectKeyPairExtension();
         KeyPair keyPair = createServerWithKeyPair.createKeyPair();
         node = createServerWithKeyPair.createServer(keyPair);
         createServerWithKeyPair.disablePasswordAuthentication(node);
         createServerWithKeyPair.deleteKeyPair(keyPair);
      }
      catch (Exception e) {
View Full Code Here


    */
   private KeyPair createKeyPair() throws IOException {
      System.out.format("  Create Key Pair%n");

      KeyPairApi keyPairApi = novaApi.getKeyPairExtensionForZone(ZONE).get();
      KeyPair keyPair = keyPairApi.create(NAME);

      Files.write(keyPair.getPrivateKey(), keyPairFile, UTF_8);

      System.out.format("    Wrote %s%n", keyPairFile.getAbsolutePath());

      return keyPair;
   }
View Full Code Here

      checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
            zoneId);

      logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);

      KeyPair keyPair = null;
      while (keyPair == null) {
         try {
            keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
         } catch (IllegalStateException e) {

         }
      }

      logger.debug("<< created keyPair(%s)", keyPair.getName());
      return keyPair;
   }
View Full Code Here

      boolean keyPairExtensionPresent = novaApi.getKeyPairApi(region).isPresent();
      if (templateOptions.shouldGenerateKeyPair()) {
         checkArgument(keyPairExtensionPresent,
                  "Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
         KeyPair keyPair = keyPairCache.getUnchecked(RegionAndName.fromRegionAndName(region, namingConvention.create()
                  .sharedNameForGroup(group)));
         keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
         templateOptions.keyPairName(keyPair.getName());
      } else if (templateOptions.getKeyPairName() != null) {
         checkArgument(keyPairExtensionPresent,
                  "Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
         if (templateOptions.getLoginPrivateKey() != null) {
            String pem = templateOptions.getLoginPrivateKey();
            KeyPair keyPair = KeyPair.builder().name(templateOptions.getKeyPairName())
                     .fingerprint(fingerprintPrivateKey(pem)).privateKey(pem).build();
            keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
         }
      }

      boolean securityGroupExtensionPresent = novaApi.getSecurityGroupApi(region).isPresent();
      List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());
View Full Code Here

      checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in region %s!",
            regionId);

      logger.debug(">> creating keyPair region(%s) prefix(%s)", regionId, prefix);

      KeyPair keyPair = null;
      while (keyPair == null) {
         try {
            keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
         } catch (IllegalStateException e) {

         }
      }

      logger.debug("<< created keyPair(%s)", keyPair.getName());
      return keyPair;
   }
View Full Code Here

      }

      Optional<String> privateKey = Optional.absent();
      if (templateOptions.getKeyPairName() != null) {
         options.keyPairName(templateOptions.getKeyPairName());
         KeyPair keyPair = keyPairCache.getIfPresent(RegionAndName.fromRegionAndName(template.getLocation().getId(), templateOptions.getKeyPairName()));
         if (keyPair != null && keyPair.getPrivateKey() != null) {
            privateKey = Optional.of(keyPair.getPrivateKey());
            credentialsBuilder.privateKey(privateKey.get());
         }
      }

      String regionId = template.getLocation().getId();
View Full Code Here

   }

   public void testCreateAndGetAndDeleteKeyPair() throws Exception {
      for (String regionId : api.getConfiguredRegions()) {
         KeyPairApi keyPairApi = api.getKeyPairApi(regionId).get();
         KeyPair createdKeyPair = null;
         try {
            createdKeyPair = keyPairApi.create(KEYPAIR_NAME);
            assertNotNull(createdKeyPair);

            KeyPair keyPair = keyPairApi.get(KEYPAIR_NAME);
            assertEquals(keyPair.getName(), createdKeyPair.getName());
            assertEquals(keyPair.getFingerprint(), createdKeyPair.getFingerprint());
            assertEquals(keyPair.getPublicKey(), createdKeyPair.getPublicKey());
         } finally {
            if (createdKeyPair != null) {
               keyPairApi.delete(KEYPAIR_NAME);
            }
         }
View Full Code Here

   }

   public void testCreateAndDeleteKeyPairWithPublicKey() throws Exception {
      for (String regionId : api.getConfiguredRegions()) {
         KeyPairApi keyPairApi = api.getKeyPairApi(regionId).get();
         KeyPair createdKeyPair = null;
         try {
            createdKeyPair = keyPairApi.createWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY);
            assertNotNull(createdKeyPair);

            KeyPair keyPair = keyPairApi.get(KEYPAIR_NAME);
            assertEquals(keyPair.getName(), createdKeyPair.getName());
            assertEquals(keyPair.getFingerprint(), createdKeyPair.getFingerprint());
            assertEquals(keyPair.getPublicKey(), createdKeyPair.getPublicKey());
         } finally {
            if (createdKeyPair != null) {
               keyPairApi.delete(KEYPAIR_NAME);
            }
         }
View Full Code Here

   @Test
   public void testApply() throws UnknownHostException {
      final NovaApi api = createMock(NovaApi.class);
      KeyPairApi keyApi = createMock(KeyPairApi.class);

      KeyPair pair = createMock(KeyPair.class);

      Optional optKeyApi = Optional.of(keyApi);

      expect(api.getKeyPairApi("region")).andReturn(optKeyApi).atLeastOnce();
View Full Code Here

      final NovaApi api = createMock(NovaApi.class);
      KeyPairApi keyApi = createMock(KeyPairApi.class);
      @SuppressWarnings("unchecked")
      final Supplier<String> uniqueIdSupplier = createMock(Supplier.class);

      KeyPair pair = createMock(KeyPair.class);

      expect(api.getKeyPairApi("region")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();

      expect(uniqueIdSupplier.get()).andReturn("1");
      expect(keyApi.create("group-1")).andThrow(new IllegalStateException());
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.nova.v2_0.domain.KeyPair

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.