Exemple #1
0
def create_users(emails):
    failed = []
    users = []

    for email in emails:
        username = email.split('@')[0]

        data = {
            'username': username,
            'password': config['default_password'],
            'email': email
        }

        dumped = json.dumps(data, ensure_ascii=False).encode('utf-8')

        resp = requests.post(
            url="{}/register/".format(base_url),
            data=dumped,
            headers={'Content-Type': 'application/json;charset=UTF-8'})

        if resp.status_code == 400:
            failed.append(email)
            LOGGER.error(
                "Failed to create account for email {0}. Response: {1}".format(
                    email, str(resp.json())))

        if resp.status_code == 201:
            users.append(resp.json())
            LOGGER.info("Account successfully created.")

    return users, failed
Exemple #2
0
def main():
    parser = argparse.ArgumentParser('Start a number of CVEL servers')
    parser.add_argument('-a', '--ami_id', help='the AMI id to use')
    parser.add_argument('-i', '--instance_type', required=True, help='the instance type to use')
    parser.add_argument('-c', '--created_by', help='the username to use')
    parser.add_argument('-n', '--name', required=True, help='the instance name to use')
    parser.add_argument('-s', '--spot_price', type=float, help='the spot price to use')
    parser.add_argument('-b', '--bash_script', help='the bash script to use')
    parser.add_argument('-p', '--processes', type=int, default=1, help='the number of processes to run')
    parser.add_argument('-fc', '--frequency_channels', type=int, default=28, help='how many frequency channels per AWS instance')
    parser.add_argument('--force', action='store_true', default=False, help='proceed with a frequency band even if we already have it')

    parser.add_argument('obs_ids', nargs='+', help='the ids of the observation')

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error('The arguments are incorrect: {0}'.format(args))
    else:
        start_servers(
            args['processes'],
            corrected_args['ami_id'],
            corrected_args['user_data'],
            corrected_args['setup_disks'],
            args['instance_type'],
            corrected_args['obs_ids'],
            corrected_args['created_by'],
            args['name'],
            corrected_args['instance_details'],
            corrected_args['spot_price'],
            args['frequency_channels'],
            args['force'])
Exemple #3
0
    def __call__(self):
        """
        Actually run the job
        """
        # Get the name of the volume
        ec2_helper = EC2Helper()
        iops = None
        if self._instance_details.iops_support:
            iops = 500

        zone = ec2_helper.get_cheapest_spot_price(self._instance_type, self._spot_price)
        if zone is not None:
            volume, snapshot_name = ec2_helper.create_volume(self._snapshot_id, zone, iops=iops)
            LOGGER.info('obs_id: {0}, volume_name: {1}'.format(self._obs_id, snapshot_name))
            user_data_mime = self.get_mime_encoded_user_data(volume.id)

            if self._spot_price is not None:
                ec2_helper.run_spot_instance(
                    self._ami_id,
                    self._spot_price,
                    user_data_mime,
                    self._instance_type,
                    volume.id,
                    self._created_by,
                    '{1}-{2}-{0}'.format(self._name, snapshot_name, self._counter),
                    self._instance_details,
                    zone,
                    ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(self._instance_type, self._spot_price))
Exemple #4
0
def main():
    parser = argparse.ArgumentParser('Start a number of CLEAN servers')
    parser.add_argument('-a', '--ami_id', help='the AMI id to use')
    parser.add_argument('-i', '--instance_type', required=True, help='the instance type to use')
    parser.add_argument('-c', '--created_by', help='the username to use')
    parser.add_argument('-n', '--name', required=True, help='the instance name to use')
    parser.add_argument('-s', '--spot_price', type=float, help='the spot price to use')
    parser.add_argument('-b', '--bash_script', help='the bash script to use')
    parser.add_argument('-p', '--processes', type=int, default=1, help='the number of processes to run')
    parser.add_argument('frequencies', nargs='+', help='the frequencies to use (vis_14XX~14YY')

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error('The arguments are incorrect: {0}'.format(args))
    else:
        start_servers(
            args['processes'],
            corrected_args['ami_id'],
            corrected_args['user_data'],
            corrected_args['setup_disks'],
            args['instance_type'],
            args['frequencies'],
            corrected_args['created_by'],
            args['name'],
            corrected_args['instance_details'],
            corrected_args['spot_price'])
