예제 #1
0
 def _check_function_type(self, resource):
     ns = list(resource.keys())[0]
     func = list(resource[ns].keys())[0]
     if tsmacro.Type in resource[ns][func][tsmacro.Properties] and resource[ns][func][tsmacro.Properties][tsmacro.Type] != 'Event':
         raise InvokeContextException("You must provide a Event Type Function")
     runtime = resource[ns][func][tsmacro.Properties][tsmacro.Runtime]
     if (runtime[0:].lower()) not in infor.EVENT_RUNTIME:
         raise InvokeContextException(
             "You must provide a support Runtime,from one of {s_r}".format(s_r=infor.EVENT_RUNTIME))
예제 #2
0
 def _check_function_type(self, resource):
     ns = list(resource.keys())[0]
     func = list(resource[ns].keys())[0]
     if tsmacro.Type not in resource[ns][func][tsmacro.Properties]:
         raise InvokeContextException(
             "You must provide Properties Type in yaml file")
     if resource[ns][func][tsmacro.Properties][tsmacro.Type] != 'HTTP':
         raise InvokeContextException(
             "You must provide a HTTP Type Service")
     runtime = resource[ns][func][tsmacro.Properties][tsmacro.Runtime]
     if (runtime[0:].lower()) not in infor.SERVICE_RUNTIME:
         raise InvokeContextException(
             "You must provide a support Runtime,from one of {s_r}".format(
                 s_r=infor.SERVICE_RUNTIME))
예제 #3
0
    def __enter__(self):
        template_dict = tcsam.tcsam_validate(
            Template.get_template_data(self._template_file))
        resource = template_dict.get(tsmacro.Resources, {})
        ns = None
        if self.namespace is not None:
            ns = resource.get(self.namespace, {})
        else:
            nss = list(resource.keys())
            if len(nss) == 1:
                ns = resource.get(nss[0], None)
        if not ns:
            raise InvokeContextException(
                "You must provide a namespace identifier,default is 'default'")
        try:
            del ns[tsmacro.Type]
        except Exception:
            pass
        self._template_dict = {tsmacro.Resources: ns}
        self._function_provider = ScfFunctionProvider(
            template_dict=self._template_dict)
        self._env_vars = self._get_env_vars(self._env_vars_file)
        self._log_file_fp = self._get_log_file(self._log_file)
        self._debug_context = self._get_debug_context(self._debug_port,
                                                      self._debug_args,
                                                      self._debugger_path)

        self._check_docker()

        return self
예제 #4
0
    def __enter__(self):
        template_dict = Resources(
            Template.get_template_data(self._template_file)).to_json()
        resource = template_dict.get(model.RESOURCE, {})
        ns = None
        if self.namespace is not None:
            ns = resource.get(self.namespace, {})
        else:
            nss = list(resource.keys())
            if len(nss) == 1:
                ns = resource.get(nss[0], None)
        if not ns:
            raise InvokeContextException(
                "You must provide a namespace identifier,default is 'default'")
        if model.TYPE in ns:
            del ns[model.TYPE]
        self._template_dict = {model.RESOURCE: ns}
        self._function_provider = ScfFunctionProvider(
            template_dict=self._template_dict)
        self._env_vars = self._get_env_vars(self._env_vars_file)
        self._log_file_fp = self._get_log_file(self._log_file)
        self._debug_context = self._get_debug_context(self._debug_port,
                                                      self._debug_args,
                                                      self._debugger_path)

        self._check_docker()

        return self
예제 #5
0
    def _check_docker(docker_client=None):
        docker_client = docker_client or docker.from_env()

        try:
            docker_client.ping()
        except Exception as e:
            raise InvokeContextException('Docker not found, please install it. %s' % e)
예제 #6
0
    def _get_env_vars(env_vars_file):
        if env_vars_file is None:
            return None

        try:
            with open(env_vars_file, 'r') as fp:
                return json.load(fp)
        except Exception as e:
            raise InvokeContextException('read environment from file {} failed: {}'.format(env_vars_file, str(e)))
예제 #7
0
    def functions_name(self):
        if self._function_identifier:
            return self._function_identifier

        functions = [f for f in self._function_provider.get_functions()]
        if len(functions) == 1:
            return functions[0].name

        function_names = [f.name for f in functions]

        raise InvokeContextException("You must provide a function identifier (function's Logical ID in the template). "
                                     "Possible options in your template: {}".format(function_names))
예제 #8
0
    def _get_function(self, namespace):
        fun = None
        if self._function:
            fun = namespace.get(self._function, None)
        else:
            funs = list(namespace.keys())
            if len(funs) == 1:
                self._function = funs[0]
                fun = namespace.get(funs[0], None)
        if not fun:
            raise InvokeContextException("You must provide a valid function")

        del fun[tsmacro.Type]
        return fun
예제 #9
0
    def _get_namespace(self, resource):
        ns = None
        if self._namespace:
            ns = resource.get(self._namespace, None)
        else:
            nss = list(resource.keys())
            if len(nss) == 1:
                self._namespace = nss[0]
                ns = resource.get(nss[0], None)
        if not ns:
            raise InvokeContextException("You must provide a valid namespace")

        del ns[tsmacro.Type]
        return ns
예제 #10
0
    def __enter__(self):
        template_dict = Resources(FuncContext().get_template_data(
            self._template_file)).to_json()
        resource = template_dict.get("Resources", {})
        ns = resource.get(self.namespace, {})
        if not ns:
            raise InvokeContextException(
                "You must provide a namespace identifier,default is 'default'")
        if ns.has_key("Type"):
            del ns["Type"]
        self._template_dict = {"Resources": ns}
        self._function_provider = ScfFunctionProvider(
            template_dict=self._template_dict)
        self._env_vars = self._get_env_vars(self._env_vars_file)
        self._log_file_fp = self._get_log_file(self._log_file)
        self._debug_context = self._get_debug_context(self._debug_port,
                                                      self._debug_args,
                                                      self._debugger_path)

        self._check_docker()

        return self