Ejemplo n.º 1
0
 def _update(self, service, resource):
     try:
         verb = self.spec["verb"]["update"]
         echo("Start " + ".".join([service, resource, verb]),
              flag=not self.silent)
         _check_api_permissions(service, resource, verb)
         self.output = _execute_api(service,
                                    resource,
                                    verb,
                                    self.spec['data'],
                                    api_version="v1",
                                    output="yaml",
                                    parser={},
                                    silent=self.silent)
         echo("Finish " + ".".join([service, resource, verb]),
              flag=not self.silent)
         echo(f'### {verb} Response ###', flag=not self.silent)
         echo(self.output, flag=not self.silent)
     except Exception as e:
         echo(e, flag=True, err=True)
         echo("Unavailable update field so Skip" +
              ".".join([service, resource, "update"]),
              flag=True,
              err=True,
              terminate=True)
Ejemplo n.º 2
0
 def _exec(self, service, resource):
     try:
         verb = self.spec["verb"]["exec"]
         # echo("Start " + ".".join([service, resource, verb]), flag=not self.silent)
         _check_api_permissions(service, resource, verb)
         self.output = _execute_api(service,
                                    resource,
                                    verb,
                                    self.spec.get("data", {}),
                                    api_version="v1",
                                    output="yaml",
                                    parser={},
                                    silent=self.silent)
         # echo("Finish " + ".".join([service, resource, verb]), flag=not self.silent)
         # echo(f'### {verb} Response ###', flag=not self.silent)
         # echo(self.output, flag=not self.silent)
     except Exception as e:
         raise e
Ejemplo n.º 3
0
def _execute_api(service,
                 resource,
                 verb,
                 params={},
                 api_version='v1',
                 output='yaml',
                 parser=None,
                 silent=False):
    config = get_config()
    _check_api_permissions(service, resource, verb)
    client = _get_client(service, api_version)

    # _call_api can change some data of params so need deepcopy
    # e.g. credential of identity.Token
    response_stream = _call_api(client,
                                resource,
                                verb,
                                copy.deepcopy(params),
                                config=config)

    for response in response_stream:
        if verb in ['list', 'stat', 'analyze']:
            results = response.get('results', [])

            if len(results) == 0:
                return []
            elif len(results) > 0:
                return results
            else:
                Exception()
        elif verb == 'create':
            return response
        elif verb == 'update':
            return response
        else:
            echo("[INFO] Non-standard verb: " + verb, flag=not silent)
            return response