Exemple #5
0
def main():
    parser = argparse.ArgumentParser('Start a number of CLEAN servers')
    parser.add_argument('-a', '--ami_id', help='the AMI id to use')
    parser.add_argument('-i', '--instance_type', required=True, help='the instance type to use')
    parser.add_argument('-c', '--created_by', help='the username to use')
    parser.add_argument('-n', '--name', required=True, help='the instance name to use')
    parser.add_argument('-s', '--spot_price', type=float, help='the spot price to use')
    parser.add_argument('-b', '--bash_script', help='the bash script to use')
    parser.add_argument('-e', '--ebs', type=int, help='the size in GB of any EBS volume')
    parser.add_argument('bottom_frequency', help='The bottom frequency')
    parser.add_argument('frequency_range', help='the range of frequencies')
    parser.add_argument('obs_id', help='the observation id')

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error('The arguments are incorrect: {0}'.format(args))
    else:
        start_servers(
            corrected_args['ami_id'],
            corrected_args['user_data'],
            corrected_args['setup_disks'],
            args['instance_type'],
            make_safe_filename(args['obs_id']),
            corrected_args['created_by'],
            args['name'],
            corrected_args['instance_details'],
            corrected_args['spot_price'],
            args['ebs'],
            args['bottom_frequency'],
            args['frequency_range'])
def open_mdb_connection():
    for host in MARIA_DB_CONFIGURATION['hosts']:
        try:
            connection = pymysql.connect(
                user=MARIA_DB_CONFIGURATION['user'],
                password=MARIA_DB_CONFIGURATION['password'],
                database=MARIA_DB_CONFIGURATION['database'],
                host=host,
                cursorclass=pymysql.cursors.DictCursor,
                autocommit=True,
            )
        except:
            if host == MARIA_DB_CONFIGURATION['hosts'][-1]:
                log_str = "Failed to connect to any MariaDB host"
                LOGGER.exception(log_str, exc_info=True)
                raise DBError(log_str)
            else:
                LOGGER.warning(
                    'Failed to connect to MariaDB on host {}. Trying next host.'
                    .format(host))
        else:
            if connection.open:
                LOGGER.debug(
                    'mariadb connection to host {} successful.'.format(host))
                return connection
            else:
                err_str = 'Connection to MariaDB failed.'
                LOGGER.error(err_str)
                raise DBError(err_str)
Exemple #7
0
def create_posts(user):
    access_token, refresh_token = obtain_token_pair(user['username'], config['default_password'])

    num_posts = random.randint(1, config['max_number_of_posts'])

    headers = {
        'Authorization': 'Bearer {}'.format(access_token),
    }

    for i in range(num_posts):
        title = "{0} {1}".format(user['username'], str(i))
        content = "{0} says: {1}".format(user['username'], config['post_content'])

        payload = {
            "title": title,
            "content": content
        }

        resp = requests.post(url="{}/posts/".format(base_url), json=payload, headers=headers)

        if resp.status_code == 401 and resp.json()['code'] == 'token_not_valid':
            LOGGER.warning("{}. Obtaining new token pair...".format(resp.json()['messages'][0]['message']))
            access_token, refresh_token = obtain_token_pair(user['username'], config['default_password'])
            headers = {
                'Authorization': 'Bearer {}'.format(access_token)
            }
            resp = requests.post(url="{}/posts/".format(base_url), json=payload, headers=headers)

        if resp.status_code != 201:
            LOGGER.error("Failed to create post. Response code: {}".format(resp.status_code))
Exemple #8
0
def main():
    parser = argparse.ArgumentParser("Start a number of CLEAN servers")
    parser.add_argument("-a", "--ami_id", help="the AMI id to use")
    parser.add_argument("-i", "--instance_type", required=True, help="the instance type to use")
    parser.add_argument("-c", "--created_by", help="the username to use")
    parser.add_argument("-n", "--name", required=True, help="the instance name to use")
    parser.add_argument("-s", "--spot_price", type=float, help="the spot price to use")
    parser.add_argument("-b", "--bash_script", help="the bash script to use")
    parser.add_argument("-p", "--processes", type=int, default=1, help="the number of processes to run")
    parser.add_argument("snapshots", nargs="+", help="the snapshots to use")

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error("The arguments are incorrect: {0}".format(args))
    else:
        start_server(
            args["processes"],
            corrected_args["ami_id"],
            corrected_args["user_data"],
            corrected_args["setup_disks"],
            args["instance_type"],
            args["snapshots"],
            corrected_args["created_by"],
            args["name"],
            corrected_args["instance_details"],
            corrected_args["spot_price"],
        )
