本文整理汇总了Python中appscale.tools.appscale_tools.AppScaleTools类的典型用法代码示例。如果您正苦于以下问题:Python AppScaleTools类的具体用法?Python AppScaleTools怎么用?Python AppScaleTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AppScaleTools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: undeploy
def undeploy(self, project_id):
""" 'undeploy' is a more accessible way to tell an AppScale deployment to
stop hosting a Google App Engine application than 'appscale-remove-app'. It
calls that command with the configuration options found in the AppScalefile
in the current working directory.
Args:
project_id: The name of the application that we should remove.
Raises:
AppScalefileException: If there is no AppScalefile in the current working
directory.
"""
contents = self.read_appscalefile()
# Construct an remove-app command from the file's contents
command = []
contents_as_yaml = yaml.safe_load(contents)
if 'keyname' in contents_as_yaml:
command.append("--keyname")
command.append(contents_as_yaml['keyname'])
if 'verbose' in contents_as_yaml and contents_as_yaml['verbose'] == True:
command.append("--verbose")
if 'test' in contents_as_yaml and contents_as_yaml['test'] == True:
command.append('--confirm')
command.append("--project-id")
command.append(project_id)
# Finally, exec the command. Don't worry about validating it -
# appscale-upload-app will do that for us.
options = ParseArgs(command, "appscale-remove-app").args
AppScaleTools.remove_app(options)
示例2: testDeployWithCloudAppScalefile
def testDeployWithCloudAppScalefile(self):
# calling 'appscale deploy app' with an AppScalefile in the local
# directory should collect any parameters needed for the
# 'appscale-upload-app' command and then exec it
appscale = AppScale()
# Mock out the actual file reading itself, and slip in a YAML-dumped
# file
contents = {
'infrastructure' : 'ec2',
'machine' : 'ami-ABCDEFG',
'keyname' : 'bookey',
'group' : 'boogroup',
'verbose' : True,
'min' : 1,
'max' : 1
}
yaml_dumped_contents = yaml.dump(contents)
self.addMockForAppScalefile(appscale, yaml_dumped_contents)
# finally, mock out the actual appscale-run-instances call
fake_port = 8080
fake_host = 'fake_host'
flexmock(AppScaleTools)
AppScaleTools.should_receive('upload_app').and_return(
(fake_host, fake_port))
app = '/bar/app'
(host, port) = appscale.deploy(app)
self.assertEquals(fake_host, host)
self.assertEquals(fake_port, port)
示例3: test_all_ok
def test_all_ok(self):
# If the user wants to relocate their app to port X, and nothing else
# runs on that port, this should succeed.
# Assume that the AppController is running, so is our app, and that other
# apps are not running on port 80.
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_app_info_map').with_args(
'the secret').and_return(json.dumps({
self.appid : {
'nginx' : 8080
},
'a-different-app' : {
'nginx' : 81
}
}))
fake_appcontroller.should_receive('relocate_app').with_args(self.appid, 80,
443, 'the secret').and_return("OK")
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
rh = flexmock(RemoteHelper)
rh.should_receive('sleep_until_port_is_open').and_return()
argv = [
'--keyname', self.keyname,
'--appname', self.appid,
'--http_port', '80',
'--https_port', '443'
]
options = ParseArgs(argv, self.function).args
AppScaleTools.relocate_app(options)
示例4: upgrade
def upgrade(self):
""" Allows users to upgrade to the latest version of AppScale."""
contents_as_yaml = yaml.safe_load(self.read_appscalefile())
# Construct the appscale-upgrade command from argv and the contents of
# the AppScalefile.
command = []
if 'keyname' in contents_as_yaml:
command.append("--keyname")
command.append(contents_as_yaml['keyname'])
if 'verbose' in contents_as_yaml and contents_as_yaml['verbose'] == True:
command.append("--verbose")
if 'ips_layout' in contents_as_yaml:
command.append('--ips_layout')
command.append(
base64.b64encode(yaml.dump(contents_as_yaml['ips_layout'])))
if 'login' in contents_as_yaml:
command.extend(['--login', contents_as_yaml['login']])
if 'test' in contents_as_yaml and contents_as_yaml['test'] == True:
command.append('--test')
options = ParseArgs(command, 'appscale-upgrade').args
options.ips = yaml.safe_load(base64.b64decode(options.ips_layout))
options.terminate = False
options.clean = False
AppScaleTools.upgrade(options)
示例5: logs
def logs(self, location, other_args=None):
""" 'logs' provides a cleaner experience for users than the
appscale-gather-logs command, by using the configuration options present in
the AppScalefile found in the current working directory.
Args:
location: The path on the local filesystem where logs should be copied to.
other_args: A list of other args from sys.argv.
Raises:
AppScalefileException: If there is no AppScalefile in the current working
directory.
"""
contents = self.read_appscalefile()
contents_as_yaml = yaml.safe_load(contents)
# construct the appscale-gather-logs command
command = []
if 'keyname' in contents_as_yaml:
command.append("--keyname")
command.append(contents_as_yaml["keyname"])
command.append("--location")
command.append(location)
if other_args:
command += other_args
# and exec it
options = ParseArgs(command, "appscale-gather-logs").args
AppScaleTools.gather_logs(options)
示例6: testUndeployWithCloudAppScalefile
def testUndeployWithCloudAppScalefile(self):
# calling 'appscale undeploy app' with an AppScalefile in the local
# directory should collect any parameters needed for the
# 'appscale-remove-app' command and then exec it
appscale = AppScale()
# Mock out the actual file reading itself, and slip in a YAML-dumped
# file
contents = {
'infrastructure' : 'ec2',
'machine' : 'ami-ABCDEFG',
'keyname' : 'bookey',
'group' : 'boogroup',
'verbose' : True,
'min_machines' : 1,
'max_machines' : 1
}
yaml_dumped_contents = yaml.dump(contents)
self.addMockForAppScalefile(appscale, yaml_dumped_contents)
# finally, mock out the actual appscale-run-instances call
flexmock(AppScaleTools)
AppScaleTools.should_receive('remove_app')
app = 'barapp'
appscale.undeploy(app)
示例7: set
def set(self, property_name, property_value):
""" 'set' provides a cleaner experience for users than the
appscale-set-property command, by using the configuration options present in
the AppScalefile found in the current working directory.
Args:
property_name: A str naming the AppController instance variable that
should be overwritten.
property_value: The new value that should be used for the named property.
Raises:
AppScalefileException: If there is no AppScalefile in the current working
directory.
"""
contents = self.read_appscalefile()
contents_as_yaml = yaml.safe_load(contents)
# construct the appscale-set-property command
command = []
if 'keyname' in contents_as_yaml:
command.append("--keyname")
command.append(contents_as_yaml["keyname"])
command.append("--property_name")
command.append(property_name)
command.append("--property_value")
command.append(property_value)
# and exec it
options = ParseArgs(command, "appscale-set-property").args
AppScaleTools.set_property(options)
示例8: up
def up(self):
""" Starts an AppScale deployment with the configuration options from the
AppScalefile in the current directory.
Raises:
AppScalefileException: If there is no AppScalefile in the current
directory.
"""
contents = self.read_appscalefile()
# If running in a cluster environment, we first need to set up SSH keys
contents_as_yaml = yaml.safe_load(contents)
if not LocalState.ensure_appscalefile_is_up_to_date():
contents = self.read_appscalefile()
contents_as_yaml = yaml.safe_load(contents)
# Construct a run-instances command from the file's contents
command = []
for key, value in contents_as_yaml.items():
if key in self.DEPRECATED_ASF_ARGS:
raise AppScalefileException(
"'{0}' has been deprecated. Refer to {1} to see the full changes.".
format(key, NodeLayout.APPSCALEFILE_INSTRUCTIONS ))
if value is True:
command.append(str("--%s" % key))
elif value is False:
pass
else:
if key == "ips_layout":
command.append("--ips_layout")
command.append(base64.b64encode(yaml.dump(value)))
elif key == "disks":
command.append("--disks")
command.append(base64.b64encode(yaml.dump(value)))
elif key == "user_commands":
command.append("--user_commands")
command.append(base64.b64encode(yaml.dump(value)))
else:
command.append(str("--%s" % key))
command.append(str("%s" % value))
run_instances_opts = ParseArgs(command, "appscale-run-instances").args
if 'infrastructure' not in contents_as_yaml:
# Generate a new keypair if necessary.
if not self.valid_ssh_key(contents_as_yaml, run_instances_opts):
add_keypair_command = []
if 'keyname' in contents_as_yaml:
add_keypair_command.append('--keyname')
add_keypair_command.append(str(contents_as_yaml['keyname']))
add_keypair_command.append('--ips_layout')
add_keypair_command.append(
base64.b64encode(yaml.dump(contents_as_yaml['ips_layout'])))
add_keypair_opts = ParseArgs(
add_keypair_command, 'appscale-add-keypair').args
AppScaleTools.add_keypair(add_keypair_opts)
AppScaleTools.run_instances(run_instances_opts)
示例9: testDownWithEC2EnvironmentVariables
def testDownWithEC2EnvironmentVariables(self):
# if the user wants us to use their EC2 credentials when running AppScale,
# we should make sure they get set
appscale = AppScale()
# Mock out the actual file reading itself, and slip in a YAML-dumped
# file
contents = {
'infrastructure' : 'ec2',
'machine' : 'ami-ABCDEFG',
'keyname' : 'bookey',
'group' : 'boogroup',
'min_machines' : 1,
'max_machines' : 1,
'EC2_ACCESS_KEY' : 'access key',
'EC2_SECRET_KEY' : 'secret key'
}
yaml_dumped_contents = yaml.dump(contents)
self.addMockForAppScalefile(appscale, yaml_dumped_contents)
# finally, mock out the actual appscale-terminate-instances call
flexmock(AppScaleTools)
AppScaleTools.should_receive('terminate_instances')
appscale.down()
self.assertEquals('access key', os.environ['EC2_ACCESS_KEY'])
self.assertEquals('secret key', os.environ['EC2_SECRET_KEY'])
示例10: testUpWithMalformedClusterAppScalefile
def testUpWithMalformedClusterAppScalefile(self):
# if we try to use an IPs layout that isn't a dictionary, we should throw up
# and die
appscale = AppScale()
# Mock out the actual file reading itself, and slip in a YAML-dumped
# file, with an IPs layout that is a str
contents = {
'ips_layout': "'master' 'ip1' 'appengine' 'ip1'",
'keyname': 'boobazblarg', 'group' : 'boobazblarg', 'EC2_ACCESS_KEY': '',
'EC2_SECRET_KEY': ''
}
yaml_dumped_contents = yaml.dump(contents)
self.addMockForAppScalefile(appscale, yaml_dumped_contents)
flexmock(os.path)
os.path.should_call('exists')
os.path.should_receive('exists').with_args(
'/boo/' + appscale.APPSCALEFILE).and_return(True)
# finally, mock out the actual appscale tools calls. since we're running
# via a cluster, this means we call add-keypair to set up SSH keys, then
# run-instances to start appscale
flexmock(AppScaleTools)
AppScaleTools.should_receive('add_keypair')
self.assertRaises(BadConfigurationException, appscale.up)
示例11: testDeployWithCloudAppScalefileAndTestFlag
def testDeployWithCloudAppScalefileAndTestFlag(self):
# same as before, but with the 'test' flag in our AppScalefile
appscale = AppScale()
# Mock out the actual file reading itself, and slip in a YAML-dumped
# file
contents = {
'infrastructure' : 'ec2',
'machine' : 'ami-ABCDEFG',
'keyname' : 'bookey',
'group' : 'boogroup',
'verbose' : True,
'min' : 1,
'max' : 1,
'test' : True
}
yaml_dumped_contents = yaml.dump(contents)
self.addMockForAppScalefile(appscale, yaml_dumped_contents)
# finally, mock out the actual appscale-run-instances call
fake_port = 8080
fake_host = 'fake_host'
flexmock(AppScaleTools)
AppScaleTools.should_receive('upload_app').and_return(
(fake_host, fake_port))
app = '/bar/app'
(host, port) = appscale.deploy(app)
self.assertEquals(fake_host, host)
self.assertEquals(fake_port, port)
示例12: test_remove_app_and_app_is_running
def test_remove_app_and_app_is_running(self):
# mock out reading from stdin, and assume the user says 'YES'
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_receive('raw_input').and_return('YES')
# mock out reading the secret key
builtins.should_call('open') # set the fall-through
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
app_stats_data = {'apps': {'blargapp': {'http': 8080, 'language': 'python27',
'total_reqs': 'no_change', 'appservers': 1, 'https': 4380, 'reqs_enqueued': None}}}
# mock out the SOAP call to the AppController and assume it succeeded
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('status').with_args('the secret') \
.and_return('Database is at public1')
fake_appcontroller.should_receive('stop_app').with_args('blargapp',
'the secret').and_return('OK')
fake_appcontroller.should_receive('is_app_running').with_args('blargapp',
'the secret').and_return(True).and_return(True).and_return(False)
fake_appcontroller.should_receive('does_app_exist').with_args('blargapp',
'the secret').and_return(True)
fake_appcontroller.should_receive('get_all_stats').with_args(
'the secret').and_return(json.dumps(app_stats_data))
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# mock out reading the locations.json file, and slip in our own json
flexmock(os.path)
os.path.should_call('exists') # set the fall-through
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(
json.dumps({"node_info": [{
"public_ip": "public1",
"private_ip": "private1",
"jobs": ["shadow", "login"]
}]}))
fake_nodes_json.should_receive('write').and_return()
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
flexmock(RemoteHelper).should_receive('is_port_open').and_return(False)
argv = [
"--appname", "blargapp",
"--keyname", self.keyname
]
options = ParseArgs(argv, self.function).args
AppScaleTools.remove_app(options)
示例13: test_describe_instances_with_two_nodes
def test_describe_instances_with_two_nodes(self):
# mock out writing the secret key to ~/.appscale, as well as reading it
# later
builtins = flexmock(sys.modules['__builtin__'])
builtins.should_call('open') # set the fall-through
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
fake_secret.should_receive('write').and_return()
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# mock out the SOAP call to the AppController and assume it succeeded
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_all_public_ips').with_args('the secret') \
.and_return(json.dumps(['public1', 'public2']))
fake_appcontroller.should_receive('status').with_args('the secret') \
.and_return('nothing interesting here') \
.and_return('Database is at not-up-yet') \
.and_return('Database is at 1.2.3.4')
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
SOAPpy.should_receive('SOAPProxy').with_args('https://public2:17443') \
.and_return(fake_appcontroller)
# mock out reading the locations.json file, and slip in our own json
flexmock(os.path)
os.path.should_call('exists') # set the fall-through
os.path.should_receive('exists').with_args(
LocalState.get_locations_json_location(self.keyname)).and_return(True)
fake_nodes_json = flexmock(name="fake_nodes_json")
fake_nodes_json.should_receive('read').and_return(json.dumps(
{"node_info": [{
"public_ip": "public1",
"private_ip": "private1",
"jobs": ["shadow", "login"]
},
{
"public_ip": "public2",
"private_ip": "private2",
"jobs": ["appengine"]
},
]}))
fake_nodes_json.should_receive('write').and_return()
builtins.should_receive('open').with_args(
LocalState.get_locations_json_location(self.keyname), 'r') \
.and_return(fake_nodes_json)
# assume that there are two machines running in our deployment
argv = [
"--keyname", self.keyname
]
options = ParseArgs(argv, self.function).args
AppScaleTools.describe_instances(options)
示例14: down
def down(self, clean=False, terminate=False):
""" 'down' provides a nicer experience for users than the
appscale-terminate-instances command, by using the configuration options
present in the AppScalefile found in the current working directory.
Args:
clean: A boolean to indicate if the deployment data and metadata
needs to be clean. This will clear the datastore.
terminate: A boolean to indicate if instances needs to be terminated
(valid only if we spawn instances at start).
Raises:
AppScalefileException: If there is no AppScalefile in the current working
directory.
"""
contents = self.read_appscalefile()
# Construct a terminate-instances command from the file's contents
command = []
contents_as_yaml = yaml.safe_load(contents)
if 'verbose' in contents_as_yaml and contents_as_yaml['verbose'] == True:
command.append("--verbose")
if 'keyname' in contents_as_yaml:
keyname = contents_as_yaml['keyname']
command.append("--keyname")
command.append(contents_as_yaml['keyname'])
else:
keyname = 'appscale'
if clean:
if 'test' not in contents_as_yaml or contents_as_yaml['test'] != True:
LocalState.confirm_or_abort("Clean will delete every data in the deployment.")
command.append("--clean")
if terminate:
infrastructure = LocalState.get_infrastructure(keyname)
if infrastructure != "xen" and not LocalState.are_disks_used(
keyname) and 'test' not in contents_as_yaml:
LocalState.confirm_or_abort("Terminate will delete instances and the data on them.")
command.append("--terminate")
if 'test' in contents_as_yaml and contents_as_yaml['test'] == True:
command.append("--test")
# Finally, exec the command. Don't worry about validating it -
# appscale-terminate-instances will do that for us.
options = ParseArgs(command, "appscale-terminate-instances").args
AppScaleTools.terminate_instances(options)
LocalState.cleanup_appscale_files(keyname, terminate)
AppScaleLogger.success("Successfully stopped your AppScale deployment.")
示例15: test_terminate_in_cloud_and_succeeds
def test_terminate_in_cloud_and_succeeds(self):
# Deployment is running on EC2.
flexmock(LocalState).should_receive('get_infrastructure').and_return('ec2')
# The secret key exists.
flexmock(os.path).should_receive('exists').and_return(True)
flexmock(RemoteHelper).should_receive('terminate_virtualized_cluster')
argv = ['--keyname', self.keyname,
'--test']
options = ParseArgs(argv, self.function).args
AppScaleTools.terminate_instances(options)