def vm_stats(caller_id, vm_id, stat_name, time, stat_range, resolution): """ Function returns requested statistics for specific VM. Stats are returned in format required by CC1 Web Interface's monitoring javascript. @cmview_admin_cm @param_post{vm_id} @param_post{stat_name,string|list(string)} type of required statistics @param_post{time,int} time of last row @param_post{stat_range,string} time interval between first and last stats @param_post{resolution,string} statistics resolution @response{list} usage of VM resources (format required by CC1 Web Interface) """ vm_u = VM.admin_get(vm_id).long_dict['user_id'] if type(stat_name) is int: stat_name = [stat_name] n = [] for stat in stat_name: n.append(stat_names.keys()[stat_names.values().index(stat)]) p = int(stat_ranges.keys()[stat_ranges.values().index(int(stat_range))]) r = int( stat_resolutions.keys()[stat_resolutions.values().index(resolution)]) return RrdHandler().get_vm_stats('vm-%d-%d' % (vm_id, vm_u), n, int(time) - p, time, r)
def vm_stats(caller_id, vm_id, stat_name, time, stat_range, resolution): """ Function returns statistics for specific \c vmid. @decoratedby{src.cm.utils.decorators.user_log} @parameter{vmid} @parameter{stat_name,string} type of required statistics @parameter{time,string} time of last row @parameter{range,string} period of time from time to past @parameter{resolution,string} statistics resolution @response{dict} list of the total usage of VM resources from start VM """ vm_u = VM.admin_get(vm_id).long_dict['user_id'] if type(stat_name) is int: stat_name = [stat_name] n = [] for stat in stat_name: n.append(stat_names.keys()[stat_names.values().index(stat)]) p = int(stat_ranges.keys()[stat_ranges.values().index(int(stat_range))]) r = int(stat_resolutions.keys()[stat_resolutions.values().index(resolution)]) return RrdHandler().get_vm_stats('vm-%d-%d' % (vm_id, vm_u), n, int(time) - p, time, r)
def vm_stats(caller_id, vm_id, stat_name, time, stat_range, resolution): """ Function returns requested statistics for specific VM. Stats are returned in format required by CC1 Web Interface's monitoring javascript. @cmview_admin_cm @param_post{vm_id} @param_post{stat_name,string|list(string)} type of required statistics @param_post{time,int} time of last row @param_post{stat_range,string} time interval between first and last stats @param_post{resolution,string} statistics resolution @response{list} usage of VM resources (format required by CC1 Web Interface) """ vm_u = VM.admin_get(vm_id).long_dict['user_id'] if type(stat_name) is int: stat_name = [stat_name] n = [] for stat in stat_name: n.append(stat_names.keys()[stat_names.values().index(stat)]) p = int(stat_ranges.keys()[stat_ranges.values().index(int(stat_range))]) r = int(stat_resolutions.keys()[stat_resolutions.values().index(resolution)]) return RrdHandler().get_vm_stats('vm-%d-%d' % (vm_id, vm_u), n, int(time) - p, time, r)
def get_by_id(caller_id, vm_id): """ @cmview_admin_cm @param_post{vm_id} id of the requested VM @response{dict} VM with id @prm{id} """ vm = VM.admin_get(vm_id) vm_mod = vm.long_dict return vm_mod
def erase(caller_id, vm_id_list): """ Cleans up after each of the specified VMs. Erase should be called for failed machines after the inspection of the failure. @cmview_admin_cm @param_post{vm_id_list,list} list of VM id's """ for vm_id in vm_id_list: vm = VM.admin_get(vm_id) VM.erase(vm)
def detach_vnc(caller_id, vm_id): """ Detaches VNC redirection from VM. @cmview_admin_cm @param_post{vm_id,int} id of the VM to have detached VM redirection """ vm = VM.admin_get(vm_id) vm.detach_vnc() try: vm.save() except: raise CMException('vnc_detach')
def erase(caller_id, vm_id_list): """ Method cleans up after each of VM, which id is in \c vm_ids. Should be called for failed machines. @cmview_admin_cm @parameter{vm_id_list,list} list of vm id's @noresponse """ for vm_id in vm_id_list: vm = VM.admin_get(vm_id) VM.erase(vm)
def destroy(caller_id, vm_id_list): """ Method destroyes VMs with ids listed in \c vm_ids. @cmview_admin_cm @parameter{vm_ids,list} list of vm id's @response{src.cm.views.utils.image.destroy()} """ vms = [] for vm_id in vm_id_list: vms.append(VM.admin_get(vm_id)) return VM.destroy(vms)
def destroy(caller_id, vm_id_list): """ Destroyes specified VMs. Destroyed VM can in no way be recovered. @cmview_admin_cm @param_post{vm_id_list,list} ids to destroy @response{src.cm.views.utils.image.destroy()} """ vms = [] for vm_id in vm_id_list: vms.append(VM.admin_get(vm_id)) return VM.destroy(vms)
def detach_vnc(caller_id, vm_id): """ Detaches VNC redirection from VM. @cmview_user @parameter{vm_id,int} id of the VM to have detached VM redirection @response{None} """ vm = VM.admin_get(vm_id) vm.detach_vnc() try: vm.save() except: raise CMException('vnc_detach')
def edit(caller_id, vm_id, name, description): """ Change vm parameters. You should get them by vm.get_by_id. @cmview_admin_cm @parameter{vm_id} @parameter{name} new VM name @parameter{description} new VM description @response{src.cm.views.utils.vm.edit()} """ vm = VM.admin_get(vm_id) vm.name = name vm.description = description vm.save()
def edit(caller_id, vm_id, name, description): """ Updates VM attributes. @cmview_admin_cm @param_post{vm_id} @param_post{name} (optional) new VM name @param_post{description} (optional) new VM description @response{src.cm.views.utils.vm.edit()} """ vm = VM.admin_get(vm_id) vm.name = name vm.description = description vm.save()
def save_and_shutdown(caller_id, vm_id, name, description): """ Saves and shutdowns specified VM, without checking User quota. @cmview_admin_cm @param_post{vm_id,string} id of the VM to save @param_post{name,string} @param_post{description,string} """ vm = VM.admin_get(vm_id) user = User.get(vm.user.id) if user.used_storage + vm.system_image.size > user.storage: raise CMException('user_storage_limit') VM.save_and_shutdown(user.id, vm, name, description)
def save_and_shutdown(caller_id, vm_id, name, description): """ Method calls save_and_shutdown for each VM with id is in @prm{vm_id} (for administrator only). @cmview_admin_cm @parameter{vm_id,string} @parameter{name,string} @parameter{description,string} """ vm = VM.admin_get(vm_id) user = User.get(vm.user.id) if user.used_storage + vm.system_image.size > user.storage: raise CMException('user_storage_limit') VM.save_and_shutdown(user.id, vm, name, description)