Beispiel #1
0
    def _do_api(self):
        if self._debug_:
            pp(csite=self._csite_,
               func=self._func_,
               yaml=self.twcc._yaml_fn_,
               res_type=self.res_type)

            if not isNone(self.url_dic):
                pp(url_dic=self.url_dic)
            if not isNone(self.data_dic):
                pp(data_dic=self.data_dic)

        res = self.twcc.doAPI(
            site_sn=self._csite_,
            key_tag=self._api_key_,
            func=self._func_,
            url_dict=self.url_dic if not isNone(self.url_dic) else None,
            data_dict=self.data_dic if not isNone(self.data_dic) else None,
            http=self.http_verb,
            url_ext_get=self.ext_get,
            res_type=self.res_type)

        if self._debug_:
            pp(res=res)

        return res
Beispiel #2
0
 def _chkSite_(self):
     if isNone(self._csite_):
         raise ValueError("No site value.")
     elif not self._csite_ in self.getSites():
         raise ValueError("Site value is not valid. {0}".format(
             self._csite_))
     else:
         return True
Beispiel #3
0
 def list(describe):
     key_info = KeyPairFun.keypair_data_info()
     if not isNone(describe):
         table_layout(' {} Info '.format(describe),
                      key_info.queryById(describe))
     else:
         #pp(show_list = key_info.list())
         table_layout(' KeyPairs Info ', key_info.list())
Beispiel #4
0
def list_all_img(solution_name):
    print("NOTE: This operation will take 1~2 mins.")
    a = solutions()
    if isNone(solution_name):
        cntrs = [(cntr['name'], cntr['id']) for cntr in a.list() if not cntr['id'] in block_set]
    else:
        cntrs = [(cntr['name'], cntr['id']) for cntr in a.list() if not cntr['id'] in block_set and cntr['name'].lower()==solution_name.lower()]

    sol_list = sites.getSolList(name_only=True)
    base_site = sites(debug=False)
    output = []
    for (sol_name, sol_id) in cntrs:
        output.append( {"sol_name":sol_name,
            "sol_id":sol_id,
            "images":list(set(base_site.getAvblImg(sol_id, sol_name)))} )

    table_layout("img", output, ['sol_name', 'sol_id', 'images'])
Beispiel #5
0
    def doAPI(self,
              site_sn=None,
              api_host="_DEF_",
              key_tag=None,
              api_key="_DEF_",
              ctype="application/json",
              func="_DEF_",
              url_dict=None,
              data_dict=None,
              url_ext_get=None,
              http='get',
              res_type='json'):

        if not res_type in self.res_type_valid:
            raise ValueError(
                "Response type Error:'{0}' is not valid, available options: {1}"
                .format(res_type, ", ".join(self.res_type_valid)))

        if not self.isFunValid(func):
            raise ValueError("Function for:'{0}' is not valid".format(func))
        if not http in set(self.valid_http_verb[func]):
            raise ValueError("http verb:'{0}' is not valid".format(http))

        t_url = self.mkAPIUrl(site_sn, api_host, func, url_dict=url_dict)
        t_header = self.mkHeader(site_sn, key_tag, api_host, api_key, ctype)

        if not isNone(url_ext_get):
            t_url += "?"
            t_url_tmp = []
            for param_key in url_ext_get.keys():
                t_url_tmp.append("{0}={1}".format(param_key,
                                                  url_ext_get[param_key]))
            t_url += "&".join(t_url_tmp)

        res = self._api_act(t_url, t_header, t_data=data_dict, mtype=http)
        if res_type in self.res_type_valid:
            if res_type == 'json':
                return res[0].json()
            elif res_type == 'txt':
                return res[0].content
Beispiel #6
0
 def delete_keypair(ctx, info):
     if not isNone(info):
         key_info = KeyPairFun.keypair_data_info()
         pp(show_list=key_info.delete(info))
     else:
         print(ctx.get_help())
Beispiel #7
0
 def list(describe):
     acls_info = AclsFun.acls_auth()
     if not isNone(describe):
         table_layout(' Acls Info ', acls_info.queryById(describe))
     else:
         pp(show_list=acls_info.list())