provisionr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject [04/21] PROVISIONR-20. Change groupId from com.axemblr.provisionr to org.apache.provisionr
Date Mon, 01 Apr 2013 08:52:27 GMT
http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/CloudStackActivity.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/CloudStackActivity.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/CloudStackActivity.java
deleted file mode 100644
index 3e128b9..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/CloudStackActivity.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.api.provider.Provider;
-import com.axemblr.provisionr.core.CoreProcessVariables;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Closeables;
-import com.google.inject.Module;
-import java.util.Properties;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.activiti.engine.delegate.JavaDelegate;
-import org.jclouds.Constants;
-import org.jclouds.ContextBuilder;
-import org.jclouds.cloudstack.CloudStackApiMetadata;
-import org.jclouds.cloudstack.CloudStackAsyncClient;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
-import org.jclouds.rest.RestContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Base class for all activities that require access to a CloudStack based cloud.
- */
-public abstract class CloudStackActivity implements JavaDelegate {
-
-    private static final Logger LOG = LoggerFactory.getLogger(CloudStackActivity.class);
-
-    /**
-     * Implement activity logic in this method. It will be called with a reference to the {@link CloudStackClient}
-     */
-    public abstract void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution);
-
-    @Override
-    public void execute(DelegateExecution execution) throws Exception {
-
-        RestContext<CloudStackClient, CloudStackAsyncClient> restContext = null;
-        try {
-            Pool pool = Pool.class.cast(checkNotNull(execution.getVariable(CoreProcessVariables.POOL),
-                "Please add 'pool' variable to the process"));
-            // delegate
-            restContext = newCloudStackClient(pool.getProvider());
-            execute(restContext.getApi(), pool, execution);
-
-        } finally {
-            Closeables.closeQuietly(restContext);
-        }
-    }
-
-    /**
-     * Creates a new {@link CloudStackClient} with {@link Provider} supplied credentials.
-     */
-    RestContext<CloudStackClient, CloudStackAsyncClient> newCloudStackClient(Provider provider) {
-        checkArgument(provider.getEndpoint().isPresent(), "please specify an endpoint for this provider");
-        Properties overrides = new Properties();
-        overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
-        return ContextBuilder.newBuilder(new CloudStackApiMetadata())
-            .endpoint(provider.getEndpoint().get())
-            .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()))
-            .credentials(provider.getAccessKey(), provider.getSecretKey())
-            .overrides(overrides)
-            .build(CloudStackApiMetadata.CONTEXT_TOKEN);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteKeyPair.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteKeyPair.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteKeyPair.java
deleted file mode 100644
index 2368e57..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteKeyPair.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.core.KeyPairs;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DeleteKeyPair extends CloudStackActivity {
-
-    private static final Logger LOG = LoggerFactory.getLogger(DeleteKeyPair.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey());
-        LOG.info("Deleting Admin Access Key pair {}", keyName);
-        cloudStackClient.getSSHKeyPairClient().deleteSSHKeyPair(keyName);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteSecurityGroup.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteSecurityGroup.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteSecurityGroup.java
deleted file mode 100644
index 8dbd03e..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/DeleteSecurityGroup.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.core.SecurityGroups;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DeleteSecurityGroup extends CloudStackActivity {
-
-    private static final Logger LOG = LoggerFactory.getLogger(DeleteSecurityGroup.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey());
-        SecurityGroups.deleteByName(cloudStackClient, securityGroupName);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureKeyPairExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureKeyPairExists.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureKeyPairExists.java
deleted file mode 100644
index f719831..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureKeyPairExists.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.core.KeyPairs;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.SshKeyPair;
-import org.jclouds.cloudstack.features.SSHKeyPairClient;
-import org.jclouds.crypto.SshKeys;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EnsureKeyPairExists extends CloudStackActivity {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EnsureKeyPairExists.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey());
-        LOG.info("Creating admin access key pair as {}", keyName);
-        SSHKeyPairClient sshKeyPairClient = cloudStackClient.getSSHKeyPairClient();
-        try {
-            SshKeyPair sshKeyPair = sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());
-            LOG.info("Registered remote key with fingerprint {}", sshKeyPair.getFingerprint());
-        } catch (IllegalStateException e) {
-            LOG.warn("Key with name {} already exists", keyName);
-            SshKeyPair key = sshKeyPairClient.getSSHKeyPair(keyName);
-            if (key.getFingerprint().equals(SshKeys.fingerprintPublicKey(pool.getAdminAccess().getPublicKey()))) {
-                LOG.info("Fingerprints match. Not updating admin access key pair.");
-            } else {
-                LOG.info("Fingerprint do not match. Replacing admin access key pair.");
-                sshKeyPairClient.deleteSSHKeyPair(keyName);
-                sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureNetworkExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureNetworkExists.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureNetworkExists.java
deleted file mode 100644
index 211fef7..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureNetworkExists.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.NetworkOptions;
-import com.axemblr.provisionr.cloudstack.ProcessVariables;
-import com.axemblr.provisionr.cloudstack.ProviderOptions;
-import com.axemblr.provisionr.cloudstack.core.Networks;
-import static com.google.common.base.Preconditions.checkNotNull;
-import java.util.NoSuchElementException;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.Network;
-import org.jclouds.cloudstack.options.CreateNetworkOptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EnsureNetworkExists extends CloudStackActivity {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EnsureNetworkExists.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        if (execution.getVariable(ProcessVariables.NETWORK_ID) != null) {
-            LOG.warn("Network process variable ({}) will be overwritten!", ProcessVariables.NETWORK_ID);
-        }
-        Network network;
-        final String existingNetwork = pool.getNetwork().getOption(NetworkOptions.EXISTING_NETWORK_ID);
-        if (existingNetwork != null) {
-            network = checkNotNull(cloudStackClient.getNetworkClient().getNetwork(existingNetwork),
-                "Network with id " + existingNetwork + " does not exist");
-        } else {
-            final String networkName = Networks.formatNameFromBusinessKey(execution.getProcessBusinessKey());
-            final String zoneId = pool.getProvider().getOption(ProviderOptions.ZONE_ID);
-            final String networkOfferingId = pool.getProvider().getOption(ProviderOptions.NETWORK_OFFERING_ID);
-            try {
-                network = Networks.getByName(cloudStackClient, networkName);
-                LOG.info("Network with name {} exists.", networkName);
-            } catch (NoSuchElementException e) {
-                LOG.info(String.format("Creating network %s in zone %s with offering %s",
-                    networkName, zoneId, networkOfferingId));
-                network = cloudStackClient.getNetworkClient().createNetworkInZone(zoneId, networkOfferingId, networkName,
-                    networkName, CreateNetworkOptions.NONE);
-            }
-        }
-        LOG.info("Storing network id {} in process variable {}", network.getId(), ProcessVariables.NETWORK_ID);
-        execution.setVariable(ProcessVariables.NETWORK_ID, network.getId());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
deleted file mode 100644
index 8da633a..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.network.Network;
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.core.SecurityGroups;
-import static com.google.common.base.Preconditions.checkNotNull;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.SecurityGroup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Creates a CloudStack {@link SecurityGroup} with specified rules. If a SecurityGroup with the same name exists,
- * it will be deleted first.
- */
-public class EnsureSecurityGroupExists extends CloudStackActivity {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EnsureSecurityGroupExists.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        Network network = checkNotNull(pool.getNetwork(), "Please configure a network for the pool");
-        String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey());
-        SecurityGroup securityGroup;
-        try {
-            LOG.info("Creating SecurityGroup {}", securityGroupName);
-            securityGroup = SecurityGroups.createSecurityGroup(cloudStackClient, securityGroupName);
-        } catch (IllegalStateException e) {
-            LOG.info("Failed creating SecurityGroup {} - checking if it exists", securityGroupName);
-            securityGroup = SecurityGroups.getByName(cloudStackClient, securityGroupName);
-            LOG.info("Delete old SecurityGroup rules for {}", securityGroupName);
-            SecurityGroups.deleteNetworkRules(cloudStackClient, securityGroup);
-        }
-        if (securityGroup != null) {
-            LOG.info("Applying network rules on SecurityGroup {}", securityGroupName);
-            SecurityGroups.applyNetworkRules(cloudStackClient, securityGroup, network);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/RunInstances.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/RunInstances.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/RunInstances.java
deleted file mode 100644
index f419f3e..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/activities/RunInstances.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.activities;
-
-import com.axemblr.provisionr.api.pool.Pool;
-import com.axemblr.provisionr.cloudstack.ProviderOptions;
-import com.axemblr.provisionr.cloudstack.core.KeyPairs;
-import com.axemblr.provisionr.cloudstack.core.Networks;
-import com.axemblr.provisionr.cloudstack.core.VirtualMachines;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.AsyncCreateResponse;
-import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class RunInstances extends CloudStackActivity {
-
-    public static final Logger LOG = LoggerFactory.getLogger(RunInstances.class);
-
-    @Override
-    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
-        final String businessKey = execution.getProcessBusinessKey();
-
-        final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey);
-
-        final String zoneId = pool.getOptions().get(ProviderOptions.ZONE_ID);
-        final String templateId = pool.getSoftware().getImageId();
-        final String serviceOffering = pool.getHardware().getType();
-
-        LOG.info("Starting instances!");
-
-        AsyncCreateResponse asyncCreateResponse = cloudStackClient.getVirtualMachineClient()
-            .deployVirtualMachineInZone(zoneId, serviceOffering, templateId,
-                DeployVirtualMachineOptions.Builder
-                    .displayName(businessKey)
-                    .group(businessKey)
-                    .networkId(Networks.formatNameFromBusinessKey(businessKey))
-                    .keyPair(keyPairName)
-                    .name(businessKey));
-
-        VirtualMachines.waitForVMtoStart(cloudStackClient, businessKey);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/CommandSupport.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/CommandSupport.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/CommandSupport.java
deleted file mode 100644
index 9099350..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/CommandSupport.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.commands;
-
-import com.axemblr.provisionr.api.provider.Provider;
-import com.axemblr.provisionr.cloudstack.DefaultProviderConfig;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Closeables;
-import java.io.PrintStream;
-import java.util.Properties;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.jclouds.Constants;
-import org.jclouds.ContextBuilder;
-import org.jclouds.cloudstack.CloudStackApiMetadata;
-import org.jclouds.cloudstack.CloudStackAsyncClient;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
-import org.jclouds.rest.RestContext;
-
-
-/**
- * Base class for CloudStack  Karaf Shell commands. It takes care of creating and cleaning a
- * {@link org.jclouds.cloudstack.CloudStackContext} for each command.
- */
-public abstract class CommandSupport extends OsgiCommandSupport {
-
-    private RestContext<CloudStackClient, CloudStackAsyncClient> context = null;
-    public static final String CLOUDSTACK_SCOPE = "cloudstack";
-
-    private final Provider provider;
-
-    protected CommandSupport(DefaultProviderConfig providerConfig) {
-        this.provider = providerConfig.createProvider().get();
-    }
-
-    public abstract Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception;
-
-    @Override
-    protected Object doExecute() throws Exception {
-        try {
-            context = newCloudStackContext(provider);
-            return doExecuteWithContext(context.getApi(), System.out);
-        } finally {
-            Closeables.closeQuietly(context);
-        }
-    }
-
-    protected RestContext<CloudStackClient, CloudStackAsyncClient> newCloudStackContext(Provider provider) {
-        Properties overrides = new Properties();
-        overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
-        return ContextBuilder.newBuilder(new CloudStackApiMetadata())
-            .endpoint(provider.getEndpoint().get())
-            .modules(ImmutableSet.of(new SLF4JLoggingModule()))
-            .credentials(provider.getAccessKey(), provider.getSecretKey())
-            .overrides(overrides)
-            .build(CloudStackApiMetadata.CONTEXT_TOKEN);
-    }
-
-    public Provider getProvider() {
-        return provider;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/OfferingsCommand.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/OfferingsCommand.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/OfferingsCommand.java
deleted file mode 100644
index fe479ea..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/OfferingsCommand.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.commands;
-
-import com.axemblr.provisionr.cloudstack.DefaultProviderConfig;
-import java.io.PrintStream;
-import org.apache.felix.gogo.commands.Command;
-import org.apache.felix.gogo.commands.Option;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.DiskOffering;
-import org.jclouds.cloudstack.domain.NetworkOffering;
-import org.jclouds.cloudstack.domain.ServiceOffering;
-
-@Command(scope = CommandSupport.CLOUDSTACK_SCOPE, name = OfferingsCommand.NAME,
-    description = "Commands to list CloudStack Service Offerings")
-public class OfferingsCommand extends CommandSupport {
-
-    public static final String NAME = "offerings";
-
-    @Option(name = "-s", aliases = "--service", description = "List service offerings")
-    private boolean serviceOffering;
-
-    @Option(name = "-n", aliases = "--network", description = "List network offerings")
-    private boolean networkOffering;
-
-    @Option(name = "-d", aliases = "--disk", description = "List disk offerings")
-    private boolean diskOffering;
-
-    public OfferingsCommand(DefaultProviderConfig providerConfig) {
-        super(providerConfig);
-    }
-
-    @Override
-    public Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception {
-        if (isDiskOfferingListed() || isServiceOfferingListed() || isNetworkOfferingListed()) {
-            out.printf("CloudStack Offerings for provider %s\n", getProvider().getId());
-            listServiceOfferingsIfSpecified(client, out);
-            listNetworkOfferingsIfSpecified(client, out);
-            listDiskOfferingsIfSpecified(client, out);
-        } else {
-            out.printf("No option specified. See --help for details.");
-        }
-        return null;
-    }
-
-    private void listDiskOfferingsIfSpecified(CloudStackClient client, PrintStream out) {
-        if (isDiskOfferingListed()) {
-            for (DiskOffering offering : client.getOfferingClient().listDiskOfferings()) {
-                out.printf("---\n%s\n", offering.toString());
-            }
-        }
-    }
-
-    private void listNetworkOfferingsIfSpecified(CloudStackClient client, PrintStream out) {
-        if (isNetworkOfferingListed()) {
-            for (NetworkOffering offering : client.getOfferingClient().listNetworkOfferings()) {
-                out.printf("---\n%s\n", offering.toString());
-            }
-        }
-    }
-
-    private void listServiceOfferingsIfSpecified(CloudStackClient client, PrintStream out) {
-        if (isServiceOfferingListed()) {
-            for (ServiceOffering offering : client.getOfferingClient().listServiceOfferings()) {
-                out.printf("---\n%s\n", offering.toString());
-            }
-        }
-    }
-
-    public boolean isDiskOfferingListed() {
-        return diskOffering;
-    }
-
-    public void setDiskOffering(boolean diskOffering) {
-        this.diskOffering = diskOffering;
-    }
-
-    public boolean isNetworkOfferingListed() {
-        return networkOffering;
-    }
-
-    public void setNetworkOffering(boolean networkOffering) {
-        this.networkOffering = networkOffering;
-    }
-
-    public boolean isServiceOfferingListed() {
-        return serviceOffering;
-    }
-
-    public void setServiceOffering(boolean serviceOffering) {
-        this.serviceOffering = serviceOffering;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/TemplatesCommand.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/TemplatesCommand.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/TemplatesCommand.java
deleted file mode 100644
index caa53db..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/TemplatesCommand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.commands;
-
-import com.axemblr.provisionr.cloudstack.DefaultProviderConfig;
-import java.io.PrintStream;
-import org.apache.felix.gogo.commands.Command;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.Template;
-
-@Command(scope = CommandSupport.CLOUDSTACK_SCOPE, name = TemplatesCommand.NAME,
-    description = "Commands to list CloudStack templates")
-public class TemplatesCommand extends CommandSupport {
-
-    public static final String NAME = "templates";
-
-    public TemplatesCommand(DefaultProviderConfig providerConfig) {
-        super(providerConfig);
-    }
-
-    @Override
-    public Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception {
-        out.printf("CloudStack templates for provider %s\n", getProvider().getId());
-
-        for (Template template : client.getTemplateClient().listTemplates()) {
-            out.printf("---\n%s\n", template.toString());
-        }
-        out.println();
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/ZonesCommand.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/ZonesCommand.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/ZonesCommand.java
deleted file mode 100644
index 039d635..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/commands/ZonesCommand.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.commands;
-
-import com.axemblr.provisionr.cloudstack.DefaultProviderConfig;
-import java.io.PrintStream;
-import org.apache.felix.gogo.commands.Command;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.Zone;
-
-@Command(scope = CommandSupport.CLOUDSTACK_SCOPE, name = ZonesCommand.NAME,
-    description = "Commands to list CloudStack Zones")
-public class ZonesCommand extends CommandSupport {
-
-    public static final String NAME = "zones";
-
-    public ZonesCommand(DefaultProviderConfig defaultProviderConfig) {
-        super(defaultProviderConfig);
-    }
-
-    @Override
-    public Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception {
-        out.printf("CloudStack zones for provider %s\n", getProvider().getId());
-        for (Zone zone : client.getZoneClient().listZones()) {
-            out.printf("---\n%s\n", zone.toString());
-        }
-        out.println();
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/ConvertIngressRuleToRule.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/ConvertIngressRuleToRule.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/ConvertIngressRuleToRule.java
deleted file mode 100644
index 4a53133..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/ConvertIngressRuleToRule.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-import com.axemblr.provisionr.api.network.Protocol;
-import com.axemblr.provisionr.api.network.Rule;
-import com.google.common.base.Function;
-import org.jclouds.cloudstack.domain.IngressRule;
-
-public enum ConvertIngressRuleToRule implements Function<IngressRule, Rule> {
-    FUNCTION;
-
-    @Override
-    public Rule apply(IngressRule input) {
-        Rule rule;
-        if (input.getProtocol().equalsIgnoreCase("icmp")) {
-            rule = Rule.builder()
-                .anySource()
-                .protocol(Protocol.valueOf(input.getProtocol().toUpperCase()))
-                .cidr(input.getCIDR())
-                .createRule();
-        } else {
-            rule = Rule.builder()
-                .anySource()
-                .protocol(Protocol.valueOf(input.getProtocol().toUpperCase()))
-                .ports(input.getStartPort(), input.getEndPort())
-                .cidr(input.getCIDR())
-                .createRule();
-        }
-        return rule;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/KeyPairs.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/KeyPairs.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/KeyPairs.java
deleted file mode 100644
index 88f8b66..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/KeyPairs.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-public class KeyPairs {
-
-    private KeyPairs() {
-        // singleton
-    }
-
-    public static String formatNameFromBusinessKey(String businessKey) {
-        return String.format("key-%s", businessKey);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Networks.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Networks.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Networks.java
deleted file mode 100644
index db85bd3..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Networks.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.Network;
-
-public class Networks {
-
-    private Networks() {
-    }
-
-    public static String formatNameFromBusinessKey(String processBusinessKey) {
-        return String.format("networks-%s", processBusinessKey);
-    }
-
-    /**
-     * Returns the first network with the given name.
-     *
-     * @throws NoSuchElementException   if no network is found
-     * @throws IllegalArgumentException if more networks with the same name are found
-     */
-    public static Network getByName(CloudStackClient client, final String networkName) {
-        Set<Network> networks = Sets.filter(client.getNetworkClient().listNetworks(), new Predicate<Network>() {
-            @Override
-            public boolean apply(Network input) {
-                return input.getName().equals(networkName);
-            }
-        });
-        return Iterables.getOnlyElement(networks);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/SecurityGroups.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/SecurityGroups.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/SecurityGroups.java
deleted file mode 100644
index 735b6e5..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/SecurityGroups.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-import com.axemblr.provisionr.api.network.Network;
-import com.axemblr.provisionr.api.network.Protocol;
-import com.axemblr.provisionr.api.network.Rule;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.IngressRule;
-import org.jclouds.cloudstack.domain.SecurityGroup;
-import org.jclouds.cloudstack.features.SecurityGroupClient;
-import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.named;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SecurityGroups {
-
-    private static final Logger LOG = LoggerFactory.getLogger(SecurityGroup.class);
-    public static final int DEFAULT_ICMP_CODE = 0;
-    public static final int DEFAULT_ICMP_TYPE = 8;
-
-    private SecurityGroups() {
-    }
-
-    public static String formatNameFromBusinessKey(String processBusinessKey) {
-        return String.format("network-%s", processBusinessKey);
-    }
-
-    /**
-     * Get a SecurityGroup by name.
-     *
-     * @throws NoSuchElementException if securityGroup does not exist.
-     */
-    public static SecurityGroup getByName(CloudStackClient cloudStackClient, String securityGroup) {
-        return Iterables.getOnlyElement(cloudStackClient
-            .getSecurityGroupClient()
-            .listSecurityGroups(named(securityGroup)));
-    }
-
-    public static Set<SecurityGroup> getAll(CloudStackClient cloudStackClient) {
-        return cloudStackClient.getSecurityGroupClient().listSecurityGroups();
-    }
-
-    public static void deleteByName(CloudStackClient cloudStackClient, String securityGroupName) {
-        try {
-            SecurityGroup securityGroup = getByName(cloudStackClient, securityGroupName);
-            LOG.info("Deleting SecurityGroup {}", securityGroup.getName());
-            cloudStackClient.getSecurityGroupClient().deleteSecurityGroup(securityGroup.getId());
-        } catch (NoSuchElementException e) {
-            LOG.warn("Exception retrieving SecurityGroup (most likely it does not yet exist){}: {}", securityGroupName, e);
-        }
-    }
-
-    public static SecurityGroup createSecurityGroup(CloudStackClient cloudStackClient, String securityGroupName) {
-        SecurityGroupClient securityGroupClient = cloudStackClient.getSecurityGroupClient();
-        return securityGroupClient.createSecurityGroup(securityGroupName);
-    }
-
-    public static void deleteNetworkRules(CloudStackClient cloudStackClient, SecurityGroup securityGroup) {
-        for (IngressRule rule : securityGroup.getIngressRules()) {
-            cloudStackClient.getSecurityGroupClient().revokeIngressRule(rule.getId());
-        }
-    }
-
-    public static void applyNetworkRules(CloudStackClient cloudStackClient, SecurityGroup securityGroup, Network network) {
-        SecurityGroupClient securityGroupClient = cloudStackClient.getSecurityGroupClient();
-        for (Rule rule : network.getIngress()) {
-            if (rule.getProtocol() == Protocol.ICMP) {
-                securityGroupClient.authorizeIngressICMPToCIDRs(securityGroup.getId(), DEFAULT_ICMP_CODE,
-                    DEFAULT_ICMP_TYPE, ImmutableList.of(rule.getCidr()));
-            } else {
-                securityGroupClient.authorizeIngressPortsToCIDRs(securityGroup.getId(),
-                    rule.getProtocol().name(),
-                    rule.getPorts().lowerEndpoint(),
-                    rule.getPorts().upperEndpoint(),
-                    Lists.newArrayList(rule.getCidr()));
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/VirtualMachines.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/VirtualMachines.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/VirtualMachines.java
deleted file mode 100644
index 00efc0d..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/VirtualMachines.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.VirtualMachine;
-import static org.jclouds.cloudstack.domain.VirtualMachine.State.STARTING;
-import org.jclouds.cloudstack.options.ListVirtualMachinesOptions;
-import static org.jclouds.util.Preconditions2.checkNotEmpty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class VirtualMachines {
-
-    private static final Logger LOG = LoggerFactory.getLogger(VirtualMachines.class);
-    public static int WAIT_TIME_OUT_IN_SECONDS = 180;
-    public static final int BETWEEN_REQUESTS_SLEEP_TIME = WAIT_TIME_OUT_IN_SECONDS / 10;
-
-    private VirtualMachines() {
-    }
-
-    public static List<String> destroyAllVirtualMachineByName(final CloudStackClient client, final String vmName) {
-        checkNotEmpty(vmName);
-
-        Set<VirtualMachine> vms = Sets.filter(client.getVirtualMachineClient()
-            .listVirtualMachines(ListVirtualMachinesOptions.Builder.name(vmName)), new Predicate<VirtualMachine>() {
-            @Override
-            public boolean apply(VirtualMachine input) {
-                return vmName.equals(input.getDisplayName());
-            }
-        });
-
-        List<String> jobIds = Lists.newArrayList();
-        LOG.info("Deleting a total of {} virtual machine instances", vms.size());
-        for (VirtualMachine vm : vms) {
-            LOG.info("Deleting instance with id {}", vm.getId());
-            jobIds.add(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId()));
-        }
-        return ImmutableList.copyOf(jobIds);
-    }
-
-    public static void waitForVMtoStart(final CloudStackClient client, final String vmName) {
-        checkNotEmpty(vmName);
-        VirtualMachine machine = getVirtualMachineByName(client, vmName);
-        String id = machine.getId();
-        long startTime = System.currentTimeMillis();
-        while (machine.getState() == STARTING) {
-            try {
-                LOG.info("Waiting for VM {} - id {} to start", machine.getName(), machine.getId());
-                TimeUnit.SECONDS.sleep(BETWEEN_REQUESTS_SLEEP_TIME);
-                machine = client.getVirtualMachineClient().getVirtualMachine(id);
-            } catch (InterruptedException e) {
-                LOG.info("Interrupted while waiting for VM's to start");
-                Throwables.propagateIfPossible(e);
-            }
-            if (timeOutExceeded(startTime)) {
-                break;
-            }
-        }
-
-        switch (machine.getState()) {
-            case RUNNING:
-                LOG.info("VM {} is running, as expected", vmName);
-                break;
-            default:
-                throw new IllegalStateException("VM " + machine + "is not in RUNNING state");
-        }
-    }
-
-    private static boolean timeOutExceeded(long startTime) {
-        return System.currentTimeMillis() - startTime > (WAIT_TIME_OUT_IN_SECONDS * 1000);
-    }
-
-    private static VirtualMachine getVirtualMachineByName(CloudStackClient client, final String vmName) {
-        Set<VirtualMachine> machines = Sets.filter(client.getVirtualMachineClient()
-            .listVirtualMachines(ListVirtualMachinesOptions.Builder.name(vmName)), new Predicate<VirtualMachine>() {
-            @Override
-            public boolean apply(VirtualMachine input) {
-                return vmName.equals(input.getDisplayName());
-            }
-        });
-        return Iterables.getOnlyElement(machines);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Zones.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Zones.java b/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Zones.java
deleted file mode 100644
index eebc4ce..0000000
--- a/providers/cloudstack/src/main/java/com/axemblr/provisionr/cloudstack/core/Zones.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.axemblr.provisionr.cloudstack.core;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import java.util.Set;
-import org.jclouds.cloudstack.CloudStackClient;
-import org.jclouds.cloudstack.domain.Zone;
-
-public class Zones {
-
-    private Zones() {
-    }
-
-    public static boolean hasSecurityGroupEnabled(final CloudStackClient cloudStackClient, final String zoneName) {
-        Set<Zone> ourZone = Sets.filter(cloudStackClient.getZoneClient().listZones(), new Predicate<Zone>() {
-            @Override
-            public boolean apply(Zone input) {
-                return input.getName().equals(zoneName);
-            }
-        });
-        return Iterables.getOnlyElement(ourZone).isSecurityGroupsEnabled();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/CloudStackProvisionr.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/CloudStackProvisionr.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/CloudStackProvisionr.java
new file mode 100644
index 0000000..2ce5a99
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/CloudStackProvisionr.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack;
+
+import com.google.common.base.Optional;
+import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.Maps;
+import java.util.Map;
+import org.activiti.engine.ProcessEngine;
+import org.activiti.engine.RuntimeService;
+import org.activiti.engine.runtime.ProcessInstance;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.api.provider.Provider;
+import org.apache.provisionr.core.CoreConstants;
+import org.apache.provisionr.core.CoreProcessVariables;
+import org.apache.provisionr.core.ProvisionrSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudStackProvisionr extends ProvisionrSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CloudStackProvisionr.class);
+    public static final String ID = "cloudstack";
+    /**
+     * Process key must match the one in
+     *  providers/cloudstack/src/main/resources/OSGI-INF/activiti/cloudstack.bpmn20.xml
+     */
+    public static final String PROCESS_KEY = "cloudstack";
+
+    private final ProcessEngine processEngine;
+    private final Optional<Provider> defaultProvider;
+
+    public CloudStackProvisionr(ProcessEngine processEngine, DefaultProviderConfig providerConfig) {
+        this.processEngine = checkNotNull(processEngine, "processEngine is null");
+        this.defaultProvider = providerConfig.createProvider();
+
+        if (defaultProvider.isPresent()) {
+            LOG.info("Default provider for CloudStackProvisionr is {}", defaultProvider.get());
+        } else {
+            LOG.info("No default provider configured for CloudStackProvisionr");
+        }
+    }
+
+    @Override
+    public String getId() {
+        return ID;
+    }
+
+    @Override
+    public Optional<Provider> getDefaultProvider() {
+        return defaultProvider;
+    }
+
+    @Override
+    public String startPoolManagementProcess(String businessKey, Pool pool) {
+        Map<String, Object> arguments = Maps.newHashMap();
+
+        arguments.put(CoreProcessVariables.POOL, pool);
+        arguments.put(CoreProcessVariables.PROVIDER, getId());
+        arguments.put(CoreProcessVariables.POOL_BUSINESS_KEY, businessKey);
+        arguments.put(CoreProcessVariables.BOOTSTRAP_TIMEOUT,
+            convertTimeoutToISO8601TimeDuration(pool.getBootstrapTimeInSeconds()));
+
+        /* Authenticate as kermit to make the process visible in the Explorer UI */
+        processEngine.getIdentityService().setAuthenticatedUserId(CoreConstants.ACTIVITI_EXPLORER_DEFAULT_USER);
+
+        RuntimeService runtimeService = processEngine.getRuntimeService();
+        ProcessInstance instance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, businessKey, arguments);
+
+        return instance.getProcessInstanceId();
+    }
+
+    @Override
+    public void destroyPool(String businessKey) {
+        LOG.info("**** CloudStack (destroyPool) id: " + businessKey);
+        // TODO use triggerSignalEvent as needed
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/DefaultProviderConfig.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/DefaultProviderConfig.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/DefaultProviderConfig.java
new file mode 100644
index 0000000..05ac50c
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/DefaultProviderConfig.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack;
+
+import org.apache.provisionr.api.provider.Provider;
+import com.google.common.base.Optional;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class DefaultProviderConfig {
+
+    private final String endpoint;
+    private final String accessKey;
+    private final String secretKey;
+    private final String zoneId;
+    private final String templateId;
+    private final String serviceOffering;
+
+    public DefaultProviderConfig(
+        String endpoint, String accessKey, String secretKey, String zoneId, String templateId, String serviceOffering
+    ) {
+        this.endpoint = checkNotNull(endpoint, "endpoint is null");
+        this.accessKey = checkNotNull(accessKey, "access key is null");
+        this.secretKey = checkNotNull(secretKey, "secret key is null");
+        this.zoneId = checkNotNull(zoneId, "zone id is null");
+        this.templateId = checkNotNull(templateId, "template id is null");
+        this.serviceOffering = checkNotNull(serviceOffering, "service offering is null");
+    }
+
+    public Optional<Provider> createProvider() {
+        if (accessKey.isEmpty() || secretKey.isEmpty() || endpoint.isEmpty()) {
+            return Optional.absent();
+        }
+        return Optional.of(Provider.builder()
+            .id(CloudStackProvisionr.ID)
+            .endpoint(endpoint)
+            .accessKey(accessKey)
+            .secretKey(secretKey)
+            .option(ProviderOptions.ZONE_ID, zoneId)
+            .option(ProviderOptions.TEMPLATE_ID, templateId)
+            .option(ProviderOptions.SERVICE_OFFERING_ID, serviceOffering)
+            .createProvider());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/NetworkOptions.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/NetworkOptions.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/NetworkOptions.java
new file mode 100644
index 0000000..9fb3fdd
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/NetworkOptions.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack;
+
+/**
+ * {@link org.apache.provisionr.api.network.Network Network} configuration is passed via the
+ * {@link org.apache.provisionr.api.pool.Pool Pool} object. This class stores names for those options.
+ */
+public class NetworkOptions {
+
+    private NetworkOptions() {
+        throw new RuntimeException("Do not instantiate");
+    }
+
+    /**
+     * Pass this option if you wish to use an existing CloudStack network.
+     */
+    public static final String EXISTING_NETWORK_ID = "existingNetworkId";
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
new file mode 100644
index 0000000..83c72fe
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack;
+
+public class ProcessVariables {
+
+    private ProcessVariables() {
+        // prevent instantiation
+    }
+
+    public static final String NETWORK_ID = "networkId";
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProviderOptions.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProviderOptions.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProviderOptions.java
new file mode 100644
index 0000000..9874696
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProviderOptions.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack;
+
+
+/**
+ * Building a pool of VM's on CloudStack requires more knowledge of the cloud's architecture,
+ * You need to know things like in what zone to build the pool, the ID's of service offerings, network offerings,
+ * and more.
+ * <p/>
+ * All the information is passed via Provider Options. This class stores some of the option names.
+ */
+public class ProviderOptions {
+
+    private ProviderOptions() {
+        throw new RuntimeException(ProviderOptions.class.getName() + " should not be instantiated");
+    }
+
+    public static final String ZONE_ID = "zoneId";
+    public static final String TEMPLATE_ID = "templateId";
+    public static final String SERVICE_OFFERING_ID = "serviceOfferingId";
+    public static final String NETWORK_OFFERING_ID = "networkOfferingId";
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/CloudStackActivity.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/CloudStackActivity.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/CloudStackActivity.java
new file mode 100644
index 0000000..5bbe3d2
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/CloudStackActivity.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.Closeables;
+import com.google.inject.Module;
+import java.util.Properties;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.activiti.engine.delegate.JavaDelegate;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.api.provider.Provider;
+import org.apache.provisionr.core.CoreProcessVariables;
+import org.jclouds.Constants;
+import org.jclouds.ContextBuilder;
+import org.jclouds.cloudstack.CloudStackApiMetadata;
+import org.jclouds.cloudstack.CloudStackAsyncClient;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
+import org.jclouds.rest.RestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base class for all activities that require access to a CloudStack based cloud.
+ */
+public abstract class CloudStackActivity implements JavaDelegate {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CloudStackActivity.class);
+
+    /**
+     * Implement activity logic in this method. It will be called with a reference to the {@link CloudStackClient}
+     */
+    public abstract void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution);
+
+    @Override
+    public void execute(DelegateExecution execution) throws Exception {
+
+        RestContext<CloudStackClient, CloudStackAsyncClient> restContext = null;
+        try {
+            Pool pool = Pool.class.cast(checkNotNull(execution.getVariable(CoreProcessVariables.POOL),
+                "Please add 'pool' variable to the process"));
+            // delegate
+            restContext = newCloudStackClient(pool.getProvider());
+            execute(restContext.getApi(), pool, execution);
+
+        } finally {
+            Closeables.closeQuietly(restContext);
+        }
+    }
+
+    /**
+     * Creates a new {@link CloudStackClient} with {@link Provider} supplied credentials.
+     */
+    RestContext<CloudStackClient, CloudStackAsyncClient> newCloudStackClient(Provider provider) {
+        checkArgument(provider.getEndpoint().isPresent(), "please specify an endpoint for this provider");
+        Properties overrides = new Properties();
+        overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
+        return ContextBuilder.newBuilder(new CloudStackApiMetadata())
+            .endpoint(provider.getEndpoint().get())
+            .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()))
+            .credentials(provider.getAccessKey(), provider.getSecretKey())
+            .overrides(overrides)
+            .build(CloudStackApiMetadata.CONTEXT_TOKEN);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPair.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPair.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPair.java
new file mode 100644
index 0000000..b0f49af
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPair.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.KeyPairs;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeleteKeyPair extends CloudStackActivity {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DeleteKeyPair.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey());
+        LOG.info("Deleting Admin Access Key pair {}", keyName);
+        cloudStackClient.getSSHKeyPairClient().deleteSSHKeyPair(keyName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroup.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroup.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroup.java
new file mode 100644
index 0000000..d4f28d1
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroup.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.SecurityGroups;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeleteSecurityGroup extends CloudStackActivity {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DeleteSecurityGroup.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey());
+        SecurityGroups.deleteByName(cloudStackClient, securityGroupName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExists.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExists.java
new file mode 100644
index 0000000..80e7b86
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExists.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.KeyPairs;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.SshKeyPair;
+import org.jclouds.cloudstack.features.SSHKeyPairClient;
+import org.jclouds.crypto.SshKeys;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EnsureKeyPairExists extends CloudStackActivity {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EnsureKeyPairExists.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey());
+        LOG.info("Creating admin access key pair as {}", keyName);
+        SSHKeyPairClient sshKeyPairClient = cloudStackClient.getSSHKeyPairClient();
+        try {
+            SshKeyPair sshKeyPair = sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());
+            LOG.info("Registered remote key with fingerprint {}", sshKeyPair.getFingerprint());
+        } catch (IllegalStateException e) {
+            LOG.warn("Key with name {} already exists", keyName);
+            SshKeyPair key = sshKeyPairClient.getSSHKeyPair(keyName);
+            if (key.getFingerprint().equals(SshKeys.fingerprintPublicKey(pool.getAdminAccess().getPublicKey()))) {
+                LOG.info("Fingerprints match. Not updating admin access key pair.");
+            } else {
+                LOG.info("Fingerprint do not match. Replacing admin access key pair.");
+                sshKeyPairClient.deleteSSHKeyPair(keyName);
+                sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExists.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExists.java
new file mode 100644
index 0000000..ec4c22b
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExists.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.NetworkOptions;
+import org.apache.provisionr.cloudstack.ProcessVariables;
+import org.apache.provisionr.cloudstack.ProviderOptions;
+import org.apache.provisionr.cloudstack.core.Networks;
+import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.NoSuchElementException;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.Network;
+import org.jclouds.cloudstack.options.CreateNetworkOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EnsureNetworkExists extends CloudStackActivity {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EnsureNetworkExists.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        if (execution.getVariable(ProcessVariables.NETWORK_ID) != null) {
+            LOG.warn("Network process variable ({}) will be overwritten!", ProcessVariables.NETWORK_ID);
+        }
+        Network network;
+        final String existingNetwork = pool.getNetwork().getOption(NetworkOptions.EXISTING_NETWORK_ID);
+        if (existingNetwork != null) {
+            network = checkNotNull(cloudStackClient.getNetworkClient().getNetwork(existingNetwork),
+                "Network with id " + existingNetwork + " does not exist");
+        } else {
+            final String networkName = Networks.formatNameFromBusinessKey(execution.getProcessBusinessKey());
+            final String zoneId = pool.getProvider().getOption(ProviderOptions.ZONE_ID);
+            final String networkOfferingId = pool.getProvider().getOption(ProviderOptions.NETWORK_OFFERING_ID);
+            try {
+                network = Networks.getByName(cloudStackClient, networkName);
+                LOG.info("Network with name {} exists.", networkName);
+            } catch (NoSuchElementException e) {
+                LOG.info(String.format("Creating network %s in zone %s with offering %s",
+                    networkName, zoneId, networkOfferingId));
+                network = cloudStackClient.getNetworkClient().createNetworkInZone(zoneId, networkOfferingId, networkName,
+                    networkName, CreateNetworkOptions.NONE);
+            }
+        }
+        LOG.info("Storing network id {} in process variable {}", network.getId(), ProcessVariables.NETWORK_ID);
+        execution.setVariable(ProcessVariables.NETWORK_ID, network.getId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
new file mode 100644
index 0000000..858aea8
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExists.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.network.Network;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.SecurityGroups;
+import static com.google.common.base.Preconditions.checkNotNull;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.SecurityGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Creates a CloudStack {@link SecurityGroup} with specified rules. If a SecurityGroup with the same name exists,
+ * it will be deleted first.
+ */
+public class EnsureSecurityGroupExists extends CloudStackActivity {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EnsureSecurityGroupExists.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        Network network = checkNotNull(pool.getNetwork(), "Please configure a network for the pool");
+        String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey());
+        SecurityGroup securityGroup;
+        try {
+            LOG.info("Creating SecurityGroup {}", securityGroupName);
+            securityGroup = SecurityGroups.createSecurityGroup(cloudStackClient, securityGroupName);
+        } catch (IllegalStateException e) {
+            LOG.info("Failed creating SecurityGroup {} - checking if it exists", securityGroupName);
+            securityGroup = SecurityGroups.getByName(cloudStackClient, securityGroupName);
+            LOG.info("Delete old SecurityGroup rules for {}", securityGroupName);
+            SecurityGroups.deleteNetworkRules(cloudStackClient, securityGroup);
+        }
+        if (securityGroup != null) {
+            LOG.info("Applying network rules on SecurityGroup {}", securityGroupName);
+            SecurityGroups.applyNetworkRules(cloudStackClient, securityGroup, network);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/RunInstances.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/RunInstances.java b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/RunInstances.java
new file mode 100644
index 0000000..d9c3b8e
--- /dev/null
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/activities/RunInstances.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.ProviderOptions;
+import org.apache.provisionr.cloudstack.core.KeyPairs;
+import org.apache.provisionr.cloudstack.core.Networks;
+import org.apache.provisionr.cloudstack.core.VirtualMachines;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.AsyncCreateResponse;
+import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RunInstances extends CloudStackActivity {
+
+    public static final Logger LOG = LoggerFactory.getLogger(RunInstances.class);
+
+    @Override
+    public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
+        final String businessKey = execution.getProcessBusinessKey();
+
+        final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey);
+
+        final String zoneId = pool.getOptions().get(ProviderOptions.ZONE_ID);
+        final String templateId = pool.getSoftware().getImageId();
+        final String serviceOffering = pool.getHardware().getType();
+
+        LOG.info("Starting instances!");
+
+        AsyncCreateResponse asyncCreateResponse = cloudStackClient.getVirtualMachineClient()
+            .deployVirtualMachineInZone(zoneId, serviceOffering, templateId,
+                DeployVirtualMachineOptions.Builder
+                    .displayName(businessKey)
+                    .group(businessKey)
+                    .networkId(Networks.formatNameFromBusinessKey(businessKey))
+                    .keyPair(keyPairName)
+                    .name(businessKey));
+
+        VirtualMachines.waitForVMtoStart(cloudStackClient, businessKey);
+    }
+}


Mime
View raw message