本文整理汇总了Python中infrastructure_manager.InfrastructureManager.terminate_instances方法的典型用法代码示例。如果您正苦于以下问题:Python InfrastructureManager.terminate_instances方法的具体用法?Python InfrastructureManager.terminate_instances怎么用?Python InfrastructureManager.terminate_instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类infrastructure_manager.InfrastructureManager
的用法示例。
在下文中一共展示了InfrastructureManager.terminate_instances方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: terminate_instances
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import terminate_instances [as 别名]
def terminate_instances(self, prefix, blocking):
i = InfrastructureManager(blocking=blocking)
params1 = {'infrastructure': prefix}
self.assertRaises(AgentConfigurationException, i.terminate_instances, params1, 'secret')
params2 = {
'credentials': {
'a': 'b', 'EC2_URL': 'http://ec2.url.com',
'EC2_ACCESS_KEY': 'access_key', 'EC2_SECRET_KEY': 'secret_key'},
'infrastructure': prefix,
'instance_ids': ['i-12345'],
'region' : 'my-zone-1',
'keyname': 'bookeyname'
}
reservation = Reservation()
instance = flexmock(name='instance', private_dns_name='private-ip',
public_dns_name='public-ip', id='i-id', state='terminated',
key_name='bookeyname', ip_address='public-ip',
private_ip_address='private-ip')
reservation.instances = [instance]
self.fake_ec2.should_receive('get_all_instances').and_return([reservation])
flexmock(i).should_receive('_InfrastructureManager__kill_vms')
result = i.terminate_instances(params2, 'secret')
if not blocking:
time.sleep(.1)
self.assertTrue(result['success'])
示例2: terminate_instances
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import terminate_instances [as 别名]
def terminate_instances(self, prefix, blocking):
i = InfrastructureManager(blocking=blocking)
params1 = {'infrastructure': prefix}
result1 = i.terminate_instances(params1, 'secret')
self.assertFalse(result1['success'])
self.assertEquals(result1['reason'], 'no credentials')
params2 = {
'credentials': {'a': 'b', 'EC2_URL': 'http://ec2.url.com',
'EC2_ACCESS_KEY': 'access_key', 'EC2_SECRET_KEY': 'secret_key'},
'infrastructure': prefix,
'instance_ids': ['i-12345']
}
result2 = i.terminate_instances(params2, 'secret')
if not blocking:
time.sleep(2)
self.assertTrue(result2['success'])
示例3: stopMachines
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import terminate_instances [as 别名]
def stopMachines(self, params, block=False):
"""
This method would terminate all the instances associated with the account
that have a keyname prefixed with stochss (all instances created by the backend service)
params must contain credentials key/value
"""
try:
i = InfrastructureManager(blocking=block)
res = i.terminate_instances(params, backendservices.KEYPREFIX)
return True
except Exception, e:
logging.error("Terminate machine failed with error : %s", str(e))
return False
示例4: stopMachines
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import terminate_instances [as 别名]
def stopMachines(self, params):
'''
This method would terminate all the instances associated with the account
It expects the following two fields in the parameter argument
params ={"infrastructure":"ec2",
'credentials':{"EC2_ACCESS_KEY":"______________",
"EC2_SECRET_KEY":"__________"},
}
'''
try:
i = InfrastructureManager(blocking=True)
res = i.terminate_instances(params)
print str(res)
return True
except Exception, e:
logging.error("Terminate machine failed with error : %s", str(e))
return False
示例5: stopMachines
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import terminate_instances [as 别名]
def stopMachines(self, params, block=False):
'''
This method would terminate all the instances associated with the account
that have a keyname prefixed with stochss (all instances created by the backend service)
params must contain credentials key/value
'''
key_prefix = self.KEYPREFIX
if "key_prefix" in params and not params["key_prefix"].startswith(key_prefix):
key_prefix += params["key_prefix"]
elif "key_prefix" in params:
key_prefix = params["key_prefix"]
try:
logging.info("Stopping compute nodes with key_prefix: {0}".format(key_prefix))
i = InfrastructureManager(blocking=block)
res = i.terminate_instances(params,key_prefix)
return True
except Exception, e:
logging.error("Terminate machine failed with error : %s", str(e))
return False