本文整理汇总了Python中agents.factory.InfrastructureAgentFactory.create_agent方法的典型用法代码示例。如果您正苦于以下问题:Python InfrastructureAgentFactory.create_agent方法的具体用法?Python InfrastructureAgentFactory.create_agent怎么用?Python InfrastructureAgentFactory.create_agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agents.factory.InfrastructureAgentFactory
的用法示例。
在下文中一共展示了InfrastructureAgentFactory.create_agent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_agent
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def test_create_agent(self):
factory = InfrastructureAgentFactory()
agent = factory.create_agent("ec2")
self.assertEquals(type(agent), type(EC2Agent()))
agent = factory.create_agent("euca")
self.assertEquals(type(agent), type(EucalyptusAgent()))
try:
factory.create_agent("bogus")
self.fail("No exception thrown for invalid infrastructure")
except NameError:
pass
except Exception:
self.fail("Unexpected exception thrown for invalid infrastructure")
示例2: terminate_cloud_infrastructure
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def terminate_cloud_infrastructure(cls, keyname, is_verbose):
"""Powers off all machines in the currently running AppScale deployment.
Args:
keyname: The name of the SSH keypair used for this AppScale deployment.
is_verbose: A bool that indicates if we should print the commands executed
to stdout.
"""
AppScaleLogger.log("About to terminate instances spawned with keyname {0}"
.format(keyname))
# This sleep is here to allow a moment for user to Ctrl-C
time.sleep(2)
# get all the instance IDs for machines in our deployment
agent = InfrastructureAgentFactory.create_agent(
LocalState.get_infrastructure(keyname))
params = agent.get_params_from_yaml(keyname)
params['IS_VERBOSE'] = is_verbose
_, _, instance_ids = agent.describe_instances(params)
# terminate all the machines
params[agent.PARAM_INSTANCE_IDS] = instance_ids
agent.terminate_instances(params)
# delete the keyname and group
agent.cleanup_state(params)
示例3: validate_machine_image
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def validate_machine_image(self):
"""Checks with the given cloud (if running in a cloud) to ensure that the
user-specified ami/emi exists, aborting if it does not.
Raises:
BadConfigurationException: If the given machine image does not exist.
"""
if not self.args.infrastructure:
return
cloud_agent = InfrastructureAgentFactory.create_agent(
self.args.infrastructure)
params = cloud_agent.get_params_from_args(self.args)
if not cloud_agent.does_image_exist(params):
raise BadConfigurationException("Couldn't find the given machine image.")
if not cloud_agent.does_zone_exist(params):
raise BadConfigurationException("Couldn't find the given zone.")
if not self.args.disks:
return
for disk in set(self.args.disks.values()):
if not cloud_agent.does_disk_exist(params, disk):
raise BadConfigurationException("Couldn't find disk {0}".format(disk))
示例4: spawn_node_in_cloud
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def spawn_node_in_cloud(cls, options):
"""Starts a single virtual machine in a cloud infrastructure.
This method also prepares the virual machine for use by the AppScale Tools.
Specifically, it enables root logins on the machine, enables SSH access,
and copies the user's SSH key to that machine.
Args:
options: A Namespace that specifies the cloud infrastructure to use, as
well as how to interact with that cloud.
Returns:
The instance ID, public IP address, and private IP address of the machine
that was started.
"""
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
agent.configure_instance_security(params)
instance_ids, public_ips, private_ips = agent.run_instances(count=1,
parameters=params, security_configured=True)
AppScaleLogger.log("Please wait for your instance to boot up.")
cls.sleep_until_port_is_open(public_ips[0], cls.SSH_PORT, options.verbose)
cls.enable_root_login(public_ips[0], options.keyname,
options.infrastructure, options.verbose)
cls.copy_ssh_keys_to_node(public_ips[0], options.keyname, options.verbose)
return instance_ids[0], public_ips[0], private_ips[0]
示例5: validate_credentials
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def validate_credentials(self):
if not self.args.infrastructure:
return
cloud_agent = InfrastructureAgentFactory.create_agent(
self.args.infrastructure)
params = cloud_agent.get_params_from_args(self.args)
cloud_agent.assert_required_parameters(params, BaseAgent.OPERATION_RUN)
示例6: validate_credentials
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def validate_credentials(self):
"""If running over a cloud infrastructure, makes sure that all of the
necessary credentials have been specified.
"""
if not self.args.infrastructure:
return
cloud_agent = InfrastructureAgentFactory.create_agent(self.args.infrastructure)
params = cloud_agent.get_params_from_args(self.args)
cloud_agent.assert_required_parameters(params, BaseAgent.OPERATION_RUN)
示例7: terminate_cloud_instance
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def terminate_cloud_instance(cls, instance_id, options):
"""Powers off a single instance in the currently AppScale deployment and
cleans up secret key from the local filesystem.
Args:
instance_id: str containing the instance id.
options: namespace containing the run parameters.
"""
AppScaleLogger.log("About to terminate instance {0}".format(instance_id))
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
params["IS_VERBOSE"] = options.verbose
params[agent.PARAM_INSTANCE_IDS] = [instance_id]
agent.terminate_instances(params)
agent.cleanup_state(params)
os.remove(LocalState.get_secret_key_location(options.keyname))
示例8: terminate_cloud_infrastructure
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def terminate_cloud_infrastructure(cls, keyname, is_verbose):
"""Powers off all machines in the currently running AppScale deployment.
Args:
keyname: The name of the SSH keypair used for this AppScale deployment.
is_verbose: A bool that indicates if we should print the commands executed
to stdout.
"""
AppScaleLogger.log("About to terminate deployment and instances with "
"keyname {0}. Press Ctrl-C to stop.".format(keyname))
# This sleep is here to allow a moment for user to Ctrl-C
time.sleep(2)
# get all the instance IDs for machines in our deployment
agent = InfrastructureAgentFactory.create_agent(
LocalState.get_infrastructure(keyname))
params = agent.get_cloud_params(keyname)
params['IS_VERBOSE'] = is_verbose
params['autoscale_agent'] = False
# We want to terminate also the pending instances.
pending = True
_, _, instance_ids = agent.describe_instances(params, pending=pending)
# If using persistent disks, unmount them and detach them before we blow
# away the instances.
nodes = LocalState.get_local_nodes_info(keyname)
for node in nodes:
if node.get('disk'):
AppScaleLogger.log("Unmounting persistent disk at {0}".
format(node['public_ip']))
cls.unmount_persistent_disk(node['public_ip'], keyname, is_verbose)
agent.detach_disk(params, node['disk'], node['instance_id'])
# terminate all the machines
AppScaleLogger.log("Terminating instances spawned with keyname {0}"
.format(keyname))
params[agent.PARAM_INSTANCE_IDS] = instance_ids
agent.terminate_instances(params)
# Delete the network configuration created for the cloud.
agent.cleanup_state(params)
# Cleanup the keyname files created on the local filesystem.
# For GCE and Azure, the keypairs are created on the filesystem,
# rather than the cloud. So we have to clean up afterwards.
LocalState.cleanup_keyname(keyname)
示例9: spawn_nodes_in_cloud
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def spawn_nodes_in_cloud(cls, options, count=1):
"""Starts a single virtual machine in a cloud infrastructure.
This method also prepares the virual machine for use by the AppScale Tools.
Args:
options: A Namespace that specifies the cloud infrastructure to use, as
well as how to interact with that cloud.
count: A int, the number of instances to start.
Returns:
The instance ID, public IP address, and private IP address of the machine
that was started.
"""
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
# If we have running instances under the current keyname, we try to
# re-attach to them. If we have issue finding the locations file or the
# IP of the head node, we throw an exception.
login_ip = None
public_ips, private_ips, instance_ids = agent.describe_instances(params)
if public_ips:
try:
login_ip = LocalState.get_login_host(options.keyname)
except (IOError, BadConfigurationException):
raise AppScaleException(
"Couldn't get login ip for running deployment with keyname"
" {}.".format(options.keyname))
if login_ip not in public_ips:
raise AppScaleException(
"Couldn't recognize running instances for deployment with"
" keyname {}.".format(options.keyname))
if login_ip in public_ips:
AppScaleLogger.log("Reusing already running instances.")
return instance_ids, public_ips, private_ips
agent.configure_instance_security(params)
instance_ids, public_ips, private_ips = agent.run_instances(count=count,
parameters=params, security_configured=True)
if options.static_ip:
agent.associate_static_ip(params, instance_ids[0], options.static_ip)
public_ips[0] = options.static_ip
AppScaleLogger.log("Static IP associated with head node.")
return instance_ids, public_ips, private_ips
示例10: terminate_cloud_infrastructure
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def terminate_cloud_infrastructure(cls, keyname, is_verbose):
"""Powers off all machines in the currently running AppScale deployment.
Args:
keyname: The name of the SSH keypair used for this AppScale deployment.
is_verbose: A bool that indicates if we should print the commands executed
to stdout.
"""
AppScaleLogger.log("About to terminate instances spawned with keyname {0}"
.format(keyname))
# This sleep is here to allow a moment for user to Ctrl-C
time.sleep(2)
# get all the instance IDs for machines in our deployment
agent = InfrastructureAgentFactory.create_agent(
LocalState.get_infrastructure(keyname))
params = agent.get_params_from_yaml(keyname)
params['IS_VERBOSE'] = is_verbose
# We want to terminate also the pending instances.
pending = True
_, _, instance_ids = agent.describe_instances(params, pending=pending)
# If using persistent disks, unmount them and detach them before we blow
# away the instances.
cls.terminate_virtualized_cluster(keyname, is_verbose)
nodes = LocalState.get_local_nodes_info(keyname)
for node in nodes:
if node.get('disk'):
AppScaleLogger.log("Unmounting persistent disk at {0}".format(
node['public_ip']))
cls.unmount_persistent_disk(node['public_ip'], keyname, is_verbose)
agent.detach_disk(params, node['disk'], node['instance_id'])
# terminate all the machines
params[agent.PARAM_INSTANCE_IDS] = instance_ids
agent.terminate_instances(params)
# delete the keyname and group
agent.cleanup_state(params)
示例11: spawn_node_in_cloud
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def spawn_node_in_cloud(cls, options):
"""Starts a single virtual machine in a cloud infrastructure.
This method also prepares the virual machine for use by the AppScale Tools.
Specifically, it enables root logins on the machine, enables SSH access,
and copies the user's SSH key to that machine.
Args:
options: A Namespace that specifies the cloud infrastructure to use, as
well as how to interact with that cloud.
Returns:
The instance ID, public IP address, and private IP address of the machine
that was started.
"""
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
agent.configure_instance_security(params)
instance_ids, public_ips, private_ips = agent.run_instances(count=1,
parameters=params, security_configured=True)
if options.static_ip:
agent.associate_static_ip(params, instance_ids[0], options.static_ip)
public_ips[0] = options.static_ip
AppScaleLogger.log("Please wait for your instance to boot up.")
cls.sleep_until_port_is_open(public_ips[0], cls.SSH_PORT, options.verbose)
# Since GCE v1beta15, SSH keys don't immediately get injected to newly
# spawned VMs. It takes around 30 seconds, so sleep a bit longer to be
# sure.
if options.infrastructure == 'gce':
AppScaleLogger.log("Waiting for SSH keys to get injected to your "
"machine.")
time.sleep(60)
cls.enable_root_login(public_ips[0], options.keyname,
options.infrastructure, options.verbose)
cls.copy_ssh_keys_to_node(public_ips[0], options.keyname, options.verbose)
return instance_ids[0], public_ips[0], private_ips[0]
示例12: InfrastructureManager
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
#.........这里部分代码省略.........
a valid 'reservation_id' parameter, this method will return a
dictionary containing information regarding the requested past
virtual machine deployment. This returned map contains several
keys including 'success', 'state', 'reason' and 'vm_info'. The value
of 'success' could be True of False depending on the outcome of the
virtual machine deployment process. If the value of 'success' happens
to be False, the 'reason' key would contain more details as to what
caused the deployment to fail. The 'state' key could contain a 'pending'
value or a 'running' value depending on the current state of the
virtual machine deployment. And finally the 'vm_info' key would point
to a another dictionary containing the IP addresses of the spawned virtual
machines. If the virtual machine deployment had failed or still in the
'pending' state, this key would contain the value None.
If this method receives an invalid key or an invalid 'reservation_id'
parameter, it will return a dictionary containing the keys 'success'
and 'reason' where 'success' would be set to False, and 'reason' is
set to a simple error message describing the cause of the error.
Raises:
TypeError If the inputs are not of the expected types
ValueError If the input JSON string (parameters) cannot be parsed properly
"""
# parameters, secret = self.__validate_args(parameters, secret)
# if self.secret != secret:
# return self.__generate_response(False, self.REASON_BAD_SECRET)
for param in self.DESCRIBE_INSTANCES_REQUIRED_PARAMS:
if not utils.has_parameter(param, parameters):
return self.__generate_response(False, 'no ' + param)
result = []
infrastructure = parameters[self.PARAM_INFRASTRUCTURE]
agent = self.agent_factory.create_agent(infrastructure)
return agent.describe_instances(parameters, prefix)
# reservation_id = parameters[self.PARAM_RESERVATION_ID]
# if self.reservations.has_key(reservation_id):
# return self.reservations.get(reservation_id)
# else:
# return self.__generate_response(False, self.REASON_RESERVATION_NOT_FOUND)
def prepare_instances(self, parameters):
"""
Prepare and setup a new virtual machine deployment using the provided parameters. The
input parameter set must include an 'infrastructure' parameter which indicates
the exact cloud environment to use. Value of this parameter will be used to
instantiate a cloud environment specific agent which knows how to interact
with the specified cloud platform. The parameters map must also contain a
'num_vms' parameter which indicates the number of virtual machines that should
be spawned. In addition to that any parameters required to spawn VMs in the
specified cloud environment must be included in the parameters map.
If this InfrastructureManager instance has been created in the blocking mode,
this method will not return until the VM deployment is complete. Otherwise
this method will simply kick off the VM deployment process and return
immediately.
Args:
parameters A parameter map containing the keys 'infrastructure',
'num_vms' and any other cloud platform specific
parameters. Alternatively one may provide a valid
JSON string instead of a dictionary object.
Returns:
示例13: cloud
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
#.........这里部分代码省略.........
JSON string instead of a dictionary object.
secret A previously established secret
Returns:
If the secret is valid and all the required parameters are available in
the input parameter map, this method will return a dictionary containing
a special 'reservation_id' key. If the secret is invalid or a required
parameter is missing, this method will return a different map with the
key 'success' set to False and 'reason' set to a simple error message.
Raises:
TypeError If the inputs are not of the expected types
ValueError If the input JSON string (parameters) cannot be parsed properly
"""
parameters, secret = self.__validate_args(parameters, secret)
utils.log('Received a request to run instances.')
if self.secret != secret:
utils.log('Incoming secret {0} does not match the current secret {1} - '\
'Rejecting request.'.format(secret, self.secret))
return self.__generate_response(False, self.REASON_BAD_SECRET)
for param in self.RUN_INSTANCES_REQUIRED_PARAMS:
if not utils.has_parameter(param, parameters):
return self.__generate_response(False, 'no ' + param)
num_vms = int(parameters[self.PARAM_NUM_VMS])
if num_vms <= 0:
utils.log('Invalid VM count: {0}'.format(num_vms))
return self.__generate_response(False, self.REASON_BAD_VM_COUNT)
infrastructure = parameters[self.PARAM_INFRASTRUCTURE]
agent = self.agent_factory.create_agent(infrastructure)
try:
agent.assert_required_parameters(parameters, BaseAgent.OPERATION_RUN)
except AgentConfigurationException as exception:
return self.__generate_response(False, str(exception))
reservation_id = utils.get_random_alphanumeric()
status_info = {
'success': True,
'reason': 'received run request',
'state': self.STATE_PENDING,
'vm_info': None
}
self.reservations.put(reservation_id, status_info)
utils.log('Generated reservation id {0} for this request.'.format(
reservation_id))
try:
if self.blocking:
self.__spawn_vms(agent, num_vms, parameters, reservation_id)
else:
thread.start_new_thread(self.__spawn_vms,
(agent, num_vms, parameters, reservation_id))
except AgentConfigurationException as exception:
status_info = {
'success' : False,
'reason' : str(exception),
'state' : self.STATE_FAILED,
'vm_info' : None
}
self.reservations.put(reservation_id, status_info)
utils.log('Updated reservation id {0} with failed status because: {1}' \
.format(reservation_id, str(exception)))
示例14: start_head_node
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def start_head_node(cls, options, my_id, node_layout):
"""Starts the first node in an AppScale deployment and instructs it to start
API services on its own node, as well as the other nodes in the deployment.
This includes spawning the first node in the deployment, copying over all
deployment-specific files to it, and starting its AppController service.
Args:
options: A Namespace that includes parameters passed in by the user that
define non-placement-strategy-related deployment options (e.g., keypair
names, security group names).
my_id: A str that is used to uniquely identify this AppScale deployment
with the remote start application.
node_layout: A NodeLayout that describes the placement strategy that
should be used for this AppScale deployment.
Returns:
The public IP and instance ID (a dummy value in non-cloud deployments)
corresponding to the node that was started.
Raises:
AppControllerException: If the AppController on the head node crashes.
The message in this exception indicates why the crash occurred.
"""
secret_key = LocalState.generate_secret_key(options.keyname)
AppScaleLogger.verbose("Secret key is {0}".
format(secret_key), options.verbose)
head_node = node_layout.head_node().public_ip
AppScaleLogger.log("Log in to your head node: ssh -i {0} [email protected]{1}".format(
LocalState.get_key_path_from_name(options.keyname), head_node))
additional_params = {}
if options.infrastructure:
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
additional_params = {}
if agent.PARAM_CREDENTIALS in params:
additional_params = params[agent.PARAM_CREDENTIALS]
if options.use_spot_instances:
additional_params[agent.PARAM_SPOT_PRICE] = \
str(params[agent.PARAM_SPOT_PRICE])
if agent.PARAM_REGION in params:
additional_params[agent.PARAM_REGION] = params[agent.PARAM_REGION]
time.sleep(10) # gives machines in cloud extra time to boot up
cls.copy_deployment_credentials(head_node, options)
cls.run_user_commands(head_node, options.user_commands, options.keyname,
options.verbose)
cls.start_remote_appcontroller(head_node, options.keyname, options.verbose)
AppScaleLogger.log("Head node successfully initialized at {0}.".
format(head_node))
AppScaleLogger.remote_log_tools_state(
options, my_id, "started head node", APPSCALE_VERSION)
# Construct serverside compatible parameters.
deployment_params = LocalState.generate_deployment_params(
options, node_layout, additional_params)
AppScaleLogger.verbose(str(LocalState.obscure_dict(deployment_params)),
options.verbose)
acc = AppControllerClient(head_node, secret_key)
try:
acc.set_parameters(node_layout.to_list(), deployment_params)
except Exception as exception:
AppScaleLogger.warn(u'Saw Exception while setting AC parameters: {0}'.
format(str(exception)))
message = RemoteHelper.collect_appcontroller_crashlog(
head_node, options.keyname, options.verbose)
raise AppControllerException(message)
示例15: start_all_nodes
# 需要导入模块: from agents.factory import InfrastructureAgentFactory [as 别名]
# 或者: from agents.factory.InfrastructureAgentFactory import create_agent [as 别名]
def start_all_nodes(cls, options, node_layout):
""" Starts all nodes in the designated public cloud.
Args:
options: A Namespace that includes parameters passed in by the user that
define non-placement-strategy-related deployment options (e.g., keypair
names, security group names).
node_layout: The node layout of the system including roles.
Returns:
The node layout (dummy values in non-cloud deployments)
corresponding to the nodes that were started.
"""
agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
params = agent.get_params_from_args(options)
# If we have running instances under the current keyname, we try to
# re-attach to them. If we have issue finding the locations file or the
# IP of the head node, we throw an exception.
login_ip = None
public_ips, private_ips, instance_ids = agent.describe_instances(params)
if public_ips:
try:
login_ip = LocalState.get_login_host(options.keyname)
except (IOError, BadConfigurationException):
raise AppScaleException(
"Couldn't get login ip for running deployment with keyname"
" {}.".format(options.keyname))
if login_ip not in public_ips:
raise AppScaleException(
"Couldn't recognize running instances for deployment with"
" keyname {}.".format(options.keyname))
if login_ip in public_ips:
AppScaleLogger.log("Reusing already running instances.")
# Get the node_info from the locations JSON.
node_info = LocalState.get_local_nodes_info(keyname=options.keyname)
previous_node_list = node_layout.from_locations_json_list(node_info)
# If this is None, the AppScalefile has been changed or the nodes could
# not be matched up by roles/jobs.
if previous_node_list is None:
raise BadConfigurationException("AppScale does not currently support "
"changes to AppScalefile or locations "
"JSON between a down and an up. If "
"you would like to "
"change the node layout use "
"down --terminate before an up.")
node_layout.nodes = previous_node_list
for node_index, node in enumerate(node_layout.nodes):
try:
index = instance_ids.index(node.instance_id)
except ValueError:
raise BadConfigurationException("Previous instance_id {} does not "
"currently exist."
.format(node.instance_id))
node_layout.nodes[node_index].public_ip = public_ips[index]
node_layout.nodes[node_index].private_ip = private_ips[index]
node_layout.nodes[node_index].instance_id = instance_ids[index]
return node_layout
agent.configure_instance_security(params)
load_balancer_roles = {}
instance_type_roles = {}
for node in node_layout.get_nodes('load_balancer', True):
load_balancer_roles.setdefault(node.instance_type, []).append(node)
for node in node_layout.get_nodes('load_balancer', False):
instance_type = instance_type_roles
instance_type.setdefault(node.instance_type, []).append(node)
spawned_instance_ids = []
for instance_type, load_balancer_nodes in load_balancer_roles.items():
# Copy parameters so we can modify the instance type.
instance_type_params = params.copy()
instance_type_params['instance_type'] = instance_type
try:
instance_ids, public_ips, private_ips = cls.spawn_nodes_in_cloud(
agent, instance_type_params, count=len(load_balancer_nodes),
load_balancer=True)
except (AgentRuntimeException, BotoServerError):
AppScaleLogger.warn("AppScale was unable to start the requested number "
"of instances, attempting to terminate those that "
"were started.")
if len(spawned_instance_ids) > 0:
AppScaleLogger.warn("Attempting to terminate those that were started.")
cls.terminate_spawned_instances(spawned_instance_ids, agent, params)
# Cleanup the keyname since it failed.
LocalState.cleanup_keyname(options.keyname)
# Re-raise the original exception.
raise
# Keep track of instances we have started.
spawned_instance_ids.extend(instance_ids)
#.........这里部分代码省略.........