本文整理汇总了Python中hackathon.RequiredFeature.load_azure_key_id方法的典型用法代码示例。如果您正苦于以下问题:Python RequiredFeature.load_azure_key_id方法的具体用法?Python RequiredFeature.load_azure_key_id怎么用?Python RequiredFeature.load_azure_key_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackathon.RequiredFeature
的用法示例。
在下文中一共展示了RequiredFeature.load_azure_key_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop_expr
# 需要导入模块: from hackathon import RequiredFeature [as 别名]
# 或者: from hackathon.RequiredFeature import load_azure_key_id [as 别名]
def stop_expr(self, expr_id, force=0):
"""
:param expr_id: experiment id
:param force: 0: only stop container and release ports, 1: force stop and delete container and release ports.
:return:
"""
self.log.debug("begin to stop %d" % expr_id)
expr = self.db.find_first_object_by(Experiment, id=expr_id, status=EStatus.RUNNING)
if expr is not None:
# Docker
if expr.template.provider == VE_PROVIDER.DOCKER:
# stop containers
for c in expr.virtual_environments.all():
try:
self.log.debug("begin to stop %s" % c.name)
docker = self.__get_docker(expr.hackathon, c)
if force:
docker.delete(c.name, virtual_environment=c, container=c.container, expr_id=expr_id)
c.status = VEStatus.DELETED
else:
docker.stop(c.name, virtual_environment=c, container=c.container, expr_id=expr_id)
c.status = VEStatus.STOPPED
except Exception as e:
self.log.error(e)
self.__roll_back(expr_id)
return internal_server_error('Failed stop/delete container')
if force:
expr.status = EStatus.DELETED
else:
expr.status = EStatus.STOPPED
self.db.commit()
else:
try:
# todo support delete azure vm
hosted_docker = RequiredFeature("hosted_docker")
af = AzureFormation(hosted_docker.load_azure_key_id(expr_id))
af.stop(expr_id, AVMStatus.STOPPED_DEALLOCATED)
except Exception as e:
self.log.error(e)
return internal_server_error('Failed stopping azure')
self.log.debug("experiment %d ended success" % expr_id)
return ok('OK')
else:
return ok()