Exemple #9
0
    def __call__(self):
        """
        Actually run the job
        """
        LOGGER.info('frequency_id: {0}'.format(self._frequency_id))
        ec2_helper = EC2Helper()
        zone = ec2_helper.get_cheapest_spot_price(self._instance_type,
                                                  self._spot_price)

        if zone is not None:
            user_data_mime = self.get_mime_encoded_user_data()
            LOGGER.info('{0}'.format(user_data_mime))

            ec2_helper.run_spot_instance(
                self._ami_id,
                self._spot_price,
                user_data_mime,
                self._instance_type,
                None,
                self._created_by,
                '{0}-{1}'.format(self._frequency_id, self._name),
                instance_details=self._instance_details,
                zone=zone,
                ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(
                self._instance_type, self._spot_price))
def detect_wrong_format(pattern_dict: dict, dump_file):
    try:
        type = pattern_dict['type']
    except KeyError:
        LOGGER.error("Introduce a type in the configuration file!")
        sys.exit(1)
    try:
        regex = pattern_dict['regex']
    except KeyError:
        LOGGER.error("Introduce if the pattern is a regex in the configuration file!")
        sys.exit(1)

    if regex:
        handler = PatternHandlerFactoryRegEx(pattern_dict)
    else:
        handler = PatternHandlerFactoryPattern(pattern_dict)

    if dump_file.endswith('.gz'):
        input_file = gzip.open(dump_file, 'rb')
    else:
        input_file = open(dump_file, 'rb')

    output_file = open('ldap_wrong_format.txt', 'w')
    processing_object = processing_object_builder(type, output_file, handler)
    parser = ldap_parser.ParseLDIF(input_file, processing_object)
    parser.parse()
def processing_object_builder(type, output_file, handler):
    if type == 'general':
        return ProblemsDetectorGeneral(output_file, handler)
    elif type == 'lock_submit':
        return SubmitLockDetector(output_file, handler, mariadb_connection=open_mdb_connection())
    else:
        LOGGER.error("Introduce a defined type in the configuration file!")
        sys.exit(1)
Exemple #12
0
 def __init__(self, output_file, handler: PatternHandlerFactory,
              mariadb_connection):
     super().__init__(output_file, handler)
     self.mariadb_connection = mariadb_connection
     try:
         self.query = self.handler.pattern_dict['mariadb_query']
     except KeyError:
         LOGGER.error('Provide a MariaDB query!')
         sys.exit(1)
Exemple #13
0
    def get(self) -> t.Dict[str, t.Any]:
        try:
            rpc_proxy: Pyro4.Proxy = get_health_service_rpc_proxy('pong')
        except LookupError as e:
            LOGGER.error(f"{e}: {traceback.format_exc()}")
            return {'hello': f'error {e}'}
        LOGGER.info(rpc_proxy.dev_pyro4_ping(1, src='duang'))

        with make_service_proxy() as service_proxy:
            LOGGER.info(service_proxy.pong.dev_nameko_ping(1, src='duang'))
        return {'hello': 'world'}
def detect_wrong_format(input_file, pattern):
    """Delete entries in ldap older than limit_days_ago before today
        :param input_file: Ldap dumb file to parse
        :param pattern: Pattern to be detected, it must be defined in config.yml!
    """
    cfg = load_config()
    try:
        cfg[pattern]
    except KeyError:
        LOGGER.error("Pattern not found in the config.yml file!")
        sys.exit(1)
    else:
        detect_ldap_problems.detect_wrong_format(cfg[pattern], input_file)
