Esempio n. 1
0
def _load_service_from_json_helper(service_json_file=None,
                                   service_json={},
                                   simple=False):
    """ load service obj from service json """
    from ymir import validation
    from ymir.beanstalk import ElasticBeanstalkService
    from ymir.service import AbstractService
    chosen_schema = yschema._choose_schema(service_json)
    validation.validate(service_json_file, chosen_schema, simple=True)
    # report("ymir","ymir service.json version:")
    report('ymir.api', 'loading service object from description')
    # dynamically create the service instance's class
    dct = dict([[x.upper(), y] for x, y in service_json.items()])
    classname = str(service_json["name"]).lower()
    if chosen_schema == yschema.eb_schema:
        BaseService = ElasticBeanstalkService
    else:
        BaseService = AbstractService
    ServiceFromJSON = type(classname, (BaseService, ), dct)
    obj = ServiceFromJSON(service_root=os.path.dirname(service_json_file))
    obj._schema = chosen_schema
    service_json = _reflect(service_json=service_json, simple=True)
    service_json = set_schema_defaults(service_json, chosen_schema)
    service_json.update(service_json['service_defaults'])
    service_json.update(host=obj._host())
    ServiceFromJSON._template_data = lambda himself, **kargs: service_json
    return obj
Esempio n. 2
0
def _load_service_from_json_helper(service_json_file=None, service_json={}, simple=False):
    """ load service obj from service json """
    from ymir import validation
    from ymir.beanstalk import ElasticBeanstalkService
    from ymir.service import AbstractService
    chosen_schema = yschema._choose_schema(service_json)
    validation.validate(service_json_file, chosen_schema, simple=True)
    # report("ymir","ymir service.json version:")
    report('ymir.api', 'loading service object from description')
    # dynamically create the service instance's class
    dct = dict([
        [x.upper(), y] for x, y in service_json.items()])
    classname = str(service_json["name"]).lower()
    if chosen_schema == yschema.eb_schema:
        BaseService = ElasticBeanstalkService
    else:
        BaseService = AbstractService
    ServiceFromJSON = type(classname, (BaseService,), dct)
    obj = ServiceFromJSON(service_root=os.path.dirname(service_json_file))
    obj._schema = chosen_schema
    service_json = _reflect(service_json=service_json, simple=True)
    service_json = set_schema_defaults(service_json, chosen_schema)
    service_json.update(service_json['service_defaults'])
    service_json.update(host=obj._host())
    ServiceFromJSON._template_data = lambda himself, **kargs: service_json
    return obj
Esempio n. 3
0
def entry(settings=None):
    """ Main entry point """
    parser = get_parser()
    args = parser.parse_args(sys.argv[1:])

    if args.debug:
        args.verbose = 4
    try:
        level = LOG_LEVELS[args.verbose]
    except IndexError:
        raise SystemExit("-vvv is the maximum!")

    logging.basicConfig(
        level=level,
        format="%(levelname)s [%(filename)s:%(lineno)s] %(message)s",
    )
    validate = lambda args: validation.validate(
        args.service_json, simple=False)
    subcommand_map = dict(
        help=parser.print_help,
        eip=ymir_eip,
        security_group=ymir_sg,
        init=ymir_init,
        validate=validate,
        load=ymir_load,
        keypair=ymir_keypair,
        freeze=ymir_freeze,
        shell=ymir_shell,
    )
    logger.debug('log level is: {0}'.format(level))
    if args.subcommand == 'sg':
        args.subcommand = 'security_group'
    if args.subcommand == 'version':
        print 'ymir=={0}'.format(__version__)
        return
    subcommand_map[args.subcommand](args)
Esempio n. 4
0
def entry(settings=None):
    """ Main entry point """
    parser = get_parser()
    args = parser.parse_args(sys.argv[1:])

    if args.debug:
        args.verbose = 4
    try:
        level = LOG_LEVELS[args.verbose]
    except IndexError:
        raise SystemExit("-vvv is the maximum!")

    logging.basicConfig(
        level=level,
        format="%(levelname)s [%(filename)s:%(lineno)s] %(message)s",
    )
    validate = lambda args: validation.validate(args.service_json,
                                                simple=False)
    subcommand_map = dict(
        help=parser.print_help,
        eip=ymir_eip,
        security_group=ymir_sg,
        init=ymir_init,
        validate=validate,
        load=ymir_load,
        keypair=ymir_keypair,
        freeze=ymir_freeze,
        shell=ymir_shell,
    )
    logger.debug('log level is: {0}'.format(level))
    if args.subcommand == 'sg':
        args.subcommand = 'security_group'
    if args.subcommand == 'version':
        print 'ymir=={0}'.format(__version__)
        return
    subcommand_map[args.subcommand](args)