本文整理汇总了Python中appscale.tools.local_state.LocalState.generate_rsa_key方法的典型用法代码示例。如果您正苦于以下问题:Python LocalState.generate_rsa_key方法的具体用法?Python LocalState.generate_rsa_key怎么用?Python LocalState.generate_rsa_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appscale.tools.local_state.LocalState
的用法示例。
在下文中一共展示了LocalState.generate_rsa_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_instance_security
# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import generate_rsa_key [as 别名]
def configure_instance_security(self, parameters):
""" Creates a GCE network and firewall with the specified name, and opens
the ports on that firewall as needed for AppScale.
We expect both the network and the firewall to not exist before this point,
to avoid accidentally placing AppScale instances from different deployments
in the same network and firewall (thus enabling them to see each other's web
traffic).
Args:
parameters: A dict with keys for each parameter needed to connect to
Google Compute Engine, and an additional key indicating the name of the
network and firewall that we should create in GCE.
Returns:
True, if the named network and firewall was created successfully.
Raises:
AgentRuntimeException: If the named network or firewall already exist in
GCE.
"""
is_autoscale_agent = parameters.get(self.PARAM_AUTOSCALE_AGENT, False)
# While creating instances during autoscaling, we do not need to create a
# new keypair or a network. We just make use of the existing one.
if is_autoscale_agent:
return
AppScaleLogger.log("Verifying that SSH key exists locally")
keyname = parameters[self.PARAM_KEYNAME]
private_key = LocalState.LOCAL_APPSCALE_PATH + keyname
public_key = private_key + ".pub"
if os.path.exists(private_key) or os.path.exists(public_key):
raise AgentRuntimeException("SSH key already found locally - please " +
"use a different keyname")
LocalState.generate_rsa_key(keyname, parameters[self.PARAM_VERBOSE])
ssh_key_exists, all_ssh_keys = self.does_ssh_key_exist(parameters)
if not ssh_key_exists:
self.create_ssh_key(parameters, all_ssh_keys)
if self.does_network_exist(parameters):
raise AgentRuntimeException("Network already exists - please use a " + \
"different group name.")
if self.does_firewall_exist(parameters):
raise AgentRuntimeException("Firewall already exists - please use a " + \
"different group name.")
network_url = self.create_network(parameters)
self.create_firewall(parameters, network_url)
示例2: configure_instance_security
# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import generate_rsa_key [as 别名]
def configure_instance_security(self, parameters):
""" Configure the resource group and storage account needed to create the
network interface for the VMs to be spawned. This method is called before
starting virtual machines.
Args:
parameters: A dict containing values necessary to authenticate with the
underlying cloud.
Returns:
True, if the group and account were created successfully.
False, otherwise.
Raises:
AgentRuntimeException: If security features could not be successfully
configured in the underlying cloud.
"""
credentials = self.open_connection(parameters)
resource_group = parameters[self.PARAM_RESOURCE_GROUP]
storage_account = parameters[self.PARAM_STORAGE_ACCOUNT]
zone = parameters[self.PARAM_ZONE]
subscription_id = parameters[self.PARAM_SUBSCRIBER_ID]
AppScaleLogger.log("Verifying that SSH key exists locally.")
keyname = parameters[self.PARAM_KEYNAME]
private_key = LocalState.LOCAL_APPSCALE_PATH + keyname
public_key = private_key + ".pub"
if os.path.exists(private_key) or os.path.exists(public_key):
raise AgentRuntimeException("SSH key already found locally - please "
"use a different keyname.")
LocalState.generate_rsa_key(keyname, parameters[self.PARAM_VERBOSE])
AppScaleLogger.log("Configuring network for machine/s under "
"resource group '{0}' with storage account '{1}' "
"in zone '{2}'".format(resource_group, storage_account, zone))
# Create a resource group and an associated storage account to access resources.
self.create_resource_group(parameters, credentials)
resource_client = ResourceManagementClient(credentials, subscription_id)
resource_client.providers.register(self.MICROSOFT_COMPUTE_RESOURCE)
resource_client.providers.register(self.MICROSOFT_NETWORK_RESOURCE)