如何调用rancher2 api

如何调用rancher2 api
强烈推介IDEA2021.1.3破解激活,IntelliJ IDEA 注册码,2021.1.3IDEA 激活码  

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说如何调用rancher2 api,希望能够帮助大家进步!!!

首先创建一个api key 获取api&key的官方文档,直接进入rancher的ui界面获取

点击下图红框获取key

在这里插入图片描述

点击添加key按钮,作用范围不要选择,然后点击创建

在这里插入图片描述

创建好会给我们一个用户api key信息,需要把里面的信息记录下来

在这里插入图片描述

然后我们可以根据上面的信息请求

这里使用的是python脚本请求

import requests
import pprint
url = 'https://192.168.11.166/v3'
headers = {
   "Accept":"application/json",
           "Authorization":"Bearer token-l2p4z:kcdj2rgkhj24csrqblrdtrvmq5jtskglgcc86dtjh2kzlzhb6k6c2w"}
res = requests.get(url, headers=headers, verify=False)
res = res.json()
pprint.pprint(res)

访问这个路由会返回所有的restful格式的api。这里是关于api restful一些文档

{
   'apiVersion': {
   'group': 'management.cattle.io',
                'path': '/v3',
                'version': 'v3'},
 'baseType': 'apiRoot',
 'links': {
   'authConfigs': 'https://192.168.11.166/v3/authconfigs',
           'catalogs': 'https://192.168.11.166/v3/catalogs',
           'cloudCredentials': 'https://192.168.11.166/v3/cloudcredentials',
           'clusterAlertGroups': 'https://192.168.11.166/v3/clusteralertgroups',
           'clusterAlertRules': 'https://192.168.11.166/v3/clusteralertrules',
           'clusterAlerts': 'https://192.168.11.166/v3/clusteralerts',
           'clusterCatalogs': 'https://192.168.11.166/v3/clustercatalogs',
           'clusterLoggings': 'https://192.168.11.166/v3/clusterloggings',
           'clusterMonitorGraphs': 'https://192.168.11.166/v3/clustermonitorgraphs',
           'clusterRegistrationTokens': 'https://192.168.11.166/v3/clusterregistrationtokens',
           'clusterRoleTemplateBindings': 'https://192.168.11.166/v3/clusterroletemplatebindings',
           'clusters': 'https://192.168.11.166/v3/clusters',
           'composeConfigs': 'https://192.168.11.166/v3/composeconfigs',
           'dynamicSchemas': 'https://192.168.11.166/v3/dynamicschemas',
           'etcdBackups': 'https://192.168.11.166/v3/etcdbackups',
           'globalRoleBindings': 'https://192.168.11.166/v3/globalrolebindings',
           'globalRoles': 'https://192.168.11.166/v3/globalroles',
           'groupMembers': 'https://192.168.11.166/v3/groupmembers',
           'groups': 'https://192.168.11.166/v3/groups',
           'kontainerDrivers': 'https://192.168.11.166/v3/kontainerdrivers',
           'ldapConfigs': 'https://192.168.11.166/v3/ldapconfigs',
           'listenConfigs': 'https://192.168.11.166/v3/listenconfigs',
           'managementSecrets': 'https://192.168.11.166/v3/managementsecrets',
           'monitorMetrics': 'https://192.168.11.166/v3/monitormetrics',
           'multiClusterAppRevisions': 'https://192.168.11.166/v3/multiclusterapprevisions',
           'multiClusterApps': 'https://192.168.11.166/v3/multiclusterapps',
           'nodeDrivers': 'https://192.168.11.166/v3/nodedrivers',
           'nodePools': 'https://192.168.11.166/v3/nodepools',
           'nodeTemplates': 'https://192.168.11.166/v3/nodetemplates',
           'nodes': 'https://192.168.11.166/v3/nodes',
           'notifiers': 'https://192.168.11.166/v3/notifiers',
           'podSecurityPolicyTemplateProjectBindings': 'https://192.168.11.166/v3/podsecuritypolicytemplateprojectbindings',
           'podSecurityPolicyTemplates': 'https://192.168.11.166/v3/podsecuritypolicytemplates',
           'preferences': 'https://192.168.11.166/v3/preferences',
           'principals': 'https://192.168.11.166/v3/principals',
           'projectAlertGroups': 'https://192.168.11.166/v3/projectalertgroups',
           'projectAlertRules': 'https://192.168.11.166/v3/projectalertrules',
           'projectAlerts': 'https://192.168.11.166/v3/projectalerts',
           'projectCatalogs': 'https://192.168.11.166/v3/projectcatalogs',
           'projectLoggings': 'https://192.168.11.166/v3/projectloggings',
           'projectMonitorGraphs': 'https://192.168.11.166/v3/projectmonitorgraphs',
           'projectNetworkPolicies': 'https://192.168.11.166/v3/projectnetworkpolicies',
           'projectRoleTemplateBindings': 'https://192.168.11.166/v3/projectroletemplatebindings',
           'projects': 'https://192.168.11.166/v3/projects',
           'roleTemplates': 'https://192.168.11.166/v3/roletemplates',
           'root': 'https://192.168.11.166/v3',
           'self': 'https://192.168.11.166/v3',
           'settings': 'https://192.168.11.166/v3/settings',
           'subscribe': 'https://192.168.11.166/v3/subscribe',
           'templateVersions': 'https://192.168.11.166/v3/templateversions',
           'templates': 'https://192.168.11.166/v3/templates',
           'tokens': 'https://192.168.11.166/v3/tokens',
           'users': 'https://192.168.11.166/v3/users'},
 'type': 'apiRoot'}


本文来源it小白求知路,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/29160

发表评论