Ejemplo n.º 1
0
def create_parser():
    """
    Creates the argumentPaser
    Returns:
        (ArgumentParser) not yet parsed.
    """
    parser = configuration.BossParser(
        description=
        "Duplicate AMIs with a given ending to another ending, like latest to sprintXX"
    )
    parser.add_bosslet()
    parser.add_argument("ami_ending",
                        help="ami_ending ex: hc1ea3281 or latest")
    parser.add_argument("new_ami_ending", help="new ami ending like: sprint01")

    return parser
Ejemplo n.º 2
0
def create_parser():
    """
    Creates the argumentPaser for the maintenance command.
    Returns:
        (ArgumentParser) not yet parsed.
    """
    parser = configuration.BossParser(
        description="",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=cmd_help)
    parser.add_argument("-yes",
                        "-y",
                        default=False,
                        type=bool,
                        help="Skip, Are you sure? prompt")
    parser.add_argument("cmd",
                        choices=CMDS,
                        help="returns maintenance on or off")
    parser.add_bosslet()

    return parser
Ejemplo n.º 3
0
def create_parser():
    """
    Setup the arg parser.

    Returns:
        (ArgumentParser)
    """
    parser = configuration.BossParser(
        description=
        'Adds collection, experiment, and channel names to S3 channel usage data.',
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument(
        "--quiet",
        "-q",
        action='store_true',
        default=False,
        help='Run the script quietly, no log statements will be displayed.')

    parser.add_bosslet()

    parser.add_argument('input_csv', help='Channel usage CSV file')
    parser.add_argument('output_csv', help='New file with names added')
    return parser
Ejemplo n.º 4
0
            client.update_auto_scaling_group(
                AutoScalingGroupName=asg['AutoScalingGroupName'],
                MinSize=1,
                MaxSize=1,
                DesiredCapacity=1)
        else:
            client.update_auto_scaling_group(
                AutoScalingGroupName=asg['AutoScalingGroupName'],
                MinSize=0,
                MaxSize=0,
                DesiredCapacity=0)


if __name__ == '__main__':
    parser = configuration.BossParser(
        description=
        'Script to scale up or down all EC2 autoscale groups for a BossDB stack.'
    )
    parser.add_bosslet()
    parser.add_argument(
        'mode',
        choices=('up', 'down'),
        help="'up' to set capacities to 1, 'down' to set capacities to 0.")
    parser.add_argument(
        '--asg-only',
        '-a',
        action='store_true',
        help='Only scale down ASG instances, keep cachemanager and bastion up.',
        default=False)
    args = parser.parse_args()
    scale_stack(args)
Ejemplo n.º 5
0
is not changed.

load_lambdas_on_s3() zips spdb, bossutils, lambda, and lambda_utils as found
in boss-manage's submodules and places it on the lambda build server.  Next,
makedomainenv is run on the lambda build server to create the virtualenv for
the lambda function.  Finally, the virutalenv is zipped and uploaded to S3.

update_lambda_code() tells AWS to point the existing lambda function at the
new zip in S3.
"""
import alter_path
from lib import configuration
from lib.lambdas import load_lambdas_on_s3, update_lambda_code

if __name__ == '__main__':
    parser = configuration.BossParser(
        description='Script for updating lambda function code. ' +
        'To supply arguments from a file, provide the filename prepended with an `@`.',
        fromfile_prefix_chars='@')
    parser.add_bosslet()
    parser.add_argument('--refresh-only',
                        '-r',
                        action='store_true',
                        help='Tell AWS to just reload the lambdas from S3')

    args = parser.parse_args()

    if not args.refresh_only:
        load_lambdas_on_s3(args.bosslet_config)
    update_lambda_code(args.bosslet_config)
Ejemplo n.º 6
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Download the existing multilambda.domain.zip from the S3 bucket.  Useful when
developing and small changes need to be made to a lambda function, but a full
rebuild of the entire zip file isn't required.
"""

import alter_path
from lib import configuration
from lib.lambdas import download_lambda_zip

if __name__ == '__main__':
    parser = configuration.BossParser(
        description='Script for downloading lambda ' +
        'function code from S3. To supply arguments ' +
        'from a file, provide the filename prepended ' + 'with an `@`.',
        fromfile_prefix_chars='@')
    parser.add_bosslet()
    parser.add_argument('lambda_name')
    parser.add_argument('--save-path',
                        '-p',
                        default='.',
                        help='Where to save the lambda zip file.')

    args = parser.parse_args()

    download_lambda_zip(args.bosslet_config, args.lambda_name, args.save_path)
Ejemplo n.º 7
0
    # Use a seperate top level key in top.sls for AMIs?
    # Use a seperate top level key to say which AMIs to not build using packer.py
    #config_file = repo_path("salt_stack", "salt", "top.sls")
    #with open(config_file, 'r') as fh:
    #    top = yaml.load(fh.read())
    #    configs = [k for k in top['base']]
    #    print(configs)

    config_help_names = list(CONFIGS)
    config_help_names.append("all")
    config_help_names.append("lambda")
    config_help = create_help("config is on of the following: ('all' will build all except 'lambda' and 'backup')", config_help_names)

    parser = configuration.BossParser(description = "Script the building of machines images using Packer and SaltStack",
                                      formatter_class=argparse.RawDescriptionHelpFormatter,
                                      epilog=config_help)
    parser.add_argument("--single-thread",
                        action = "store_true",
                        default = False,
                        help = "Only build one config at a time. (default: Build all configs at the same time)")
    parser.add_argument("--force", "-f",
                        action = "store_true",
                        default = False,
                        help = "Override any existing AMI with the same name")
    parser.add_argument("--ami-version",
                        metavar = "<ami-version>",
                        default = 'h' + git_hash[:8],
                        help = "The AMI version for the machine image(s). (default: First 8 characters of the git SHA1 hash)")
    parser.add_argument("--base-ami",
                        metavar = "<base-ami>",
Ejemplo n.º 8
0
        del self.ingress[name]

    def add_ingress(self, name, cidr):
        if name in self.ingress:
            self.remove_ingress(name)

        resp = self.client.authorize_security_group_ingress(IpPermissions = [{
                                                                'FromPort': 22, 'ToPort': 22, 'IpProtocol': 'tcp',
                                                                'IpRanges': [{'CidrIp': cidr, 'Description': name}],
                                                                }],
                                                            GroupId = self.sg_id)

        self.ingress[name] = cidr

if __name__ == '__main__':
    parser = configuration.BossParser(description = 'Script to update the Security Group with your current IP address')
    parser.add_bosslet()
    parser.add_argument('--vpc',
                        default = 'Test-VPC',
                        help = 'The name of the VPC in which the SG resides')
    parser.add_argument('--sg',
                        default = 'SSH From Home',
                        help = 'The name of the SG to work with')
    parser.add_argument('--list',
                        action = 'store_true',
                        help = 'List currently configured ingress rules')
    parser.add_argument('--rm',
                        action = 'store_true',
                        help = 'Remove the given ingress rule')
    parser.add_argument('name',
                        help = 'The unique name for the SG entry for your address')
                sfn.start_execution(stateMachineArn=arn, input=json.dumps(body))
                wait_secs += spacing
            except botocore.exception.ClientError as ex:
                print('Failed to start Index.IdWriter: {}'.format(ex))
                continue

            try:
                sqs.delete_message(QueueUrl=queue_url, ReceiptHandle=msg['ReceiptHandle'])
            except:
                print('Failed to delete message {} from queue'.format(
                    msg['MessageId']))
                continue


if __name__ == '__main__':
    parser = configuration.BossParser(description='Script for retrying Index.IdWriters that failed' + 
                                      'To supply arguments from a file, provide the filename prepended with an `@`.',
                                      fromfile_prefix_chars = '@')
    parser.add_bosslet()
    parser.add_argument('wait_secs',
                        nargs='?',
                        type=int,
                        default=10,
                        help='# seconds to space starting of step functions (default: 10)')

    args = parser.parse_args()

    start(args.bosslet_config, args.wait_secs)
    print('Done.')

Ejemplo n.º 10
0
        prompt = input
    else:
        prompt = getpass.getpass

    while True:
        initial = prompt('Password: '******'Verify: ')
        if initial == confirm:
            return initial
        else:
            print("Passwords don't match")
            print()


if __name__ == '__main__':
    parser = configuration.BossParser(
        description="Script to reset the password for an IAM user")
    parser.add_argument(
        "--disable-reset",
        action="store_true",
        help="Disable the need to reset the password on next login")
    parser.add_bosslet()
    parser.add_argument("iam_user", help="Name of the IAM User account")

    args = parser.parse_args()

    iam = args.bosslet_config.session.resource('iam')
    profile = iam.LoginProfile(args.iam_user)

    try:
        profile.create_date
    except iam.meta.client.exceptions.NoSuchEntityException:
Ejemplo n.º 11
0
            console.debug("\tAlert level: {:,}".format(threshold))
            alarm_parms['AlarmName'] = "Billing_{}_Acc#_{}".format(str(threshold), str(self.bosslet_config.ACCOUNT_ID))
            alarm_parms['AlarmDescription'] = "Alarm when spending reaches {:,}".format(threshold)
            alarm_parms['Threshold'] = float(threshold)
            response = self.client_cw.put_metric_alarm(**alarm_parms)

class AlertList(SubscriptionList):
    def __init__(self, bosslet_config):
        super().__init__(bosslet_config, bosslet_config.ALERT_TOPIC)


if __name__ == '__main__':
    os.chdir(os.path.abspath(os.path.dirname(__file__)))

    parser = configuration.BossParser(description="This script does some initial configuration of a new AWS Account " +
                                                  "to function as theboss.  It should only be run once on an AWS Account.",
                                      formatter_class=argparse.RawDescriptionHelpFormatter,
                                      epilog='one time setup for new AWS Account')
    parser.add_bosslet()
    parser.add_argument('command',
                        choices = ['billing', 'alerts'],
                        help = 'The account setting to configure')
    parser.add_argument('--create',
                        action = 'store_true',
                        help = 'Setup the given setting in the AWS account')
    parser.add_argument('--add',
                        nargs = '+',
                        help = 'Email addresses to add to the target SNS topic')
    parser.add_argument('--rem',
                        nargs = '+',
                        help = 'Email addresses to remove from the target SNS topic')
    parser.add_argument('--ls',
Ejemplo n.º 12
0
import os
import sys

import alter_path
from lib import utils
from lib import aws
from lib import configuration
from lib.ssh import SSHConnection, SSHTarget
from lib.names import AWSNames
from lib.utils import keypair_to_file

if __name__ == "__main__":
    os.chdir(os.path.abspath(os.path.dirname(__file__)))

    parser = configuration.BossParser(
        description=
        "Script to lookup AWS instance names and start an SSH session",
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        "--cmd",
        "-c",
        default=None,
        help="command to run in ssh, if you want to run a command.")
    parser.add_argument(
        "--scp",
        default=None,
        help=
        "Copy file. (Format: 'remote:path local:path' or 'local:path remote:path')"
    )
    parser.add_argument("--user",
                        "-u",
                        default=None,
Ejemplo n.º 13
0
# limitations under the License.
"""
Tell a lambda to reload its code from S3.  

Useful when developing and small changes need to be made to a lambda function, 
but a full rebuild of the entire zip file isn't required.
"""

import alter_path
from lib import configuration
from lib.lambdas import freshen_lambda, lambda_dirs

if __name__ == '__main__':
    parser = configuration.BossParser(
        description="Script for freshening lambda " +
        "function code from S3. To supply arguments " +
        "from a file, provide the filename prepended " + "with an '@'",
        fromfile_prefix_chars='@')
    parser.add_argument(
        '--code',
        action='store_true',
        help='The lambda_name is the name of the lambda directory ' +
        'used to built the code zip. All lambdas that used the ' +
        'code zip will be updated')
    parser.add_bosslet()
    parser.add_argument('lambda_name',
                        help='Name of lambda function to freshen.')

    args = parser.parse_args()

    if args.code:
Ejemplo n.º 14
0
exclude_regex = []


def is_excluded(resource):
    for regex in exclude_regex:
        if regex.match(resource):
            return True
    return False


if __name__ == '__main__':
    os.chdir(os.path.abspath(os.path.dirname(__file__)))

    parser = configuration.BossParser(description="This script is used to cleanup AWS resources that were not " + \
                                                  "automatically cleanned up.",
                                      formatter_class=argparse.RawDescriptionHelpFormatter,
                                      epilog='one time setup for new AWS Account')
    parser.add_bosslet()
    parser.add_argument(
        '--exclude',
        '-e',
        action='append',
        help=
        'Whitelist the given resource(s) from being deleted (supports regex)')
    parser.add_argument('--delete',
                        action='store_true',
                        help='Delete the indicated resources')
    parser.add_argument('--quiet',
                        '-q',
                        action='store_true',
                        help='Suppress warnings')
Ejemplo n.º 15
0
}

if __name__ == '__main__':
    os.chdir(os.path.abspath(os.path.dirname(__file__)))

    def create_help(header, options):
        """Create formated help."""
        return "\n" + header + "\n" + \
               "\n".join(map(lambda x: "  " + x, options)) + "\n"

    commands = list(COMMANDS.keys())
    instructions = list(HELP)
    commands_help = create_help("command supports the following:", instructions)
    
    parser = configuration.BossParser(description = "Script for manipulating the endpoint's RDS instance",
                                      formatter_class=argparse.RawDescriptionHelpFormatter,
                                      epilog=commands_help)
    parser.add_argument("--quiet", "-q",
                        action='store_true',
                        default=False,
                        help='Run the script quietly, no print statements will be displayed.')
    parser.add_bosslet()
    parser.add_argument("command",
                        choices = commands,
                        metavar = "command",
                        help = "Command to execute")
    parser.add_argument("arguments",
                        nargs = "*",
                        help = "Arguments to pass to the command")

    args = parser.parse_args()
Ejemplo n.º 16
0
            self.client.detach_user_policy(UserName=user.name, PolicyArn=arn)

        # Non-default versions
        resp = self.client.list_policy_versions(PolicyArn=arn)
        for version in resp['Versions']:
            if not version['IsDefaultVersion']:
                self.client.delete_policy_version(
                    PolicyArn=arn, VersionId=version['VersionId'])

        # The policy itself
        self.client.delete_policy(PolicyArn=arn)


if __name__ == '__main__':
    parser = configuration.BossParser(
        description="Load Policies, Roles and Groups into and out of AWS",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='Exports and Imports Iam Information')
    parser.add_argument(
        '--names',
        '-n',
        default=DEFAULT_NAMES_FILE,
        help=
        'JSON document containing the whitelist of names that should be exported/imported'
    )
    parser.add_argument(
        '--groups',
        '-g',
        default=DEFAULT_GROUP_FILE,
        help=
        'JSON document where exported data is saved to or data to import is read from'
    )
Ejemplo n.º 17
0
from lib import aws
from lib import configuration
from pathlib import Path

if __name__ == '__main__':

    def create_help(header, options):
        """Create formated help."""
        return "\n" + header + "\n" + \
               "\n".join(map(lambda x: "  " + x, options)) + "\n"

    actions = ["create", "delete"]
    actions_help = create_help("action supports the following:", actions)

    parser = configuration.BossParser(
        description="Script the creation and deletion of keypairs.",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=actions_help)
    parser.add_bosslet()
    parser.add_argument("action",
                        choices=actions,
                        metavar="action",
                        help="Action to execute")
    parser.add_argument("keypairName",
                        metavar="keypairName",
                        help="Name of keypair to manage")
    args = parser.parse_args()

    client = args.bosslet_config.session.client('ec2')

    #Define key pair path
    key_file_path = Path.home() / '.ssh' / (args.keypairName + '.pem')
Ejemplo n.º 18
0
    if response["ResponseMetadata"]["HTTPStatusCode"] != 200:
        print("Failed with HTTPStatusCode: " + response["HTTPStatusCode"])
        return
    if reverse:
        print(
            "ONLINE: Termination and HealthCheck processes are back online for asg: "
            + asg_name_full_name)
    else:
        print(
            "SUSPENDED: Termination and HealthCheck processes are suspended for asg: "
            + asg_name_full_name)


if __name__ == '__main__':
    parser = configuration.BossParser(
        description=
        "Suspend ASG healthchecks and termination processes or enable them again",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument(
        "--reverse",
        "-r",
        action="store_true",
        default=False,
        help=
        "This flag reverses the suspension and puts Termination and HeatlhChecks back online"
    )
    parser.add_hostname(
        help="Hostname of the EC2 instances that the target ASG maintains")

    args = parser.parse_args()
Ejemplo n.º 19
0
from lib.vault import Vault

if __name__ == "__main__":

    def create_help(header, options):
        """Create formated help."""
        return "\n" + header + "\n" + \
               "\n".join(map(lambda x: "  " + x, options)) + "\n"

    commands = ["ssh", "scp", "ssh-cmd", "ssh-tunnel", "ssh-all"]
    commands.extend(vault.COMMANDS.keys())
    commands_help = create_help("command supports the following:", commands)

    parser = configuration.BossParser(
        description=
        "Script creating SSH Tunnels and connecting to internal VMs",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=commands_help)

    parser.add_hostname(private_ip=True)
    parser.add_argument("--user",
                        "-u",
                        default='ubuntu',
                        help="Username of the internal machine")
    parser.add_argument("--port",
                        default=22,
                        type=int,
                        help="Port to connect to on the internal machine")
    parser.add_argument("--local-port",
                        default=None,
                        type=int,