
def create_ec2_cloud = { instance, cloud_name, cloud_credentials_id, cloud_region, cloud_priv_key, cloud_instance_cap, ec2_workers ->
    def new_cloud = new hudson.plugins.ec2.AmazonEC2Cloud(
      cloud_name,           // Amazon EC2 Cloud Name
      false,                // Use EC2 instance profile for credentials
      cloud_credentials_id, // Credentials ID
      cloud_region,         // Region
      cloud_priv_key,       // Private Key
      cloud_instance_cap,   // Instance Cap
      ec2_workers           // List<? extends SlaveTemplate> templates
    )
    println '+++++ START CLOUD ADDING ' + cloud_name
    instance.clouds.each {
      instance.clouds.remove(it)
    }
    instance.clouds.add(new_cloud)
}