Exemple #15
0
def start_servers(
        ami_id,
        user_data,
        setup_disks,
        instance_type,
        obs_id,
        created_by,
        name,
        instance_details,
        spot_price,
        ebs,
        bottom_frequency,
        frequency_range):
    LOGGER.info('obs_id: {0}, bottom_frequency: {1}, frequency_range: {2}'.format(obs_id, bottom_frequency, frequency_range))
    ec2_helper = EC2Helper()
    zone = ec2_helper.get_cheapest_spot_price(instance_type, spot_price)

    if zone is not None:
        # Swap size
        if ebs is None:
            swap_size = 1
        else:
            ephemeral_size = instance_details.number_disks * instance_details.size
            swap_size = min(int(ephemeral_size * 0.75), 16)

        user_data_mime = get_mime_encoded_user_data(
            user_data,
            obs_id,
            setup_disks,
            bottom_frequency,
            frequency_range,
            swap_size
        )
        LOGGER.info('{0}'.format(user_data_mime))

        ec2_helper.run_spot_instance(
            ami_id,
            spot_price,
            user_data_mime,
            instance_type,
            None,
            created_by,
            name + '- {0}'.format(obs_id),
            instance_details=instance_details,
            zone=zone,
            ebs_size=ebs,
            number_ebs_volumes=4,
            ephemeral=True)
    else:
        LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(instance_type, spot_price))
Exemple #16
0
def main():
    parser = argparse.ArgumentParser('Start a number of CVEL servers')
    parser.add_argument('-a', '--ami_id', help='the AMI id to use')
    parser.add_argument('-i',
                        '--instance_type',
                        required=True,
                        help='the instance type to use')
    parser.add_argument('-c', '--created_by', help='the username to use')
    parser.add_argument('-n',
                        '--name',
                        required=True,
                        help='the instance name to use')
    parser.add_argument('-s',
                        '--spot_price',
                        type=float,
                        help='the spot price to use')
    parser.add_argument('-b', '--bash_script', help='the bash script to use')
    parser.add_argument('-p',
                        '--processes',
                        type=int,
                        default=1,
                        help='the number of processes to run')
    parser.add_argument('-fc',
                        '--frequency_channels',
                        type=int,
                        default=28,
                        help='how many frequency channels per AWS instance')
    parser.add_argument(
        '--force',
        action='store_true',
        default=False,
        help='proceed with a frequency band even if we already have it')

    parser.add_argument('obs_ids',
                        nargs='+',
                        help='the ids of the observation')

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error('The arguments are incorrect: {0}'.format(args))
    else:
        start_servers(args['processes'], corrected_args['ami_id'],
                      corrected_args['user_data'],
                      corrected_args['setup_disks'], args['instance_type'],
                      corrected_args['obs_ids'], corrected_args['created_by'],
                      args['name'], corrected_args['instance_details'],
                      corrected_args['spot_price'], args['frequency_channels'],
                      args['force'])
Exemple #17
0
def check_args(args):
    """
    Check the arguments and prompt for new ones
    """
    map_args = {}

    if args['obs_ids'] is None:
        return None
    elif len(args['obs_ids']) == 1 and args['obs_ids'][0] == '*':
        map_args['obs_ids'] = OBS_IDS.keys()
    else:
        map_args['obs_ids'] = args['obs_ids']

    if args['instance_type'] is None:
        return None

    if args['name'] is None:
        return None

    instance_details = AWS_INSTANCES.get(args['instance_type'])
    if instance_details is None:
        LOGGER.error('The instance type {0} is not supported.'.format(
            args['instance_type']))
        return None
    else:
        LOGGER.info(
            'instance: {0}, vCPU: {1}, RAM: {2}GB, Disks: {3}x{4}GB, IOPS: {5}'
            .format(args['instance_type'], instance_details.vCPU,
                    instance_details.memory, instance_details.number_disks,
                    instance_details.size, instance_details.iops_support))

    map_args.update({
        'ami_id':
        args['ami_id'] if args['ami_id'] is not None else AWS_AMI_ID,
        'created_by':
        args['created_by']
        if args['created_by'] is not None else getpass.getuser(),
        'spot_price':
        args['spot_price'] if args['spot_price'] is not None else None,
        'user_data':
        get_script(args['bash_script']
                   if args['bash_script'] is not None else BASH_SCRIPT_CVEL),
        'setup_disks':
        get_script(BASH_SCRIPT_SETUP_DISKS),
        'instance_details':
        instance_details,
    })

    return map_args
