Пример #1
0
class TestOpsWorksConnection(unittest.TestCase):
    def setUp(self):
        self.api = OpsWorksConnection()

    def test_describe_stacks(self):
        response = self.api.describe_stacks()
        self.assertIn('Stacks', response)

    def test_validation_errors(self):
        with self.assertRaises(ValidationException):
            self.api.create_stack('testbotostack', 'us-east-1', 'badarn',
                                  'badarn2')
Пример #2
0
class TestOpsWorksConnection(unittest.TestCase):
    def setUp(self):
        self.api = OpsWorksConnection()

    def test_describe_stacks(self):
        response = self.api.describe_stacks()
        self.assertIn('Stacks', response)

    def test_validation_errors(self):
        with self.assertRaises(ValidationException):
            self.api.create_stack('testbotostack', 'us-east-1',
                                  'badarn', 'badarn2')
Пример #3
0
    def handle(self, *args, **options):
        opsworks = OpsWorksConnection()
        stack_resp = opsworks.describe_stacks()
        stack_id = None
        stack_name = None

        for stack in stack_resp['Stacks']:
            if stack['Name'].startswith('web') and stack['Name'].endswith(
                    options['environment']):
                stack_id = stack['StackId']
                stack_name = stack['Name']
                break
        if not stack_id:
            raise CommandError('Stack does not exist.' %
                               options['environment'])

        # get application
        app_resp = opsworks.describe_apps(stack_id=stack_id)
        app_id = app_resp['Apps'][0]['AppId']
        app_name = app_resp['Apps'][0]['Name']

        # get layer
        for layers in opsworks.describe_layers(stack_id=stack_id)['Layers']:
            if layers['Name'] == 'bots':

                # deploy to the instances of particular layer
                for instance in opsworks.describe_instances(
                        layer_id=layers['LayerId'])['Instances']:
                    custom_json = json.dumps(get_json())
                    comment = "Deploying %s from %s@%s at %s to %s on %s" % (
                        app_name, getpass.getuser(), socket.gethostname(),
                        datetime.now().isoformat(' '), instance['Hostname'],
                        stack_name)

                    deployment = opsworks.create_deployment(
                        stack_id, {'Name': 'deploy'},
                        app_id=app_id,
                        instance_ids=[instance['InstanceId']],
                        custom_json=custom_json,
                        comment=comment)

                    print "https://console.aws.amazon.com/opsworks/home?#/stack/%s/deployments/%s" % (
                        stack_id, deployment['DeploymentId'])
Пример #4
0
    def run(self, *args, **options):
        opsworks = OpsWorksConnection()
        stack_resp = opsworks.describe_stacks()
        stack_id = None
        stack_name = None

        # get web production stack
        for stack in stack_resp['Stacks']:
            if stack['Name'].startswith('web') and stack['Name'].endswith(self.environment):
                stack_id = stack['StackId']
                stack_name = stack['Name']
                break
        if not stack_id:
            raise Exception('Stack does not exist.' % options['environment'])

        # get application
        app_resp = opsworks.describe_apps(stack_id=stack_id)
        app_id = app_resp['Apps'][0]['AppId']
        app_name = app_resp['Apps'][0]['Name']

        # get layer
        for layers in opsworks.describe_layers(stack_id=stack_id)['Layers']:
            if layers['Name'] == 'bots':

                # deploy to the instances of particular layer
                for instance in opsworks.describe_instances(layer_id=layers['LayerId'])['Instances']:
                    custom_json = json.dumps(get_json())
                    comment = "Deploying %s from %s@%s at %s to %s on %s" % (
                        app_name,
                        getpass.getuser(),
                        socket.gethostname(),
                        datetime.now().isoformat(' '),
                        instance['Hostname'],
                        stack_name)

                    deployment = opsworks.create_deployment(stack_id, {'Name': 'deploy'}, app_id=app_id,
                        instance_ids=[instance['InstanceId']], custom_json=custom_json, comment=comment)

                    print "https://console.aws.amazon.com/opsworks/home?#/stack/%s/deployments/%s" % (stack_id, deployment['DeploymentId'])
Пример #5
0
from boto.opsworks.layer1 import OpsWorksConnection

command = "execute_recipes"
opsworks = OpsWorksConnection()
stackName = u'CIC-InnovationService01'

# set deploymentCommand
deploymentCommand = {'Name': '%s' % command}
deploymentCommand['Name'] = 'execute_recipes'
deploymentCommand['Args'] = {"recipes": ["git::sync_crawler"]}

# get stackId
desc_stacks = opsworks.describe_stacks()
stackId = u'None'
for loop in desc_stacks[u'Stacks']:
    if loop[u'Name'] == stackName:
        stackId = loop[u'StackId']
if stackId == u'None':
    print("Error: stackName not found")

# execute recipes
opsworks.create_deployment(stack_id=stackId, command=deploymentCommand)
Пример #6
0
from boto.opsworks.layer1 import OpsWorksConnection

command = "execute_recipes"
opsworks = OpsWorksConnection()
stackName = u'CIC-InnovationService01'

# set deploymentCommand
deploymentCommand = {
   'Name': '%s' % command
}
deploymentCommand['Name'] = 'execute_recipes'
deploymentCommand['Args'] = {"recipes":["git::sync_tech-info"]}

# get stackId
desc_stacks = opsworks.describe_stacks()
stackId = u'None'
for loop in desc_stacks[u'Stacks']:
   if loop[u'Name'] == stackName:
      stackId = loop[u'StackId']
if stackId == u'None':
   print ("Error: stackName not found")

# execute recipes
opsworks.create_deployment(stack_id = stackId, command = deploymentCommand )