def on_put(self, req, resp, name):
"""
Handles PUT (or "initiate") requests for a Cluster upgrade.
:param req: Request instance that will be passed through.
:type req: falcon.Request
:param resp: Response instance that will be passed through.
:type resp: falcon.Response
:param name: The name of the Cluster being upgraded.
:type name: str
"""
# Make sure the cluster name is valid.
if not util.etcd_cluster_exists(name):
self.logger.info(
'Upgrade PUT requested for nonexistent cluster {0}'.format(
name))
resp.status = falcon.HTTP_404
return
# If the operation is already in progress, return the current
# status with response code 200 OK.
try:
store_manager = cherrypy.engine.publish('get-store-manager')[0]
cluster_upgrade = store_manager.get(ClusterUpgrade.new(name=name))
self.logger.debug('Found ClusterUpgrade for {0}'.format(name))
if not cluster_upgrade.finished_at:
self.logger.debug(
'Cluster {0} upgrade already in progress'.format(name))
resp.status = falcon.HTTP_200
req.context['model'] = cluster_upgrade
return
except:
# This means one doesn't already exist.
pass
# TODO: Move to a poll?
store_manager = cherrypy.engine.publish('get-store-manager')[0]
args = (store_manager.clone(), name, 'upgrade')
p = Process(target=clusterexec, args=args)
p.start()
self.logger.debug('Started upgrade in clusterexecpool for {0}'.format(
name))
cluster_upgrade = ClusterUpgrade.new(
name=name,
status='in_process',
started_at=datetime.datetime.utcnow().isoformat()
)
store_manager = cherrypy.engine.publish('get-store-manager')[0]
store_manager.save(cluster_upgrade)
resp.status = falcon.HTTP_201
req.context['model'] = cluster_upgrade
评论列表
文章目录