Package org.jclouds.cloudstack

Examples of org.jclouds.cloudstack.CloudStackContext


    * @throws NoSuchElementException, AuthorizationException
    * @return
    */
   public static ApiKeyPair loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair(
         URI endpoint, String username, String password, String domain) {
      CloudStackContext context = null;
      try {
         Properties overrides = new Properties();
         overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
         overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");
         overrides.put("jclouds.cloudstack.credential-type", "passwordCredentials");
        
         context =  ContextBuilder.newBuilder(new CloudStackApiMetadata())
               .endpoint(checkNotNull(endpoint, "endpoint").toASCIIString())
               .credentials(String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username")), password)
               .overrides(overrides).build(CloudStackContext.class);

         CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
         Set<Account> listOfAccounts = client.getAccountClient().listAccounts();

         domain = (domain.equals("") || domain.equals("/")) ? "ROOT" : domain;
         for (Account account : listOfAccounts) {
            for (User user : account.getUsers()) {
               if (user.getName().equals(username) && user.getDomain().equals(domain)) {
                  return ApiKeyPair.builder().apiKey(user.getApiKey())
                     .secretKey(user.getSecretKey()).build();
               }
            }
         }
         throw new NoSuchElementException("Unable to find API keypair for user " + username);

      } finally {
         if (context != null)
            context.close();
      }
   }
View Full Code Here


         .setupStaticNat(false)
         .generateSecurityGroup(true)
         .overrideLoginPrivateKey(privKey);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials().getPrivateKey(), privKey);
View Full Code Here

         .domainId("domainId")
         .setupStaticNat(false)
         .overrideLoginPrivateKey(privKey);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials().getPrivateKey(), privKey);
View Full Code Here

      Template template = forKeyPair.getInstance(TemplateBuilder.class).osFamily(OsFamily.CENTOS).build();
      template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").setupStaticNat(false);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials(),
                   LoginCredentials.fromCredentials(context.utils().getCredentialStore().get("keypair#" +
                                                                        template.getOptions().
                                                                          as(CloudStackTemplateOptions.class).
                                                                          getKeyPair())));
   }
View Full Code Here

      Template template = forKeyPair.getInstance(TemplateBuilder.class).osFamily(OsFamily.CENTOS).build();
      template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").account("account").domainId("domainId").setupStaticNat(false);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials(),
                   LoginCredentials.fromCredentials(context.utils().getCredentialStore().get("keypair#" +
                                                                        template.getOptions().
                                                                          as(CloudStackTemplateOptions.class).
                                                                          getKeyPair())));
   }  
View Full Code Here

    * @throws NoSuchElementException, AuthorizationException
    * @return
    */
   public static ApiKeyPair loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair(
         URI endpoint, String username, String password, String domain) {
      CloudStackContext context = null;
      try {
         Properties overrides = new Properties();
         overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
         overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");
         overrides.put("jclouds.cloudstack.credential-type", "passwordCredentials");
        
         context =  ContextBuilder.newBuilder(new CloudStackApiMetadata())
               .endpoint(checkNotNull(endpoint, "endpoint").toASCIIString())
               .credentials(String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username")), password)
               .overrides(overrides).build(CloudStackContext.class);

         CloudStackApi client = context.getApi();
         Set<Account> listOfAccounts = client.getAccountApi().listAccounts();

         domain = (domain.equals("") || domain.equals("/")) ? "ROOT" : domain;
         for (Account account : listOfAccounts) {
            for (User user : account.getUsers()) {
               if (user.getName().equals(username) && user.getDomain().equals(domain)) {
                  return ApiKeyPair.builder().apiKey(user.getApiKey())
                     .secretKey(user.getSecretKey()).build();
               }
            }
         }
         throw new NoSuchElementException("Unable to find API keypair for user " + username);

      } finally {
         if (context != null)
            context.close();
      }
   }
View Full Code Here

         .setupStaticNat(false)
         .generateSecurityGroup(true)
         .overrideLoginPrivateKey(privKey);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials().getPrivateKey(), privKey);
View Full Code Here

         .domainId("domainId")
         .setupStaticNat(false)
         .overrideLoginPrivateKey(privKey);

      CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
      CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);

      NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
            template);
      assertNotNull(server);
      assertEquals(server.getCredentials().getPrivateKey(), privKey);
View Full Code Here

         globalAdminClient.getAccountApi().deleteAccount(testAccount.getId());
      }
   }

   private void checkAuthAsUser(ApiKeyPair keyPair) {
      CloudStackContext context = createView(credentialsAsProperties(keyPair), setupModules());

      CloudStackApi client = context.getApi();
      Set<Account> accounts = client.getAccountApi().listAccounts();

      assert accounts.size() > 0;

      context.close();
   }
View Full Code Here

    * @throws NoSuchElementException, AuthorizationException
    * @return
    */
   public static ApiKeyPair loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair(
         URI endpoint, String username, String password, String domain) {
      CloudStackContext context = null;
      try {
         Properties overrides = new Properties();
         overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
         overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");
         overrides.put("jclouds.cloudstack.credential-type", "passwordCredentials");
        
         context =  ContextBuilder.newBuilder(new CloudStackApiMetadata())
               .endpoint(checkNotNull(endpoint, "endpoint").toASCIIString())
               .credentials(String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username")), password)
               .overrides(overrides).build(CloudStackContext.class);

         CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
         Set<Account> listOfAccounts = client.getAccountClient().listAccounts();

         domain = (domain.equals("") || domain.equals("/")) ? "ROOT" : domain;
         for (Account account : listOfAccounts) {
            for (User user : account.getUsers()) {
               if (user.getName().equals(username) && user.getDomain().equals(domain)) {
                  return ApiKeyPair.builder().apiKey(user.getApiKey())
                     .secretKey(user.getSecretKey()).build();
               }
            }
         }
         throw new NoSuchElementException("Unable to find API keypair for user " + username);

      } finally {
         if (context != null)
            context.close();
      }
   }
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.CloudStackContext

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.