def log_json(self, trans, l_log=0, no_json=False): if no_json: return {'log_messages' : self.app.logger.logmessages[int(l_log):], 'log_cursor' : len(self.app.logger.logmessages)} else: return to_json_string({'log_messages' : self.app.logger.logmessages[int(l_log):], 'log_cursor' : len(self.app.logger.logmessages)})
def adjust_autoscaling(self, trans, as_min_adj=None, as_max_adj=None): if self.app.manager.get_services('Autoscale'): if self.check_as_vals(as_min_adj, as_max_adj): # log.debug("Adjusting autoscaling; new bounds min: %s, max: %s" % (as_min_adj, as_max_adj)) self.app.manager.adjust_autoscaling(int(as_min_adj), int(as_max_adj)) else: log.error("Invalid values to adjust autoscaling bounds (min: %s, max: %s)." % (as_min_adj, as_max_adj)) return to_json_string({'running' : True, 'as_min' : self.app.manager.get_services('Autoscale')[0].as_min, 'as_max' : self.app.manager.get_services('Autoscale')[0].as_max, 'ui_update_data' : self.instance_state_json(trans, no_json=True)}) else: return to_json_string({'running' : False, 'as_min' : 0, 'as_max' : 0, 'ui_update_data' : self.instance_state_json(trans, no_json=True)})
def toggle_autoscaling(self, trans, as_min=None, as_max=None, as_instance_type=None): if self.app.manager.get_services('Autoscale'): log.debug("Turning autoscaling OFF") self.app.manager.stop_autoscaling() else: log.debug("Turning autoscaling ON") if self.check_as_vals(as_min, as_max): self.app.manager.start_autoscaling(int(as_min), int(as_max), as_instance_type) else: log.error("Invalid values for autoscaling bounds (min: %s, max: %s). Autoscaling is OFF." % (as_min, as_max)) if self.app.manager.get_services('Autoscale'): return to_json_string({'running' : True, 'as_min' : self.app.manager.get_services('Autoscale')[0].as_min, 'as_max' : self.app.manager.get_services('Autoscale')[0].as_max, 'ui_update_data' : self.instance_state_json(trans, no_json=True)}) else: return to_json_string({'running' : False, 'as_min' : 0, 'as_max' : 0, 'ui_update_data' : self.instance_state_json(trans, no_json=True)})
def static_instance_state_json(self, trans, no_json=False): ret_dict = {'master_ip': self.app.cloud_interface.get_public_ip(), 'master_id': self.app.cloud_interface.get_instance_id(), 'ami_id' : self.app.cloud_interface.get_ami(), 'availability_zone' : self.app.cloud_interface.get_zone(), 'key_pair_name' : self.app.cloud_interface.get_key_pair_name(), 'security_groups' : self.app.cloud_interface.get_security_groups(), 'master_host_name': self.app.cloud_interface.get_public_hostname() } if no_json: return ret_dict else: return to_json_string(ret_dict)
def get_all_services_status(self, trans): status_dict = self.app.manager.get_all_services_status() #status_dict['filesystems'] = self.app.manager.get_all_filesystems_status() status_dict['galaxy_dns'] = self.get_galaxy_dns() status_dict['galaxy_rev'] = self.app.manager.get_galaxy_rev() status_dict['galaxy_admins'] = self.app.manager.get_galaxy_admins() snap_status = self.app.manager.snapshot_status() status_dict['snapshot'] = {'status' : str(snap_status[0]), 'progress' : str(snap_status[1])} status_dict['master_is_exec_host'] = self.app.manager.master_exec_host status_dict['messages'] = self.messages_string(self.app.msgs.get_messages()) #status_dict['dummy'] = str(datetime.now()) # Used for testing only return to_json_string(status_dict)
def instance_state_json(self, trans, no_json=False): dns = self.get_galaxy_dns() snap_status = self.app.manager.snapshot_status() ret_dict = {'cluster_status': self.app.manager.get_cluster_status(), 'dns': dns, 'instance_status': {'idle': str(len(self.app.manager.get_idle_instances())), 'available' : str(self.app.manager.get_num_available_workers()), 'requested' : str(len(self.app.manager.worker_instances))}, 'disk_usage': {'used':str(self.app.manager.disk_used), 'total':str(self.app.manager.disk_total), 'pct':str(self.app.manager.disk_pct)}, 'data_status': self.app.manager.get_data_status(), 'app_status': self.app.manager.get_app_status(), 'all_fs' : self.app.manager.all_fs_status_array(), 'snapshot' : {'status' : str(snap_status[0]), 'progress' : str(snap_status[1])}, 'autoscaling': {'use_autoscaling': bool(self.app.manager.get_services('Autoscale')), 'as_min': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_min, 'as_max': 'N/A' if not self.app.manager.get_services('Autoscale') else self.app.manager.get_services('Autoscale')[0].as_max} } if no_json: return ret_dict else: return to_json_string(ret_dict)
def update_users_CM(self, trans): return to_json_string({'updated':self.app.manager.update_users_CM()})
def get_user_data(self, trans): return to_json_string(self.app.ud)
def get_shared_instances(self, trans): return to_json_string({'shared_instances': self.app.manager.get_shared_instances()})
def instance_feed_json(self, trans): dict_feed = {'instances' : [self.app.manager.get_status_dict()] + [x.get_status_dict() for x in self.app.manager.worker_instances]} return to_json_string(dict_feed)
def full_update(self, trans, l_log=0): return to_json_string({ 'ui_update_data' : self.instance_state_json(trans, no_json=True), 'log_update_data' : self.log_json(trans, l_log, no_json=True), 'messages': self.messages_string(self.app.msgs.get_messages())})
def get_all_filesystems(self, trans): return to_json_string(self.app.manager.get_all_filesystems_status())
def get_srvc_status(self, trans, srvc): return to_json_string({'srvc': srvc, 'status': self.app.manager.get_srvc_status(srvc)})