def create_monitor_instance(stackName, client, layerName='Monitor',
                        hostname=None):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    layerId = layerId_from_stackId_and_name(stackId, layerName)
    if layerId is None:
        print("Can't find layer %s in stack %s; nothing done" %
              (layerName, stackName))
        return False

    host_name = 'monitor'
    try:
        result = client.create_instance(

                  # Required parameters
                  StackId=stackId,
                  LayerIds=[layerId],
                  InstanceType='t2.micro',

                  # Optional parameters
                  Hostname = host_name,
                  # SshKeyName='string',
                  Architecture = 'x86_64',
                  )
        print("instance in layer %s of stack %s created" %
              (layerName, stackName))
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False
    return True
Exemple #2
0
def create_db_layer(stackName, client):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    try:
        result = client.create_layer(
            # Required parameters
            StackId=stackId,
            Type='db-master',
            Name='MySQL DB',
            Shortname='MySQL DB',

            # Optional parameters
            Attributes={
                'MysqlRootPassword': '******',
                'MysqlRootPasswordUbiquitous': 'true',
            },
            CustomRecipes={
                'Setup': ['mash::devpkgs', 'mash::dbsetup'],
            },
        )

        print("DB layer in stack %s created" % stackName)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False

    return True
def create_db_layer(stackName, client):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    try:
        result = client.create_layer(
            # Required parameters
            StackId=stackId,
            Type='db-master',
            Name='MySQL DB',
            Shortname='MySQL DB',

            # Optional parameters
            Attributes={
                'MysqlRootPassword' : 'secret',
                'MysqlRootPasswordUbiquitous': 'true',
                },
            CustomRecipes =  {
                'Setup': ['mash::devpkgs', 'mash::dbsetup'],
                },

            )

        print("DB layer in stack %s created" % stackName)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False

    return True
def create_app_layer(stackName, client):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    try:
        layerName = 'PHP App Servers'
        result = client.create_layer(
            # Required parameters
            StackId=stackId,
            Type = 'php-app',
            Name = layerName,
            Shortname = layerName,

            # Optional parameters
            CustomRecipes =  {
                'Setup': [   'mash::devpkgs',
                             'mash::phpcomposer',
                             'mash::cachetsetup'],
                }
            )
        layerId = layerId_from_stackId_and_name(stackId, layerName)
        client.set_load_based_auto_scaling(LayerId=layerId)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False
    return True
def create_app_layer(stackName, client):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    try:
        layerName = 'PHP App Servers'
        result = client.create_layer(
            # Required parameters
            StackId=stackId,
            Type='php-app',
            Name=layerName,
            Shortname=layerName,

            # Optional parameters
            CustomRecipes={
                'Setup':
                ['mash::devpkgs', 'mash::phpcomposer', 'mash::cachetsetup'],
            })
        layerId = layerId_from_stackId_and_name(stackId, layerName)
        client.set_load_based_auto_scaling(LayerId=layerId)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False
    return True
def create_monitor_layer(stackName, client):
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    try:
        result = client.create_layer(
            # Required parameters
            StackId=stackId,
            Type='custom',  # consider monitoring-master
            Name='Monitor',
            Shortname='monitor',

            # Optional parameters
            CustomRecipes =  {
                'Setup': ['mash::devpkgs'],
                },
            )

        print("Monitor layer in stack %s created" % stackName)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False

    return True
def create_app_instance(stackName,
                        client,
                        layerName='PHP App Servers',
                        hostname=None,
                        availabilityZone='us-east-1a'):
    global LAST_APP_NUM
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    layerId = layerId_from_stackId_and_name(stackId, layerName)
    if layerId is None:
        print("Can't find layer %s in stack %s; nothing done" %
              (layerName, stackName))
        return False

    host_name = 'cachet-app%d' % LAST_APP_NUM
    try:
        result = client.create_instance(

            # Required parameters
            StackId=stackId,
            LayerIds=[layerId],
            InstanceType='t2.micro',

            # Optional parameters
            Hostname=host_name,
            # SshKeyName='string',
            Architecture='x86_64',
            AvailabilityZone=availabilityZone,
        )
        print("host %s created" % host_name)
        LAST_APP_NUM += 1
        instanceId = result['InstanceId']
        print(result)
    except botocore.exceptions.ClientError as e:
        print(e)
        return False
    return True
def create_app_instance(stackName, client, layerName='PHP App Servers',
                        hostname=None):
    global LAST_APP_NUM
    stackId = stackId_from_name(stackName)
    if stackId is None:
        print("Can't find stack %s; nothing done" % stackName)
        return False

    layerId = layerId_from_stackId_and_name(stackId, layerName)
    if layerId is None:
        print("Can't find layer %s in stack %s; nothing done" %
              (layerName, stackName))
        return False

    host_name = 'cachet-app%d' % LAST_APP_NUM
    try:
        result = client.create_instance(

                  # Required parameters
                  StackId=stackId,
                  LayerIds=[layerId],
                  InstanceType='t2.micro',

                  # Optional parameters
                  Hostname = host_name,
                  # SshKeyName='string',
                  Architecture = 'x86_64',
                  )
        LAST_APP_NUM += 1
        instanceId = result['InstanceId']
        print("instance %s in layer %s of stack %s created" %
              (instanceId, layerName, stackName))
        register_app_instance(instanceId, elb_client)
        print(result)
    except botocore.exceptions.ClientError as e:
        print e
        return False
    return True
Exemple #9
0
if not (1 <= len(sys.argv) <= 2):
    print("""usage:
%s [*StackName*]

Delete all OpsWorks layers in stack *StackName*. If no
*StackName* is given we use BotoTest
""" % os.path.basename(sys.argv[0]))
    sys.exit(1)

stackName = 'BotoTest'
if len(sys.argv) == 2: stackName = sys.argv[1]

if stackName not in stackNames():
    print("Stack %s doesn't exists, nothing done" % stackName)
    sys.exit(2)

stackId = stackId_from_name(stackName)
if stackId is None:
    print("Can't find stack with name %s" % stackName)
    sys.exit(3)

resp = ops_client.describe_layers(StackId=stackId)
count = 0
for layer in resp['Layers']:
    count += 1
    result = ops_client.delete_layer(LayerId=layer['LayerId'])
    print("Layer %s of %s deleted" % (layer['Name'], stackName))
    print(result)
print("Total of %d layer(s) deleted" % count)