本文整理汇总了Python中appcontroller_client.AppControllerClient类的典型用法代码示例。如果您正苦于以下问题:Python AppControllerClient类的具体用法?Python AppControllerClient怎么用?Python AppControllerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AppControllerClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: relocate_app
def relocate_app(cls, options):
"""Instructs AppScale to move the named application to a different port.
Args:
options: A Namespace that has fields for each parameter that can be passed
in via the command-line interface.
Raises:
AppScaleException: If the named application isn't running in this AppScale
cloud, if the destination port is in use by a different application, or
if the AppController rejects the request to relocate the application (in
which case it includes the reason why the rejection occurred).
"""
login_host = LocalState.get_login_host(options.keyname)
acc = AppControllerClient(login_host, LocalState.get_secret_key(
options.keyname))
app_info_map = acc.get_app_info_map()
if options.appname not in app_info_map.keys():
raise AppScaleException("The given application, {0}, is not currently " \
"running in this AppScale cloud, so we can't move it to a different " \
"port.".format(options.appname))
relocate_result = acc.relocate_app(options.appname, options.http_port,
options.https_port)
if relocate_result == "OK":
AppScaleLogger.success("Successfully issued request to move {0} to " \
"ports {1} and {2}.".format(options.appname, options.http_port,
options.https_port))
AppScaleLogger.success("Your app serves unencrypted traffic at: " +
"http://{0}:{1}".format(login_host, options.http_port))
AppScaleLogger.success("Your app serves encrypted traffic at: " +
"https://{0}:{1}".format(login_host, options.https_port))
else:
raise AppScaleException(relocate_result)
示例2: add_instances
def add_instances(cls, options):
"""Adds additional machines to an AppScale deployment.
Args:
options: A Namespace that has fields for each parameter that can be
passed in via the command-line interface.
"""
if 'master' in options.ips.keys():
raise BadConfigurationException("Cannot add master nodes to an " + \
"already running AppScale deployment.")
# Skip checking for -n (replication) because we don't allow the user
# to specify it here (only allowed in run-instances).
additional_nodes_layout = NodeLayout(options)
# In virtualized cluster deployments, we need to make sure that the user
# has already set up SSH keys.
if LocalState.get_from_yaml(options.keyname, 'infrastructure') == "xen":
for ip in options.ips.values():
# throws a ShellException if the SSH key doesn't work
RemoteHelper.ssh(ip, options.keyname, "ls", options.verbose)
# Finally, find an AppController and send it a message to add
# the given nodes with the new roles.
AppScaleLogger.log("Sending request to add instances")
login_ip = LocalState.get_login_host(options.keyname)
acc = AppControllerClient(login_ip, LocalState.get_secret_key(
options.keyname))
acc.start_roles_on_nodes(json.dumps(options.ips))
# TODO(cgb): Should we wait for the new instances to come up and get
# initialized?
AppScaleLogger.success("Successfully sent request to add instances " + \
"to this AppScale deployment.")
示例3: ensure_appscale_isnt_running
def ensure_appscale_isnt_running(cls, keyname, force):
"""Checks the secret key file to see if AppScale is running, and
aborts if it is.
Args:
keyname: The keypair name that is used to identify AppScale deployments.
force: A bool that is used to run AppScale even if the secret key file
is present.
Raises:
BadConfigurationException: If AppScale is already running.
"""
if force:
return
if os.path.exists(cls.get_secret_key_location(keyname)):
try:
login_host = cls.get_login_host(keyname)
secret_key = cls.get_secret_key(keyname)
except (IOError, AppScaleException, BadConfigurationException):
# If we don't have the locations files, we are not running.
return
acc = AppControllerClient(login_host, secret_key)
try:
acc.get_all_public_ips()
except AppControllerException:
# AC is not running, so we assume appscale is not up and running.
AppScaleLogger.log("AppController not running on login node.")
else:
raise BadConfigurationException("AppScale is already running. Terminate" +
" it, set 'force: True' in your AppScalefile, or use the --force flag" +
" to run anyways.")
示例4: gather_logs
def gather_logs(cls, options):
"""Collects logs from each machine in the currently running AppScale
deployment.
Args:
options: A Namespace that has fields for each parameter that can be
passed in via the command-line interface.
"""
# First, make sure that the place we want to store logs doesn't
# already exist.
if os.path.exists(options.location):
raise AppScaleException("Can't gather logs, as the location you " + \
"specified, {0}, already exists.".format(options.location))
acc = AppControllerClient(LocalState.get_login_host(options.keyname),
LocalState.get_secret_key(options.keyname))
# do the mkdir after we get the secret key, so that a bad keyname will
# cause the tool to crash and not create this directory
os.mkdir(options.location)
for ip in acc.get_all_public_ips():
# Get the logs from each node, and store them in our local directory
local_dir = "{0}/{1}".format(options.location, ip)
os.mkdir(local_dir)
RemoteHelper.scp_remote_to_local(ip, options.keyname, '/var/log/appscale',
local_dir, options.verbose)
AppScaleLogger.success("Successfully copied logs to {0}".format(
options.location))
示例5: remove_app
def remove_app(cls, options):
"""Instructs AppScale to no longer host the named application.
Args:
options: A Namespace that has fields for each parameter that can be
passed in via the command-line interface.
"""
if not options.confirm:
response = raw_input("Are you sure you want to remove this " + \
"application? (Y/N) ")
if response not in ['y', 'yes', 'Y', 'YES']:
raise AppScaleException("Cancelled application removal.")
login_host = LocalState.get_login_host(options.keyname)
acc = AppControllerClient(login_host, LocalState.get_secret_key(
options.keyname))
userappserver_host = acc.get_uaserver_host(options.verbose)
userappclient = UserAppClient(userappserver_host, LocalState.get_secret_key(
options.keyname))
if not userappclient.does_app_exist(options.appname):
raise AppScaleException("The given application is not currently running.")
acc.stop_app(options.appname)
AppScaleLogger.log("Please wait for your app to shut down.")
while True:
if acc.is_app_running(options.appname):
time.sleep(cls.SLEEP_TIME)
else:
break
AppScaleLogger.success("Done shutting down {0}".format(options.appname))
示例6: test_set_deployment_id
def test_set_deployment_id(self):
host = 'boo'
secret = 'baz'
# The function should return whatever run_with_timeout_returns.
flexmock(AppControllerClient).should_receive('run_with_timeout')\
.and_return()
acc = AppControllerClient(host, secret)
acc.get_deployment_id()
示例7: terminate_virtualized_cluster
def terminate_virtualized_cluster(cls, keyname, is_verbose):
"""Stops all API services running on all nodes 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("Terminating appscale deployment with keyname {0}"
.format(keyname))
time.sleep(2)
shadow_host = LocalState.get_host_with_role(keyname, 'shadow')
try:
secret = LocalState.get_secret_key(keyname)
except IOError:
# We couldn't find the secret key: AppScale is most likely not
# running.
raise AppScaleException("Couldn't find AppScale secret key.")
acc = AppControllerClient(shadow_host, secret)
try:
all_ips = acc.get_all_public_ips()
except Exception as exception:
AppScaleLogger.warn('Saw Exception while getting deployments IPs {0}'.
format(str(exception)))
all_ips = LocalState.get_all_public_ips(keyname)
threads = []
for ip in all_ips:
thread = threading.Thread(target=cls.stop_remote_appcontroller, args=(ip,
keyname, is_verbose))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
boxes_shut_down = 0
is_running_regex = re.compile("appscale-controller stop")
for ip in all_ips:
AppScaleLogger.log("Shutting down AppScale API services at {0}".
format(ip))
while True:
remote_output = cls.ssh(ip, keyname, 'ps x', is_verbose)
AppScaleLogger.verbose(remote_output, is_verbose)
if not is_running_regex.match(remote_output):
break
time.sleep(0.3)
boxes_shut_down += 1
if boxes_shut_down != len(all_ips):
raise AppScaleException("Couldn't terminate your AppScale deployment on"
" all machines - please do so manually.")
AppScaleLogger.log("Terminated AppScale on {0} machines.".
format(boxes_shut_down))
示例8: test_deployment_id_exists
def test_deployment_id_exists(self):
# The function should return whatever run_with_timeout returns.
host = 'boo'
secret = 'baz'
deployment_id_exists = True
flexmock(AppControllerClient).should_receive('run_with_timeout')\
.and_return(deployment_id_exists)
acc = AppControllerClient(host, secret)
self.assertEqual(deployment_id_exists, acc.deployment_id_exists())
示例9: test_get_deployment_id
def test_get_deployment_id(self):
# The function should return whatever run_with_timeout_returns.
host = 'boo'
secret = 'baz'
deployment_id = 'foo'
flexmock(AppControllerClient).should_receive('run_with_timeout')\
.and_return(deployment_id)
acc = AppControllerClient(host, secret)
self.assertEqual(deployment_id, acc.get_deployment_id())
示例10: create_user_accounts
def create_user_accounts(cls, email, password, public_ip, keyname):
"""Registers two new user accounts with the UserAppServer.
One account is the standard account that users log in with (via their
e-mail address. The other is their XMPP account, so that they can log into
any jabber-compatible service and send XMPP messages to their application
(and receive them).
Args:
email: The e-mail address that should be registered for the user's
standard account.
password: The password that should be used for both the standard and XMPP
accounts.
public_ip: The location where the AppController can be found.
keyname: The name of the SSH keypair used for this AppScale deployment.
"""
acc = AppControllerClient(public_ip, LocalState.get_secret_key(keyname))
is_new_user = False
# first, create the standard account
encrypted_pass = LocalState.encrypt_password(email, password)
if acc.does_user_exist(email):
AppScaleLogger.log("User {0} already exists, so not creating it again.".
format(email))
else:
acc.create_user(email, encrypted_pass)
is_new_user = True
# next, create the XMPP account. if the user's e-mail is [email protected], then that
# means their XMPP account name is [email protected]_ip
username_regex = re.compile('\A(.*)@')
username = username_regex.match(email).groups()[0]
try:
login_host = acc.get_property('login')['login']
except KeyError:
raise AppControllerException('login property not found')
xmpp_user = "{0}@{1}".format(username, login_host)
xmpp_pass = LocalState.encrypt_password(xmpp_user, password)
is_xmpp_user_exist = acc.does_user_exist(xmpp_user)
if is_xmpp_user_exist and is_new_user:
AppScaleLogger.log("XMPP User {0} conflict!".format(xmpp_user))
generated_xmpp_username = LocalState.generate_xmpp_username(username)
xmpp_user = "{0}@{1}".format(generated_xmpp_username, login_host)
xmpp_pass = LocalState.encrypt_password(xmpp_user, password)
acc.create_user(xmpp_user, xmpp_pass)
elif is_xmpp_user_exist and not is_new_user:
AppScaleLogger.log("XMPP User {0} already exists, so not creating it again.".format(xmpp_user))
else:
acc.create_user(xmpp_user, xmpp_pass)
AppScaleLogger.log("Your XMPP username is {0}".format(xmpp_user))
示例11: get_deployment_id
def get_deployment_id(cls, head_node, keyname):
""" Retrieve this AppScale deployment's ID.
Args:
head_node: A string containing the IP address of the head node.
keyname: A string representing the SSH keypair name used for this
AppScale deployment.
"""
secret = LocalState.get_secret_key(keyname)
acc = AppControllerClient(head_node, secret)
return acc.get_deployment_id()
示例12: gather_logs
def gather_logs(cls, options):
"""Collects logs from each machine in the currently running AppScale
deployment.
Args:
options: A Namespace that has fields for each parameter that can be
passed in via the command-line interface.
"""
# First, make sure that the place we want to store logs doesn't
# already exist.
if os.path.exists(options.location):
raise AppScaleException("Can't gather logs, as the location you " + \
"specified, {0}, already exists.".format(options.location))
acc = AppControllerClient(LocalState.get_login_host(options.keyname),
LocalState.get_secret_key(options.keyname))
try:
all_ips = acc.get_all_public_ips()
except socket.error: # Occurs when the AppController has failed.
AppScaleLogger.warn("Couldn't get an up-to-date listing of the " + \
"machines in this AppScale deployment. Using our locally cached " + \
"info instead.")
all_ips = LocalState.get_all_public_ips(options.keyname)
# do the mkdir after we get the secret key, so that a bad keyname will
# cause the tool to crash and not create this directory
os.mkdir(options.location)
for ip in all_ips:
# Get the logs from each node, and store them in our local directory
local_dir = "{0}/{1}".format(options.location, ip)
os.mkdir(local_dir)
RemoteHelper.scp_remote_to_local(ip, options.keyname, '/var/log/appscale',
local_dir, options.verbose)
try:
RemoteHelper.scp_remote_to_local(ip, options.keyname,
'/var/log/cassandra', local_dir, options.verbose)
except ShellException:
pass
try:
RemoteHelper.scp_remote_to_local(ip, options.keyname,
'/var/log/zookeeper', local_dir, options.verbose)
except ShellException:
pass
RemoteHelper.scp_remote_to_local(ip, options.keyname, '/var/log/kern.log',
local_dir, options.verbose)
RemoteHelper.scp_remote_to_local(ip, options.keyname, '/var/log/syslog',
local_dir, options.verbose)
AppScaleLogger.success("Successfully copied logs to {0}".format(
options.location))
示例13: set_deployment_id
def set_deployment_id(cls, head_node, keyname, deployment_id):
""" Set a deployment ID to use for communicating with the AppScale
Portal.
Args:
head_node: A string containing the IP address of the head node.
keyname: A string representing the SSH keypair name used for this
AppScale deployment.
deployment_id: A string containing the deployment ID.
"""
secret = LocalState.get_secret_key(keyname)
acc = AppControllerClient(head_node, secret)
acc.set_deployment_id(deployment_id)
示例14: remove_app
def remove_app(cls, options):
"""Instructs AppScale to no longer host the named application.
Args:
options: A Namespace that has fields for each parameter that can be
passed in via the command-line interface.
"""
if not options.confirm:
response = raw_input("Are you sure you want to remove this application? (y/N) ")
if response.lower() not in ["y", "yes"]:
raise AppScaleException("Cancelled application removal.")
login_host = LocalState.get_login_host(options.keyname)
secret = LocalState.get_secret_key(options.keyname)
acc = AppControllerClient(login_host, secret)
if not acc.is_app_running(options.appname):
raise AppScaleException("The given application is not currently running.")
# Makes a call to the AppController to get all the stats and looks
# through them for the http port the app can be reached on.
http_port = None
for _ in range(cls.MAX_RETRIES + 1):
result = acc.get_all_stats()
try:
json_result = json.loads(result)
apps_result = json_result["apps"]
current_app = apps_result[options.appname]
http_port = current_app["http"]
if http_port:
break
time.sleep(cls.SLEEP_TIME)
except (KeyError, ValueError):
AppScaleLogger.verbose("Got json error from get_all_data result.", options.verbose)
time.sleep(cls.SLEEP_TIME)
if not http_port:
raise AppScaleException("Unable to get the serving port for the application.")
acc.stop_app(options.appname)
AppScaleLogger.log("Please wait for your app to shut down.")
for _ in range(cls.MAX_RETRIES + 1):
if RemoteHelper.is_port_open(login_host, http_port, options.verbose):
time.sleep(cls.SLEEP_TIME)
AppScaleLogger.log("Waiting for {0} to terminate...".format(options.appname))
else:
AppScaleLogger.success("Done shutting down {0}.".format(options.appname))
return
AppScaleLogger.warn("App {0} may still be running.".format(options.appname))
示例15: set_property
def set_property(cls, options):
"""Instructs AppScale to replace the value it uses for a particular
AppController instance variable (property) with a new value.
Args:
options: A Namespace that has fields for each parameter that can be passed
in via the command-line interface.
"""
shadow_host = LocalState.get_host_with_role(options.keyname, "shadow")
acc = AppControllerClient(shadow_host, LocalState.get_secret_key(options.keyname))
result = acc.set_property(options.property_name, options.property_value)
if result == "OK":
AppScaleLogger.success("Successfully updated the given property.")
else:
raise AppControllerException("Unable to update the given property " + "because: {0}".format(result))