Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.VirtualMachine


      logger.debug("serviceOfferingId %s, templateId %s, zoneId %s, options %s%n", serviceOfferingId, templateId,
         zoneId, options);
      AsyncCreateResponse job = client.getVirtualMachineApi().deployVirtualMachineInZone(zoneId, serviceOfferingId,
         templateId, options);
      VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job);
      logger.debug("--- virtualmachine: %s", vm);
      LoginCredentials.Builder credentialsBuilder = LoginCredentials.builder();
      if (templateOptions.getKeyPair() != null) {
         SshKeyPair keyPair = keyPairCache.getUnchecked(templateOptions.getKeyPair());
         credentialsBuilder.privateKey(keyPair.getPrivateKey());
      } else if (vm.isPasswordEnabled()) {
         assert vm.getPassword() != null : vm;
         credentialsBuilder.password(vm.getPassword());
      }
     
      if (templateOptions.shouldSetupStaticNat()) {
         Capabilities capabilities = client.getConfigurationApi().listCapabilities();
         // TODO: possibly not all network ids, do we want to do this
         for (String networkId : options.getNetworkIds()) {
            logger.debug(">> creating static NAT for virtualMachine(%s) in network(%s)", vm.getId(), networkId);
            PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
            logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());
            vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId());
            List<Integer> ports = Ints.asList(templateOptions.getInboundPorts());
            if (capabilities.getCloudStackVersion().startsWith("2")) {
               logger.debug(">> setting up IP forwarding for IPAddress(%s) rules(%s)", ip.getId(), ports);
               Set<IPForwardingRule> rules = setupPortForwardingRulesForIP.apply(ip, ports);
               logger.trace("<< setup %d IP forwarding rules on IPAddress(%s)", rules.size(), ip.getId());
            } else {
               logger.debug(">> setting up firewall rules for IPAddress(%s) rules(%s)", ip.getId(), ports);
               Set<FirewallRule> rules = setupFirewallRulesForIP.apply(ip, ports);
               logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId());
            }
         }
      }
      return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId() + "", credentialsBuilder.build());
   }
View Full Code Here


                        return ImmutableSet.of(IPForwardingRule.builder().id("1234l").IPAddress("1.1.1.1").build());
                     }
                  }), namingConvention);

      // notice if we've already parsed this properly here, we can rely on it.
      VirtualMachine guest = Iterables.get(new ListVirtualMachinesResponseTest().expected(), 0);

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node.toString(),
View Full Code Here

                     public Set<IPForwardingRule> load(String arg0) throws Exception {
                        return ImmutableSet.of();
                     }
                  }), namingConvention);

      VirtualMachine guest =VirtualMachine.builder()
         .id("54")
         .name("i-3-54-VM")
         .displayName("i-3-54-VM")
         .account("adrian")
         .domainId("1")
View Full Code Here

                     }

                  }), namingConvention);

      // notice if we've already parsed this properly here, we can rely on it.
      VirtualMachine guest = Iterables.get(new ListVirtualMachinesResponseTest().expected(), 0);

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node.toString(),
View Full Code Here

      assertPredicateResult(State.ERROR, true);
   }

   private void assertPredicateResult(State state, boolean expected) {
      String virtualMachineId = "229";
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id(virtualMachineId).state(state).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(virtualMachine);
      replay(client, virtualMachineClient);
View Full Code Here

      expect(client.getVirtualMachineApi()).andReturn(virtualMachineClient);
   }

   @Test
   public void testWaitForVirtualMachineToBeExpunged() {
      VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build();
      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(null);

      replay(client, virtualMachineClient);
      assertTrue(new VirtualMachineExpunged(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

      verify(client, virtualMachineClient);
   }

   @Test
   public void testNoRemovedYet() {
      VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build();
      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertFalse(new VirtualMachineExpunged(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

      expect(client.getVirtualMachineApi()).andReturn(virtualMachineClient);
   }

   @Test
   public void testIsDestroyed() {
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id("229").state(VirtualMachine.State.DESTROYED).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

      verify(client, virtualMachineClient);
   }

   @Test
   public void testStillRunning() {
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id("229").state(VirtualMachine.State.RUNNING).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertFalse(new VirtualMachineDestroyed(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

   @Test
   public void testCreateVMWithoutSecurityGroupAssignsDefault() throws Exception {
      skipIfSecurityGroupsNotSupported();
      String defaultTemplate = template != null ? template.getImageId() : null;
      VirtualMachine newVm = VirtualMachineApiLiveTest.createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions.NONE,
            zone.getId(), defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), client,
            jobComplete, virtualMachineRunning);
      try {
         VirtualMachine runningVm = client.getVirtualMachineApi().getVirtualMachine(newVm.getId());
         assertEquals(1, runningVm.getSecurityGroups().size());
         assertEquals(Iterables.getOnlyElement(runningVm.getSecurityGroups()).getName(), "default");
      } finally {
         assertTrue(jobComplete.apply(client.getVirtualMachineApi().destroyVirtualMachine(newVm.getId())));
      }
   }
View Full Code Here

TOP

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

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.