Beispiel #1
0
 def __init__(self, template_file, forced=False):
     self.template_file = template_file
     self.check_params()
     template_data = tcsam.tcsam_validate(
         Template.get_template_data(self.template_file))
     self.resources = template_data.get(tsmacro.Resources)
     self.forced = forced
Beispiel #2
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
Beispiel #3
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
Beispiel #4
0
 def __init__(self, template_file, cos_bucket, output_template_file):
     self.template_file = template_file
     self.cos_bucket = cos_bucket
     self.output_template_file = output_template_file
     self.check_params()
     self.resource = Resources(
         Template.get_template_data(self.template_file))
Beispiel #5
0
 def __enter__(self):
     template_dict = Resources(Template.get_template_data(self._template_file)).to_json()
     resource = template_dict.get(model.RESOURCE, {})
     func = self._get_function(self._get_namespace(resource))
     self._runtime = Runtime(func[model.PROPERTY])
     self._debug_context = DebugContext(self._debug_port, self._debug_argv, self._runtime.runtime)
     return self
Beispiel #6
0
    def __enter__(self):
        template_dict = tcsam.tcsam_validate(Template.get_template_data(self._template_file))

        resource = template_dict.get(tsmacro.Resources, {})
        func = self._get_function(self._get_namespace(resource))
        #self._check_function_type(resource)
        self._runtime = Runtime(func.get(tsmacro.Properties, {}))
        self._debug_context = DebugContext(self._debug_port, self._debug_argv, self._runtime.runtime)
        return self
Beispiel #7
0
    def __init__(self, template_file, cos_bucket, output_template_file):
        self.template_file = template_file
        self.cos_bucket = cos_bucket
        self.output_template_file = output_template_file
        self.check_params()

        # self.resource = Resources(Template.get_template_data(self.template_file))
        template_data = tcsam.tcsam_validate(Template.get_template_data(self.template_file))
        self.resource = template_data.get(tsmacro.Resources, {})
Beispiel #8
0
 def __init__(self, template_file, cos_bucket, function, region, deploy_namespace):
     self.template_file = template_file
     self.template_file_dir = ""
     self.cos_bucket = cos_bucket
     self.check_params()
     template_data = tcsam.tcsam_validate(Template.get_template_data(self.template_file))
     self.resource = template_data.get(tsmacro.Resources, {})
     self.function = function
     self.deploy_namespace = deploy_namespace
     self.region = region
Beispiel #9
0
 def __init__(self, template_file, cos_bucket, function, region, deploy_namespace, without_cos, history=None):
     self.template_file = template_file
     self.template_file_dir = ""
     self.cos_bucket = cos_bucket
     self.check_params()
     template_data = tcsam.tcsam_validate(Template.get_template_data(self.template_file))
     self.resource = template_data.get(tsmacro.Resources, {})
     self.function = function
     self.deploy_namespace = deploy_namespace
     self.region = region
     self.without_cos = without_cos
     self.history = history
     self.bucket_name = "scf-deploy-" + self.region
Beispiel #10
0
def logs(name, namespace, region, count, start_time, end_time, duration, failed, tail, no_color):
    """
    \b
    Scf cli can use the logs command to view historical or real-time logs generated by cloud functions.
    \b
    Common usage:
        \b
        * Fetch logs using the function's name
          $ scf logs -n(--name) function
        \b
        * Specify a namespace, the default value is 'default'
          $ scf logs -n function -ns(--namespace) nodefault
        \b
        * Specific time range using the -s (--starttime) and -e (--endtime) options
          $ scf logs -n function -s xxxx-xx-xx 00:00:00 -e xxxx-xx-xx 00:00:10
        \b
        * Specify a duration between starttime and current time(unit:second)
          $ scf logs -n function -d(--duration)  10
        \b
        * Fetch logs that was exceptional
          $ scf logs -n function  -f(--failed)
        \b
        * Specify region of service
          $ scf logs -n function --region ap-guangzhou
    """

    if region and region not in REGIONS:
        raise ArgsException("The region must in %s." % (", ".join(REGIONS)))
    else:
        if name is None:
            try:
                template_data = tcsam.tcsam_validate(Template.get_template_data("template.yaml"))
                resource = template_data.get(tsmacro.Resources, {})
                for ns in resource:
                    if not resource[ns]:
                        continue
                    for func in resource[ns]:
                        if func == tsmacro.Type:
                            continue
                        name = func
                        if name:
                            Operation("In this project, default function name is: %s" % func).information()
                            Operation(
                                "If you want to specify the function name, use --name, like: scf logs --name YourFunctionName").information()
                            break

            except:
                raise InvalidEnvParameters("Function name is unspecif")

        if name is None:
            raise InvalidEnvParameters("Function name is unspecif")

        if duration and (start_time or end_time):
            raise InvalidEnvParameters("Duration is conflict with (start_time, end_time)")

        if tail:
            start = datetime.now()
            end = start + timedelta(days=1)
            if count:
                end = start
                start = end - timedelta(days=1)
        else:
            start, end = _align_time(start_time, end_time, duration)
        client = ScfLogClient(name, namespace, region, failed)
        if tail and count:
            client.fetch_log_tail_c(start.strftime(TM_FORMAT), end.strftime(TM_FORMAT), count, tail)
            return
        if not count:
            count = 10000  # cloudapi limit
        client.fetch_log(start.strftime(TM_FORMAT), end.strftime(TM_FORMAT), count, tail)
Beispiel #11
0
 def __init__(self, template_file, forced=False):
     self.template_file = template_file
     self.check_params()
     self.resource = Resources(Template.get_template_data(self.template_file))
     self.forced = forced
Beispiel #12
0
def validate(template_file):
    '''
    Validate a SCF template.
    '''
    tcsam.tcsam_validate(Template.get_template_data(template_file))
Beispiel #13
0
def validate(template_file):
    '''
    validate a scf template.
    '''
    tcsam.tcsam_validate(Template.get_template_data(template_file))