使用api python客户端获取google云容器集群配置的状态 [英] Get the status of google cloud container cluster provisioning using api python client
问题描述
我正在使用API python客户端为Google云平台创建容器引擎集群。我已成功完成容器创建,现在我需要应用一些yaml配置,但在应用任何kubernetes yaml配置之前,应该配置集群,否则将配置kubernetes API不可用。
我需要在一个请求中同时执行两个操作(容器创建和应用yaml配置)。
如何使用api获取集群的供应状态?
以下是我尝试过的:
创建群集后:
来自views.py:
print('获取集群配置....')
cc = subprocess.call(
'gcloud container clusters get-credentials'+ deployment.deploymentName.lower()+'--zone'+ deployment.region + '--project'+ deployment.project,
shell = True)
print(cc)
while cc == 1:
cc = subprocess.call(
'gcloud container clusters get-credentials'+ deployment.deploymentName.lower()+'--zone'+ deployment.region +'--project'+ deployment.project,
shell = True)
print (cc)
请帮助我!
在此先感谢!
这就是我在代码中所做的:
如果您有凭证问题,请运行:
gcloud beta auth application-default login
进口时间
进口googleapiclient.discovery
服务= googleapiclient.discovery.build('container','v1')
clusters_resource = service.projects()。zones()。clusters()
operations_resource = service.projects()。zones()。operations()
$ b $ def create_cluster(project_id ,zone,config,async = False):
req = clusters_resource.create(projectId = project_id,zone = zone,body = config)
operation = req.execute()
如果是异步的:
return
while operation ['status'] =='RUNNING':
time.sleep(1)
req = operations_resource.get projectIid = zone_zone,operationId = operation ['name'])
operation = req.execute()
return operation ['status'] =='DONE'
I'm creating a container engine cluster using API python client for google cloud platform.I have done with container creation successfully, Now I need to apply some yaml configurations but before applying any kubernetes yaml configurations the cluster should be provisioned otherwise kubernetes API not available. I need to do both(Container creation & Apply yaml configs) things in a single request. How can i get the provision status of a cluster using api?
Here's what i have tried:
After cluster creation: From views.py:
print('Fetching Cluster configs ....')
cc = subprocess.call(
'gcloud container clusters get-credentials ' + deployment.deploymentName.lower() + ' --zone ' + deployment.region + ' --project ' + deployment.project,
shell=True)
print(cc)
while cc == 1:
cc = subprocess.call(
'gcloud container clusters get-credentials ' + deployment.deploymentName.lower() + ' --zone ' + deployment.region + ' --project ' + deployment.project,
shell=True)
print(cc)
Help me, please!
Thanks in Advance!
This is how I do in my code:
"""
If you have a credentials issue, run:
gcloud beta auth application-default login
"""
import time
import googleapiclient.discovery
service = googleapiclient.discovery.build('container', 'v1')
clusters_resource = service.projects().zones().clusters()
operations_resource = service.projects().zones().operations()
def create_cluster(project_id, zone, config, async=False):
req = clusters_resource.create(projectId=project_id, zone=zone, body=config)
operation = req.execute()
if async:
return
while operation['status'] == 'RUNNING':
time.sleep(1)
req = operations_resource.get(projectId=project_id, zone=zone, operationId=operation['name'])
operation = req.execute()
return operation['status'] == 'DONE'
这篇关于使用api python客户端获取google云容器集群配置的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!