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
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
def load_service_from_json(filename=None): """ return a service object from ymir-style service.json file. when filename is not given it will be guessed based on cwd. """ from ymir.version import __version__ report('aws profile', os.environ.get('AWS_PROFILE', 'default')) report('ymir', 'version {0}'.format(__version__)) service_json_file = filename or util.get_or_guess_service_json_file() report('ymir', 'service.json is {0}'.format(util.unexpand(service_json_file))) return _load_service_from_json_helper( service_json_file=service_json_file, service_json=load_json(service_json_file))
def load_service_from_json(filename=None): """ return a service object from ymir-style service.json file. when filename is not given it will be guessed based on cwd. """ from ymir.version import __version__ report('aws profile', os.environ.get('AWS_PROFILE', 'default')) report('ymir', 'version {0}'.format(__version__)) service_json_file = filename or util.get_or_guess_service_json_file() report('ymir', 'service.json is {0}'.format( util.unexpand(service_json_file))) return _load_service_from_json_helper( service_json_file=service_json_file, service_json=load_json(service_json_file))