Exemple #18
0
def check_args(args):
    """
    Check the arguments and prompt for new ones
    """
    map_args = {}

    if args['obs_ids'] is None:
        return None
    elif len(args['obs_ids']) == 1 and args['obs_ids'][0] == '*':
        map_args['obs_ids'] = OBS_IDS.keys()
    else:
        map_args['obs_ids'] = args['obs_ids']

    if args['instance_type'] is None:
        return None

    if args['name'] is None:
        return None

    instance_details = AWS_INSTANCES.get(args['instance_type'])
    if instance_details is None:
        LOGGER.error('The instance type {0} is not supported.'.format(args['instance_type']))
        return None
    else:
        LOGGER.info(
            'instance: {0}, vCPU: {1}, RAM: {2}GB, Disks: {3}x{4}GB, IOPS: {5}'.format(
                args['instance_type'],
                instance_details.vCPU,
                instance_details.memory,
                instance_details.number_disks,
                instance_details.size,
                instance_details.iops_support))

    map_args.update({
        'ami_id': args['ami_id'] if args['ami_id'] is not None else AWS_AMI_ID,
        'created_by': args['created_by'] if args['created_by'] is not None else getpass.getuser(),
        'spot_price': args['spot_price'] if args['spot_price'] is not None else None,
        'user_data': get_script(args['bash_script'] if args['bash_script'] is not None else BASH_SCRIPT_CVEL),
        'setup_disks': get_script(BASH_SCRIPT_SETUP_DISKS),
        'instance_details': instance_details,
    })

    return map_args
Exemple #19
0
def check_args(args):
    """
    Check the arguments and prompt for new ones
    """
    map_args = {}

    if args["snapshots"] is None:
        return None

    if args["instance_type"] is None:
        return None

    if args["name"] is None:
        return None

    instance_details = AWS_INSTANCES.get(args["instance_type"])
    if instance_details is None:
        LOGGER.error("The instance type {0} is not supported.".format(args["instance_type"]))
        return None
    else:
        LOGGER.info(
            "instance: {0}, vCPU: {1}, RAM: {2}GB, Disks: {3}x{4}GB, IOPS: {5}".format(
                args["instance_type"],
                instance_details.vCPU,
                instance_details.memory,
                instance_details.number_disks,
                instance_details.size,
                instance_details.iops_support,
            )
        )

    map_args.update(
        {
            "ami_id": args["ami_id"] if args["ami_id"] is not None else AWS_AMI_ID,
            "created_by": args["created_by"] if args["created_by"] is not None else getpass.getuser(),
            "spot_price": args["spot_price"] if args["spot_price"] is not None else None,
            "user_data": get_script(args["bash_script"] if args["bash_script"] is not None else BASH_SCRIPT_CLEAN_ALL),
            "setup_disks": get_script(BASH_SCRIPT_SETUP_DISKS),
            "instance_details": instance_details,
        }
    )
    return map_args
def start_servers(
        ami_id,
        user_data,
        setup_disks,
        instance_type,
        obs_id,
        created_by,
        name,
        instance_details,
        spot_price):

    snapshot_id = OBS_IDS.get(obs_id)
    if snapshot_id is None:
        LOGGER.warning('The obs-id: {0} does not exist in the settings file')
    else:
        ec2_helper = EC2Helper()
        iops = None
        if instance_details.iops_support:
            iops = 500

        zone = ec2_helper.get_cheapest_spot_price(instance_type, spot_price)
        if zone is not None:
            volume, snapshot_name = ec2_helper.create_volume(snapshot_id, zone, iops=iops)
            LOGGER.info('obs_id: {0}, volume_name: {1}'.format(obs_id, snapshot_name))
            now = datetime.datetime.now()
            user_data_mime = get_mime_encoded_user_data(volume.id, setup_disks, user_data, now.strftime('%Y-%m-%dT%H-%M-%S'))

            if spot_price is not None:
                ec2_helper.run_spot_instance(
                    ami_id,
                    spot_price,
                    user_data_mime,
                    instance_type,
                    volume.id,
                    created_by,
                    '{1}-{0}'.format(name, snapshot_name),
                    instance_details,
                    zone,
                    ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(instance_type, spot_price))
