本文整理汇总了Python中appscale.tools.appscale_logger.AppScaleLogger.log方法的典型用法代码示例。如果您正苦于以下问题:Python AppScaleLogger.log方法的具体用法?Python AppScaleLogger.log怎么用?Python AppScaleLogger.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appscale.tools.appscale_logger.AppScaleLogger
的用法示例。
在下文中一共展示了AppScaleLogger.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_security_group
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def create_security_group(self, parameters, group):
"""Creates a new security group in AWS with the given name.
Args:
parameters: A dict that contains the credentials necessary to authenticate
with AWS.
group: A str that names the group that should be created.
Raises:
AgentRuntimeException: If the security group could not be created.
"""
AppScaleLogger.log('Creating security group: {0}'.format(group))
conn = self.open_connection(parameters)
retries_left = self.SECURITY_GROUP_RETRY_COUNT
while retries_left:
try:
conn.create_security_group(group, 'AppScale security group')
except EC2ResponseError:
pass
try:
conn.get_all_security_groups(group)
return
except EC2ResponseError:
pass
time.sleep(self.SLEEP_TIME)
retries_left -= 1
raise AgentRuntimeException("Couldn't create security group with " \
"name {0}".format(group))
示例2: does_user_exist
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def does_user_exist(self, username, silent=False):
""" Queries the AppController to see if the given user exists.
Args:
username: The email address registered as username for the user's application.
"""
while True:
try:
user_exists = self.run_with_timeout(
self.DEFAULT_TIMEOUT, self.DEFAULT_NUM_RETRIES,
self.server.does_user_exist, username, self.secret)
if user_exists == 'true':
return True
elif user_exists == 'false':
return False
else:
raise Exception(user_exists)
except BadSecretException as exception:
raise AppControllerException(
"Exception when checking if a user exists: {0}".format(exception))
except Exception as acc_error:
if not silent:
AppScaleLogger.log("Exception when checking if a user exists: {0}".
format(acc_error))
AppScaleLogger.log("Backing off and trying again.")
time.sleep(10)
示例3: cleanup_state
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def cleanup_state(self, parameters):
""" Removes any remote state that was created to run AppScale instances
during this deployment.
Args:
parameters: A dict that includes keys indicating the remote state
that should be deleted.
"""
subscription_id = parameters[self.PARAM_SUBSCRIBER_ID]
resource_group = parameters[self.PARAM_RESOURCE_GROUP]
credentials = self.open_connection(parameters)
network_client = NetworkManagementClient(credentials, subscription_id)
verbose = parameters[self.PARAM_VERBOSE]
AppScaleLogger.log("Deleting the Virtual Network, Public IP Address "
"and Network Interface created for this deployment.")
network_interfaces = network_client.network_interfaces.list(resource_group)
for interface in network_interfaces:
result = network_client.network_interfaces.delete(resource_group, interface.name)
resource_name = 'Network Interface' + ':' + interface.name
self.sleep_until_delete_operation_done(result, resource_name,
self.MAX_SLEEP_TIME, verbose)
public_ip_addresses = network_client.public_ip_addresses.list(resource_group)
for public_ip in public_ip_addresses:
result = network_client.public_ip_addresses.delete(resource_group, public_ip.name)
resource_name = 'Public IP Address' + ':' + public_ip.name
self.sleep_until_delete_operation_done(result, resource_name,
self.MAX_SLEEP_TIME, verbose)
virtual_networks = network_client.virtual_networks.list(resource_group)
for network in virtual_networks:
result = network_client.virtual_networks.delete(resource_group, network.name)
resource_name = 'Virtual Network' + ':' + network.name
self.sleep_until_delete_operation_done(result, resource_name,
self.MAX_SLEEP_TIME, verbose)
示例4: get_optimal_spot_price
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def get_optimal_spot_price(self, conn, instance_type, zone):
"""
Returns the spot price for an EC2 instance of the specified instance type.
The returned value is computed by averaging all the spot price history
values returned by the back-end EC2 APIs and incrementing the average by
extra 10%.
Args:
conn: A boto.EC2Connection that can be used to communicate with AWS.
instance_type: A str representing the instance type whose prices we
should speculate for.
zone: A str representing the availability zone that the instance will
be placed in.
Returns:
The estimated spot price for the specified instance type, in the
specified availability zone.
"""
end_time = datetime.datetime.now()
start_time = end_time - datetime.timedelta(days=7)
history = conn.get_spot_price_history(start_time=start_time.isoformat(),
end_time=end_time.isoformat(), product_description='Linux/UNIX',
instance_type=instance_type, availability_zone=zone)
var_sum = 0.0
for entry in history:
var_sum += entry.price
average = var_sum / len(history)
bid_price = average * 1.10
AppScaleLogger.log('The average spot instance price for a {0} machine is'\
' {1}, and 10% more is {2}'.format(instance_type, average, bid_price))
return bid_price
示例5: create_storage_account
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def create_storage_account(self, parameters, storage_client):
""" Creates a Storage Account under the Resource Group, if it does not
already exist. In the case where no resource group is specified, a default
storage account is created.
Args:
parameters: A dict, containing all the parameters necessary to authenticate
this user with Azure.
credentials: A ServicePrincipalCredentials instance, that can be used to access or
create any resources.
Raises:
AgentConfigurationException: If there was a problem creating or accessing
a storage account with the given subscription.
"""
storage_account = parameters[self.PARAM_STORAGE_ACCOUNT]
rg_name = parameters[self.PARAM_RESOURCE_GROUP]
try:
AppScaleLogger.log("Creating a new storage account '{0}' under the "
"resource group '{1}'.".format(storage_account, rg_name))
result = storage_client.storage_accounts.create(
rg_name, storage_account,StorageAccountCreateParameters(
sku=Sku(SkuName.standard_lrs), kind=Kind.storage,
location=parameters[self.PARAM_ZONE]))
# Result is a msrestazure.azure_operation.AzureOperationPoller instance.
# wait() insures polling the underlying async operation until it's done.
result.wait()
except CloudError as error:
raise AgentConfigurationException("Unable to create a storage account "
"using the credentials provided: {}".format(error.message))
示例6: create_security_group
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def create_security_group(self, parameters, group):
"""Creates a new security group in AWS with the given name.
Args:
parameters: A dict that contains the credentials necessary to authenticate
with AWS.
group: A str that names the group that should be created.
Returns:
The 'boto.ec2.securitygroup.SecurityGroup' that was just created.
Raises:
AgentRuntimeException: If the security group could not be created.
"""
AppScaleLogger.log('Creating security group: {0}'.format(group))
conn = self.open_connection(parameters)
specified_vpc = parameters.get(self.PARAM_VPC_ID)
retries_left = self.SECURITY_GROUP_RETRY_COUNT
while retries_left:
try:
conn.create_security_group(group, 'AppScale security group',
specified_vpc)
except EC2ResponseError:
pass
try:
return self.get_security_group_by_name(conn, group, specified_vpc)
except SecurityGroupNotFoundException:
pass
time.sleep(self.SLEEP_TIME)
retries_left -= 1
raise AgentRuntimeException("Couldn't create security group with " \
"name {0}".format(group))
示例7: print_table
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def print_table(table_name, headers, data):
"""
Prints a list of statistics with specified headers.
Args:
table_name: A string representing a name of table.
headers: A list of statistic headers.
data: A list of statistics.
"""
table = tabulate(tabular_data=data, headers=headers, tablefmt='simple',
floatfmt=".1f", numalign="right", stralign="left")
table_width = len(table.split("\n", 2)[1])
left_signs = " " * ((table_width - len(table_name) - 2) / 2)
right_signs = left_signs + (
" " if (table_width - len(table_name)) % 2 == 1 else ""
)
result_table_name = (
"{l_signs} {name} {r_signs}"
.format(l_signs=left_signs, name=table_name, r_signs=right_signs)
)
title = styled(result_table_name, "bold", "blue", "reverse")
AppScaleLogger.log(title)
AppScaleLogger.log(table + "\n")
示例8: attach_disk
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def attach_disk(self, parameters, disk_name, instance_id):
""" Attaches the Elastic Block Store volume specified in 'disk_name' to this
virtual machine.
Args:
parameters: A dict with keys for each parameter needed to connect to AWS.
disk_name: A str naming the EBS mount to attach to this machine.
instance_id: A str naming the id of the instance that the disk should be
attached to. In practice, callers add disks to their own instances.
Returns:
The location on the local filesystem where the disk has been attached.
"""
# In Amazon Web Services, if we're running on a Xen Paravirtualized machine,
# then devices get added starting at /dev/xvda. If not, they get added at
# /dev/sda. Find out which one we're on so that we know where the disk will
# get attached to.
if glob.glob("/dev/xvd*"):
mount_point = '/dev/xvdc'
else:
mount_point = '/dev/sdc'
conn = self.open_connection(parameters)
try:
AppScaleLogger.log('Attaching volume {0} to instance {1}, at {2}'.format(
disk_name, instance_id, mount_point))
conn.attach_volume(disk_name, instance_id, mount_point)
return mount_point
except EC2ResponseError as exception:
if self.disk_attached(conn, disk_name, instance_id):
return mount_point
AppScaleLogger.log('An error occurred when trying to attach volume {0} '
'to instance {1} at {2}'.format(disk_name, instance_id, mount_point))
self.handle_failure('EC2 response error while attaching volume:' +
exception.error_message)
示例9: handle_failure
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def handle_failure(self, msg):
""" Log the specified error message and raise an AgentRuntimeException
Args:
msg: An error message to be logged and included in the raised exception.
Raises:
AgentRuntimeException Contains the input error message.
"""
AppScaleLogger.log(msg)
raise AgentRuntimeException(msg)
示例10: configure_instance_security
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def configure_instance_security(self, parameters):
"""
Setup EC2 security keys and groups. Required input values are read from
the parameters dictionary. More specifically, this method expects to
find a 'keyname' parameter and a 'group' parameter in the parameters
dictionary. Using these provided values, this method will create a new
EC2 key-pair and a security group. Security group will be granted permission
to access any port on the instantiated VMs. (Also see documentation for the
BaseAgent class)
Args:
parameters: A dictionary of parameters.
"""
keyname = parameters[self.PARAM_KEYNAME]
group = parameters[self.PARAM_GROUP]
is_autoscale = parameters['autoscale_agent']
AppScaleLogger.log("Verifying that keyname {0}".format(keyname) + \
" is not already registered.")
conn = self.open_connection(parameters)
# While creating instances during autoscaling, we do not need to create a
# new keypair or a security group. We just make use of the existing one.
if is_autoscale in ['True', True]:
return
if conn.get_key_pair(keyname):
self.handle_failure("SSH keyname {0} is already registered. Please " \
"change the 'keyname' specified in your AppScalefile to a different " \
"value, or erase it to have one automatically generated for you." \
.format(keyname))
security_groups = conn.get_all_security_groups()
for security_group in security_groups:
if security_group.name == group:
self.handle_failure("Security group {0} is already registered. Please" \
" change the 'group' specified in your AppScalefile to a different " \
"value, or erase it to have one automatically generated for you." \
.format(group))
AppScaleLogger.log("Creating key pair: {0}".format(keyname))
key_pair = conn.create_key_pair(keyname)
ssh_key = '{0}{1}.key'.format(LocalState.LOCAL_APPSCALE_PATH, keyname)
LocalState.write_key_file(ssh_key, key_pair.material)
self.create_security_group(parameters, group)
self.authorize_security_group(parameters, group, from_port=1, to_port=65535,
ip_protocol='udp', cidr_ip='0.0.0.0/0')
self.authorize_security_group(parameters, group, from_port=1, to_port=65535,
ip_protocol='tcp', cidr_ip='0.0.0.0/0')
self.authorize_security_group(parameters, group, from_port=-1, to_port=-1,
ip_protocol='icmp', cidr_ip='0.0.0.0/0')
return True
示例11: configure_instance_security
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [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)
示例12: create_resource_group
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def create_resource_group(self, parameters, credentials):
""" Creates a Resource Group for the application using the Service Principal
Credentials, if it does not already exist. In the case where no resource
group is specified, a default group is created.
Args:
parameters: A dict, containing all the parameters necessary to
authenticate this user with Azure.
credentials: A ServicePrincipalCredentials instance, that can be used to
access or create any resources.
Raises:
AgentConfigurationException: If there was a problem creating or accessing
a resource group with the given subscription.
"""
subscription_id = parameters[self.PARAM_SUBSCRIBER_ID]
resource_client = ResourceManagementClient(credentials, subscription_id)
rg_name = parameters[self.PARAM_RESOURCE_GROUP]
tag_name = 'default-tag'
if parameters[self.PARAM_TAG]:
tag_name = parameters[self.PARAM_TAG]
storage_client = StorageManagementClient(credentials, subscription_id)
resource_client.providers.register(self.MICROSOFT_STORAGE_RESOURCE)
try:
# If the resource group does not already exist, create a new one with the
# specified storage account.
if not parameters[self.PARAM_EXISTING_RG]:
AppScaleLogger.log("Creating a new resource group '{0}' with the tag "
"'{1}'.".format(rg_name, tag_name))
resource_client.resource_groups.create_or_update(
rg_name, ResourceGroup(location=parameters[self.PARAM_ZONE],
tags={'tag': tag_name}))
self.create_storage_account(parameters, storage_client)
else:
# If it already exists, check if the specified storage account exists
# under it and if not, create a new account.
storage_accounts = storage_client.storage_accounts.\
list_by_resource_group(rg_name)
acct_names = []
for account in storage_accounts:
acct_names.append(account.name)
if parameters[self.PARAM_STORAGE_ACCOUNT] in acct_names:
AppScaleLogger.log("Storage account '{0}' under '{1}' resource group "
"already exists. So not creating it again.".format(
parameters[self.PARAM_STORAGE_ACCOUNT], rg_name))
else:
self.create_storage_account(parameters, storage_client)
except CloudError as error:
raise AgentConfigurationException("Unable to create a resource group "
"using the credentials provided: {}".format(error.message))
示例13: attach_disk
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def attach_disk(self, parameters, disk_name, instance_id):
""" Attaches the persistent disk specified in 'disk_name' to this virtual
machine.
Args:
parameters: A dict with keys for each parameter needed to connect to
Google Compute Engine.
disk_name: A str naming the persistent disk to attach to this machine.
instance_id: A str naming the id of the instance that the disk should be
attached to. In practice, callers add disks to their own instance.
Returns:
A str indicating where the persistent disk has been attached to.
"""
gce_service, credentials = self.open_connection(parameters)
http = httplib2.Http()
auth_http = credentials.authorize(http)
project = parameters[self.PARAM_PROJECT]
zone = parameters[self.PARAM_ZONE]
# If the disk is already attached, return the mount point.
request = gce_service.instances().get(project=project, zone=zone,
instance=instance_id)
disks = request.execute(auth_http)['disks']
for disk in disks:
path = disk['source'].split('/')
if project == path[-5] and zone == path[-3] and disk_name == path[-1]:
device_name = '/dev/{}'.format(disk['deviceName'])
AppScaleLogger.log('Disk is already attached at {}'.format(device_name))
return device_name
request = gce_service.instances().attachDisk(
project=project,
zone=zone,
instance=instance_id,
body={
'kind': 'compute#attachedDisk',
'type': 'PERSISTENT',
'mode': 'READ_WRITE',
'source': "https://www.googleapis.com/compute/{0}/projects/{1}" \
"/zones/{2}/disks/{3}".format(self.API_VERSION, project,
zone, disk_name),
'deviceName': 'sdb'
}
)
response = request.execute(auth_http)
AppScaleLogger.log(str(response))
self.ensure_operation_succeeds(gce_service, auth_http, response,
parameters[self.PARAM_PROJECT])
return '/dev/sdb'
示例14: warn_if_version_defined
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def warn_if_version_defined(cls, version, test=False):
""" Warns the user if version is defined in the application configuration.
Args:
version: A Version object.
test: A boolean indicating that the tools are in test mode.
Raises:
AppScaleException: If version is defined and user decides to cancel.
"""
if version.id is not None:
AppScaleLogger.log(
'The version element is not supported in {}. Module {} will be '
'overwritten.'.format(version.configuration_type, version.service_id))
if not test:
response = raw_input('Continue? (y/N) ')
if response.lower() not in ['y', 'yes']:
raise AppScaleException('Cancelled deploy operation')
示例15: authorize_security_group
# 需要导入模块: from appscale.tools.appscale_logger import AppScaleLogger [as 别名]
# 或者: from appscale.tools.appscale_logger.AppScaleLogger import log [as 别名]
def authorize_security_group(self, parameters, group_id, from_port,
to_port, ip_protocol, cidr_ip):
"""Opens up traffic on the given port range for traffic of the named type.
Args:
parameters: A dict that contains the credentials necessary to authenticate
with AWS.
group_id: A str that contains the id of the group whose ports should be
opened.
from_port: An int that names the first port that access should be allowed
on.
to_port: An int that names the last port that access should be allowed on.
ip_protocol: A str that indicates if TCP, UDP, or ICMP traffic should be
allowed.
cidr_ip: A str that names the IP range that traffic should be allowed
from.
Raises:
AgentRuntimeException: If the ports could not be opened on the security
group.
"""
AppScaleLogger.log('Authorizing security group {0} for {1} traffic from ' \
'port {2} to port {3}'.format(group_id, ip_protocol, from_port, to_port))
conn = self.open_connection(parameters)
retries_left = self.SECURITY_GROUP_RETRY_COUNT
while retries_left:
try:
conn.authorize_security_group(group_id=group_id, from_port=from_port,
to_port=to_port, cidr_ip=cidr_ip,
ip_protocol=ip_protocol)
except EC2ResponseError:
pass
try:
group_info = self.get_security_group_by_name(
conn, parameters[self.PARAM_GROUP], parameters.get(self.PARAM_VPC_ID))
for rule in group_info.rules:
if int(rule.from_port) == from_port and int(rule.to_port) == to_port \
and rule.ip_protocol == ip_protocol:
return
except SecurityGroupNotFoundException as e:
raise AgentRuntimeException(e.message)
time.sleep(self.SLEEP_TIME)
retries_left -= 1
raise AgentRuntimeException("Couldn't authorize {0} traffic from port " \
"{1} to port {2} on CIDR IP {3}".format(ip_protocol, from_port, to_port,
cidr_ip))