Ejemplo n.º 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
Ejemplo n.º 2
0
class TestCloudformationConnection(unittest.TestCase):
    def setUp(self):
        self.connection = CloudFormationConnection()
        self.stack_name = 'testcfnstack' + str(int(time.time()))

    def test_large_template_stack_size(self):
        # See https://github.com/boto/boto/issues/1037
        body = self.connection.create_stack(
            self.stack_name, template_body=json.dumps(BASIC_EC2_TEMPLATE))
        self.addCleanup(self.connection.delete_stack, self.stack_name)
Ejemplo n.º 3
0
class TestCloudformationConnection(unittest.TestCase):
    def setUp(self):
        self.connection = CloudFormationConnection()
        self.stack_name = 'testcfnstack' + str(int(time.time()))

    def test_large_template_stack_size(self):
        # See https://github.com/boto/boto/issues/1037
        body = self.connection.create_stack(
            self.stack_name,
            template_body=json.dumps(BASIC_EC2_TEMPLATE))
        self.addCleanup(self.connection.delete_stack, self.stack_name)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
class TestCloudformationConnection(unittest.TestCase):
    def setUp(self):
        self.connection = CloudFormationConnection()
        self.stack_name = 'testcfnstack' + str(int(time.time()))

    def test_large_template_stack_size(self):
        # See https://github.com/boto/boto/issues/1037
        body = self.connection.create_stack(
            self.stack_name,
            template_body=json.dumps(BASIC_EC2_TEMPLATE))
        self.addCleanup(self.connection.delete_stack, self.stack_name)

        # A newly created stack should have events
        events = self.connection.describe_stack_events(self.stack_name)
        self.assertTrue(events)

        # No policy should be set on the stack by default
        policy = self.connection.get_stack_policy(self.stack_name)
        self.assertEqual(None, policy)

        # Our new stack should show up in the stack list
        stacks = self.connection.describe_stacks()
        self.assertEqual(self.stack_name, stacks[0].stack_name)
Ejemplo n.º 6
0
class TestCloudformationConnection(unittest.TestCase):
    def setUp(self):
        self.connection = CloudFormationConnection()
        self.stack_name = 'testcfnstack' + str(int(time.time()))

    def test_large_template_stack_size(self):
        # See https://github.com/boto/boto/issues/1037
        body = self.connection.create_stack(
            self.stack_name,
            template_body=json.dumps(BASIC_EC2_TEMPLATE),
            parameters=[('Parameter1', 'initial_value'),
                        ('Parameter2', 'initial_value')])
        self.addCleanup(self.connection.delete_stack, self.stack_name)

        # A newly created stack should have events
        events = self.connection.describe_stack_events(self.stack_name)
        self.assertTrue(events)

        # No policy should be set on the stack by default
        policy = self.connection.get_stack_policy(self.stack_name)
        self.assertEqual(None, policy)

        # Our new stack should show up in the stack list
        stacks = self.connection.describe_stacks(self.stack_name)
        stack = stacks[0]
        self.assertEqual(self.stack_name, stack.stack_name)

        params = [(p.key, p.value) for p in stack.parameters]
        self.assertEquals([('Parameter1', 'initial_value'),
                           ('Parameter2', 'initial_value')], params)

        for _ in range(30):
            stack.update()
            if stack.stack_status.find("PROGRESS") == -1:
                break
            time.sleep(5)

        body = self.connection.update_stack(
            self.stack_name,
            template_body=json.dumps(BASIC_EC2_TEMPLATE),
            parameters=[('Parameter1', '', True),
                        ('Parameter2', 'updated_value')])

        stacks = self.connection.describe_stacks(self.stack_name)
        stack = stacks[0]
        params = [(p.key, p.value) for p in stacks[0].parameters]
        self.assertEquals([('Parameter1', 'initial_value'),
                           ('Parameter2', 'updated_value')], params)

        # Waiting for the update to complete to unblock the delete_stack in the
        # cleanup.
        for _ in range(30):
            stack.update()
            if stack.stack_status.find("PROGRESS") == -1:
                break
            time.sleep(5)
Ejemplo n.º 7
0
class TestCloudformationConnection(unittest.TestCase):
    def setUp(self):
        self.connection = CloudFormationConnection()
        self.stack_name = 'testcfnstack' + str(int(time.time()))

    def test_large_template_stack_size(self):
        # See https://github.com/boto/boto/issues/1037
        body = self.connection.create_stack(
            self.stack_name,
            template_body=json.dumps(BASIC_EC2_TEMPLATE),
            parameters=[('Parameter1', 'initial_value'),
                        ('Parameter2', 'initial_value')])
        self.addCleanup(self.connection.delete_stack, self.stack_name)

        # A newly created stack should have events
        events = self.connection.describe_stack_events(self.stack_name)
        self.assertTrue(events)

        # No policy should be set on the stack by default
        policy = self.connection.get_stack_policy(self.stack_name)
        self.assertEqual(None, policy)

        # Our new stack should show up in the stack list
        stacks = self.connection.describe_stacks(self.stack_name)
        stack = stacks[0]
        self.assertEqual(self.stack_name, stack.stack_name)
        
        params = [(p.key, p.value) for p in stack.parameters]
        self.assertEquals([('Parameter1', 'initial_value'),
                           ('Parameter2', 'initial_value')], params)
        
        for _ in range(30):
            stack.update()
            if stack.stack_status.find("PROGRESS") == -1:
                break
            time.sleep(5)
        
        body = self.connection.update_stack(
             self.stack_name,
             template_body=json.dumps(BASIC_EC2_TEMPLATE),
             parameters=[('Parameter1', '', True),
                         ('Parameter2', 'updated_value')])
        
        stacks = self.connection.describe_stacks(self.stack_name)
        stack = stacks[0]
        params = [(p.key, p.value) for p in stacks[0].parameters]
        self.assertEquals([('Parameter1', 'initial_value'),
                           ('Parameter2', 'updated_value')], params)

        # Waiting for the update to complete to unblock the delete_stack in the
        # cleanup.
        for _ in range(30):
            stack.update()
            if stack.stack_status.find("PROGRESS") == -1:
                break
            time.sleep(5)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def getCloudFormationConnection (awsAccessKey, awsSecretKey):
    cloudFormationConnection = CloudFormationConnection(awsAccessKey, awsSecretKey)
    return cloudFormationConnection
Ejemplo n.º 10
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'],
Ejemplo n.º 11
0
 def setUp(self):
     self.connection = CloudFormationConnection()
     self.stack_name = 'testcfnstack' + str(int(time.time()))
Ejemplo n.º 12
0
'''
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)
Ejemplo n.º 13
0
 def setUp(self):
     self.connection = CloudFormationConnection()
     self.stack_name = 'testcfnstack' + str(int(time.time()))