Exemple #21
0
def start_servers(ami_id, user_data, setup_disks, instance_type, obs_id,
                  created_by, name, instance_details, spot_price):

    snapshot_id = OBS_IDS.get(obs_id)
    if snapshot_id is None:
        LOGGER.warning('The obs-id: {0} does not exist in the settings file')
    else:
        ec2_helper = EC2Helper()
        iops = None
        if instance_details.iops_support:
            iops = 500

        zone = ec2_helper.get_cheapest_spot_price(instance_type, spot_price)
        if zone is not None:
            volume, snapshot_name = ec2_helper.create_volume(snapshot_id,
                                                             zone,
                                                             iops=iops)
            LOGGER.info('obs_id: {0}, volume_name: {1}'.format(
                obs_id, snapshot_name))
            now = datetime.datetime.now()
            user_data_mime = get_mime_encoded_user_data(
                volume.id, setup_disks, user_data,
                now.strftime('%Y-%m-%dT%H-%M-%S'))

            if spot_price is not None:
                ec2_helper.run_spot_instance(ami_id,
                                             spot_price,
                                             user_data_mime,
                                             instance_type,
                                             volume.id,
                                             created_by,
                                             '{1}-{0}'.format(
                                                 name, snapshot_name),
                                             instance_details,
                                             zone,
                                             ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(
                instance_type, spot_price))
Exemple #22
0
def main():
    parser = argparse.ArgumentParser('Start a number of CLEAN servers')
    parser.add_argument('-a', '--ami_id', help='the AMI id to use')
    parser.add_argument('-i',
                        '--instance_type',
                        required=True,
                        help='the instance type to use')
    parser.add_argument('-c', '--created_by', help='the username to use')
    parser.add_argument('-n',
                        '--name',
                        required=True,
                        help='the instance name to use')
    parser.add_argument('-s',
                        '--spot_price',
                        type=float,
                        help='the spot price to use')
    parser.add_argument('-b', '--bash_script', help='the bash script to use')
    parser.add_argument('-p',
                        '--processes',
                        type=int,
                        default=1,
                        help='the number of processes to run')
    parser.add_argument('frequencies',
                        nargs='+',
                        help='the frequencies to use (vis_14XX~14YY')

    args = vars(parser.parse_args())

    corrected_args = check_args(args)
    if corrected_args is None:
        LOGGER.error('The arguments are incorrect: {0}'.format(args))
    else:
        start_servers(args['processes'], corrected_args['ami_id'],
                      corrected_args['user_data'],
                      corrected_args['setup_disks'], args['instance_type'],
                      args['frequencies'], corrected_args['created_by'],
                      args['name'], corrected_args['instance_details'],
                      corrected_args['spot_price'])
Exemple #23
0
    def __call__(self):
        """
        Actually run the job
        """
        # Get the name of the volume
        ec2_helper = EC2Helper()
        iops = None
        if self._instance_details.iops_support:
            iops = 500

        zone = ec2_helper.get_cheapest_spot_price(self._instance_type,
                                                  self._spot_price)
        if zone is not None:
            volume, snapshot_name = ec2_helper.create_volume(self._snapshot_id,
                                                             zone,
                                                             iops=iops)
            LOGGER.info('obs_id: {0}, volume_name: {1}'.format(
                self._obs_id, snapshot_name))
            user_data_mime = self.get_mime_encoded_user_data(volume.id)

            if self._spot_price is not None:
                ec2_helper.run_spot_instance(self._ami_id,
                                             self._spot_price,
                                             user_data_mime,
                                             self._instance_type,
                                             volume.id,
                                             self._created_by,
                                             '{1}-{2}-{0}'.format(
                                                 self._name, snapshot_name,
                                                 self._counter),
                                             self._instance_details,
                                             zone,
                                             ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(
                self._instance_type, self._spot_price))
Exemple #24
0
    def __call__(self):
        """
        Actually run the job
        """
        LOGGER.info('frequency_id: {0}'.format(self._frequency_id))
        ec2_helper = EC2Helper()
        zone = ec2_helper.get_cheapest_spot_price(self._instance_type, self._spot_price)

        if zone is not None:
            user_data_mime = self.get_mime_encoded_user_data()
            LOGGER.info('{0}'.format(user_data_mime))

            ec2_helper.run_spot_instance(
                self._ami_id,
                self._spot_price,
                user_data_mime,
                self._instance_type, None,
                self._created_by,
                '{0}-{1}'.format(self._frequency_id, self._name),
                instance_details=self._instance_details,
                zone=zone,
                ephemeral=True)
        else:
            LOGGER.error('Cannot get a spot instance of {0} for ${1}'.format(self._instance_type, self._spot_price))
