Package org.jclouds.cloudstack

Examples of org.jclouds.cloudstack.CloudStackApi


         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)) {
View Full Code Here


@Test(groups = "unit", testName = "FindSecurityGroupOrCreateTest")
public class FindSecurityGroupOrCreateTest {

   @Test
   public void testLoad() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.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.getSecurityGroupApi()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneApi()).andReturn(zoneClient);
      expect(client.getAsyncJobApi()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-1")).andReturn(zone);
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(null);
      expect(secClient.createSecurityGroup("group-1")).andReturn(group);
      expect(secClient.authorizeIngressPortsToCIDRs("sec-1234",
View Full Code Here

   }

  
   @Test
   public void testLoadAlreadyExists() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getId()).andReturn("sec-1234").anyTimes();
     
      expect(client.getSecurityGroupApi()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneApi()).andReturn(zoneClient);
      expect(client.getAsyncJobApi()).andReturn(jobClient).anyTimes();

      expect(secClient.getSecurityGroupByName("group-1")).andReturn(group);

      replay(client, secClient, zoneClient, zone, group);
View Full Code Here

      verify(client, secClient, zoneClient, zone, group);
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testLoadZoneNoSecurityGroups() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(zone.isSecurityGroupsEnabled()).andReturn(false);
     
      expect(client.getSecurityGroupApi()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneApi()).andReturn(zoneClient);
      expect(client.getAsyncJobApi()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-1")).andReturn(zone);
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(null);

      replay(client, secClient, zoneClient, zone, group);
View Full Code Here

@Test(groups = "unit", testName = "CreateSecurityGroupIfNeededTest")
public class CreateSecurityGroupIfNeededTest {

   @Test
   public void testApply() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.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.getSecurityGroupApi()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneApi()).andReturn(zoneClient);
      expect(client.getAsyncJobApi()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-abc1")).andReturn(zone);
      expect(secClient.createSecurityGroup("group-1")).andReturn(group);
      expect(secClient.authorizeIngressPortsToCIDRs("sec-1234",
                                                    "TCP",
View Full Code Here

   }

  
   @Test
   public void testApplyGroupAlreadyExists() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getId()).andReturn("sec-1234").anyTimes();
      expect(zone.isSecurityGroupsEnabled()).andReturn(true);
     
      expect(client.getSecurityGroupApi()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneApi()).andReturn(zoneClient);
      expect(client.getAsyncJobApi()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-abc2")).andReturn(zone);
      expect(secClient.createSecurityGroup("group-1")).andThrow(new IllegalStateException());
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(group);
View Full Code Here

      verify(client, secClient, zoneClient, zone, group);
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testApplyZoneNoSecurityGroups() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
      ZoneApi zoneClient = createMock(ZoneApi.class);
      AsyncJobApi jobClient = createMock(AsyncJobApi.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(zone.isSecurityGroupsEnabled()).andReturn(false);
     
      expect(client.getZoneApi()).andReturn(zoneClient);

      expect(zoneClient.getZone("zone-abc3")).andReturn(zone);

      replay(client, zoneClient, zone);
View Full Code Here

   @BeforeClass(groups = { "integration", "live" })
   public void setupContext() {
      super.setupContext();

      CloudStackApi api = view.unwrapApi(CloudStackApi.class);
      for (Zone z: api.getZoneApi().listZones()) {
         if (z.isSecurityGroupsEnabled()) {
            zone = z;
            break;
         }
      }
View Full Code Here

@Test(groups = "unit", testName = "CreateUniqueKeyPairTest")
public class CreateUniqueKeyPairTest {

   @Test
   public void testLoad() throws UnknownHostException {
      final CloudStackApi client = createMock(CloudStackApi.class);
      SSHKeyPairApi keyClient = createMock(SSHKeyPairApi.class);

      SshKeyPair pair = createMock(SshKeyPair.class);

      expect(client.getSSHKeyPairApi()).andReturn(keyClient);
      expect(keyClient.createSSHKeyPair("group-1")).andReturn(pair);

      replay(client, keyClient);

      CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
View Full Code Here

   public void testApply() {
      String id = "1";
      String jobId = "2";

      CloudStackApi client = createMock(CloudStackApi.class);
      Predicate<String> jobComplete = Predicates.alwaysTrue();
      AsyncJobApi jobClient = createMock(AsyncJobApi.class);

      expect(client.getAsyncJobApi()).andReturn(jobClient).atLeastOnce();
      expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce();

      replay(client);
      replay(jobClient);
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.CloudStackApi

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.