Exemple #1
0
def validate_template(template, aws_key=None, aws_secret_key=None):
    # Connect to CloudFormation, if keys are None, they're loaded from
    # environment variables or boto configuration if present.
    conn = CloudFormationConnection(aws_access_key_id=aws_key,
                                    aws_secret_access_key=aws_secret_key)
    retval = True
    try:
        conn.validate_template(template_body=template)
    except BotoServerError as e:
        print >> sys.stderr, "Template Validation Failed:"
        for Error in ElementTree.fromstring(e.args[2]):
            if not Error.tag.endswith("Error"):
                continue
            code = "Unknown"
            msg = "Unknown"
            for element in Error:
                if element.tag.endswith("Code"):
                    code = element.text
                elif element.tag.endswith("Message"):
                    msg = element.text
            print >> sys.stderr, "Source:   %s" % code
            print >> sys.stderr, "Message:  %s" % msg
        retval = False
    conn.close()
    return retval
Exemple #2
0
 def setUp(self):
     self.https_connection = Mock(spec=httplib.HTTPSConnection)
     self.https_connection_factory = (Mock(
         return_value=self.https_connection), ())
     self.stack_id = u'arn:aws:cloudformation:us-east-1:18:stack/Name/id'
     self.cloud_formation = CloudFormationConnection(
         https_connection_factory=self.https_connection_factory,
         aws_access_key_id='aws_access_key_id',
         aws_secret_access_key='aws_secret_access_key')
     self.actual_request = None
     # We want to be able to verify the request params that
     # are sent to the CloudFormation service. By the time
     # we get to the boto.connection.AWSAuthConnection._mexe
     # method, all of the request params have been populated.
     # By patching out the _mexe method with self._mexe_spy,
     # we can record the actual http request that _mexe is passed
     # so that we can verify the http params (and anything
     # else about the request that we want).
     self.original_mexe = self.cloud_formation._mexe
     self.cloud_formation._mexe = self._mexe_spy
Exemple #3
0
def getCloudFormationConnection (awsAccessKey, awsSecretKey):
    cloudFormationConnection = CloudFormationConnection(awsAccessKey, awsSecretKey)
    return cloudFormationConnection
Exemple #4
0
        "-m",
        "--mothball",
        type=str,
        help="reduce the instances for all autoscaling group(s) "
        "in a stack to zero")
    parser.add_argument(
        "-r",
        "--reopen",
        nargs=2,
        help="increase the instances for all autoscaling group(s) "
        "in a stack to min:max:desired")
    args = parser.parse_args()

    # connect to AWS
    try:
        cfn = CloudFormationConnection()
        asg = AutoScaleConnection()
    except:
        print "AWS connect error"
    else:
        # get the key data
        data = getStackAutoscalingGroupData(cfn, asg)
        # list if explicitly listing or not doing anything else
        if args.list or args.mothball is None and args.reopen is None:
            for stackname in sorted(data, key=data.__getitem__):
                print "{s}:".format(s=stackname, )
                for asginfo in data[stackname]:
                    print "    {n} {mn}:{mx}:{d}".format(
                        n=asginfo['name'],
                        mn=asginfo['min'],
                        mx=asginfo['max'],
Exemple #5
0
 def setUp(self):
     self.connection = CloudFormationConnection()
     self.stack_name = 'testcfnstack' + str(int(time.time()))
'''
cloudFormationOutput = {}

from boto.s3.connection import S3Connection
s3conn = S3Connection(accessKey, secretKey)
s3conn.auth_region_name = 'us-east-1'
bucket = s3conn.create_bucket('ipmstempbucket_0101')

from boto.s3.key import Key
bucketKey = Key(bucket)
bucketKey.key = 'templatefile'
bucketKey.set_contents_from_filename('docker_server.template')
s3url = "https://s3.amazonaws.com/ipmstempbucket_0101/templatefile"

from boto.cloudformation.connection import CloudFormationConnection
cfConn = CloudFormationConnection(accessKey, secretKey)
#stackName = "TestStack"
disableRollback = False

cfConn.create_stack(stackName,
                    template_url=s3url,
                    parameters=parameters.items(),
                    disable_rollback=disableRollback,
                    timeout_in_minutes=rollbacktimeout)

#print "Creating the stack"

count = 0
finished = False
while (count < 9 and finished == False):
    stacks = cfConn.describe_stacks(stackName)