Exemple #25
0
def start_server(
    processes,
    ami_id,
    user_data,
    setup_disks,
    instance_type,
    snapshot_ids,
    created_by,
    name,
    instance_details,
    spot_price,
):

    LOGGER.info("snapshot_ids: {0}".format(snapshot_ids))
    ec2_helper = EC2Helper()
    zone = ec2_helper.get_cheapest_spot_price(instance_type, spot_price)

    if zone is not None:
        # Get the snapshot details
        connection = ec2_helper.ec2_connection
        snapshot_details = {}
        for snapshot in connection.get_all_snapshots(owner="self"):
            name = snapshot.tags.get("Name")
            if name is None:
                LOGGER.info("Looking at {0} - None".format(snapshot.id))
            elif snapshot.status == "completed":
                LOGGER.info("Looking at {0} - {1}".format(snapshot.id, snapshot.tags["Name"]))
                if snapshot.tags["Name"].endswith("_FINAL_PRODUCTS"):
                    snapshot_details[snapshot.id] = snapshot
            else:
                LOGGER.info(
                    "Looking at {0} - {1} which is {2}".format(snapshot.id, snapshot.tags["Name"], snapshot.status)
                )

        # Create the volumes
        bdm = blockdevicemapping.BlockDeviceMapping()

        # The ephemeral disk
        xvdb = BlockDeviceType()
        xvdb.ephemeral_name = "ephemeral0"
        bdm["/dev/xvdb"] = xvdb

        if instance_details.number_disks == 2:
            xvdc = BlockDeviceType()
            xvdc.ephemeral_name = "ephemeral1"
            bdm["/dev/xvdc"] = xvdc

        # The Scratch space
        for disks in range(0, SCRATCH_DISKS):
            xvd_n = blockdevicemapping.EBSBlockDeviceType(delete_on_termination=True)
            xvd_n.size = int(SCRATCH_DISK_SIZE)  # size in Gigabytes
            xvd_n.volume_type = "gp2"
            last_char = chr(ord("d") + disks)
            bdm["/dev/xvd" + last_char] = xvd_n

        disks = 0
        for snapshot_id in snapshot_ids:
            snapshot_detail = snapshot_details.get(snapshot_id)
            xvd_n = blockdevicemapping.EBSBlockDeviceType(delete_on_termination=True)
            xvd_n.size = int(snapshot_detail.volume_size)  # size in Gigabytes
            xvd_n.volume_type = "gp2"
            xvd_n.snapshot_id = snapshot_id
            last_char = chr(ord("d") + disks + SCRATCH_DISKS)
            bdm["/dev/xvd" + last_char] = xvd_n
            disks += 1

        user_data_mime = get_mime_encoded_user_data(instance_details, setup_disks, user_data)
        LOGGER.info("{0}".format(user_data_mime))

        ec2_helper.run_spot_instance(
            ami_id,
            spot_price,
            user_data_mime,
            instance_type,
            None,
            created_by,
            "BIG Clean",
            instance_details=instance_details,
            zone=zone,
            ephemeral=True,
            bdm=bdm,
        )
    else:
        LOGGER.error("Cannot get a spot instance of {0} for ${1}".format(instance_type, spot_price))
Exemple #26
0
                        kodi(XBMC_dic[IR])
                    elif codeIR[0] in extra_esp_keys:
                        e = ESP()
                        e.Go_parallel(extra_esp_keys[IR])
                    else:
                        logger.info('speaking only ' + IR)
                        Speak(IR)
                last = [IR, datetime.datetime.now()]
        except:
            logger.error('error : ' + str(sys.exc_info()))
            Speak('error in lirc module')
            sleep(2)
        sleep(0.3)


if __name__ == '__main__':
    #    with daemon.DaemonContext():
    try:
        from common import LOGGER, PID
        logger = LOGGER('lirc')
        #            logger = log # compatibility
        logger.info('starting lirc')
        from time import sleep
        from KODI_control import kodi
        PID()
        import lirc
        sockid = lirc.init("test", blocking=False)
        Start()
    except:
        logger.error('error on initiation: ' + str(sys.exc_info()))