/controllers/default/c_virtual_machines.php
PHP | 2571 lines | 1630 code | 504 blank | 437 comment | 135 complexity | 4469e4a87f06d6011395b7c20836f0ee MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- require_once( ONAPP_PATH . ONAPP_DS . 'controllers' . ONAPP_DS . ONAPP_CONTROLLERS . ONAPP_DS . 'controller.php');
- class Virtual_Machines extends Controller {
- /**
- * Main controller function
- *
- * @return void
- */
- public function view() {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- $id = onapp_get_arg('id');
- $action = onapp_get_arg('action');
- onapp_debug('id => ' . $id . ' action => ' . $action);
- switch ($action) {
- case 'details':
- $this->show_template_details($id);
- break;
- case 'create_page':
- $this->show_template_create();
- break;
- case 'startup':
- $this->startup($id);
- break;
- case 'reboot':
- $this->reboot($id);
- break;
- case 'shutdown':
- $this->shutdown($id);
- break;
- case 'suspend':
- $this->suspend($id);
- break;
- case 'reset_password':
- $this->reset_password($id);
- break;
- case 'create':
- $this->create();
- break;
- case 'cpu_usage':
- $this->show_template_cpu_usage($id);
- break;
- case 'delete':
- $this->delete($id);
- break;
- case 'rebuild':
- case 'build':
- $this->build($id);
- break;
- case 'backup':
- $this->show_template_backup($id);
- break;
- case 'backup_restore':
- $this->backup_restore($id);
- break;
- case 'backup_convert':
- $this->backup_convert($id);
- break;
- case 'backup_delete':
- $this->backup_delete($id);
- break;
- case 'ip_addresses':
- $this->show_template_ip_addresses($id);
- break;
- case 'rebuild_network':
- $this->rebuild_network($id);
- break;
- case 'ip_address_join_new':
- $this->ip_address_join_new($id);
- break;
- case 'ip_address_delete':
- $this->ip_address_delete($id);
- break;
- case 'network_interfaces':
- $this->show_template_network_interface($id);
- break;
- case 'network_interface_edit':
- $this->network_interface_edit($id);
- break;
- case 'network_interface_delete':
- $this->network_interface_delete($id);
- break;
- case 'network_interface_create':
- $this->network_interface_create($id);
- break;
- case 'disks':
- $this->show_template_disks($id);
- break;
- case 'change_owner':
- $this->change_owner($id);
- break;
- case 'edit':
- $this->edit($id);
- break;
- case 'autobackup_disable':
- $this->autobackup_disable($id);
- break;
- case 'autobackup_enable':
- $this->autobackup_enable($id);
- break;
- case 'disk_edit':
- $this->disk_edit($id);
- break;
- case 'disk_create':
- $this->disk_create($id);
- break;
- case 'disk_delete':
- $this->disk_delete($id);
- break;
- case 'disk_backups':
- $this->show_template_disk_backup($id);
- break;
- case 'disk_backups_schedule':
- $this->show_template_disk_backups_schedule($id);
- break;
- case 'disk_backups_schedule_edit':
- $this->disk_backups_schedule_edit($id);
- break;
- case 'disk_backups_schedule_delete':
- $this->disk_backups_schedule_delete($id);
- break;
- case 'disk_backups_schedule_create':
- $this->disk_backups_schedule_create($id);
- break;
- case 'firewall':
- $this->show_template_firewall($id);
- break;
- case 'firewall_rule_create':
- $this->firewall_rule_create($id);
- break;
- case 'firewall_rule_move':
- $this->firewall_rule_move($id);
- break;
- case 'firewall_rule_delete':
- $this->firewall_rule_delete($id);
- break;
- case 'firewall_rule_edit':
- $this->firewall_rule_edit($id);
- break;
- case 'firewall_rule_update_defaults':
- $this->firewall_rule_update_defaults($id);
- break;
- case 'firewall_rules_apply':
- $this->firewall_rules_apply($id);
- break;
- case 'backup_take':
- $this->backup_take($id);
- break;
- case 'migrate':
- $this->migrate($id);
- break;
- case 'edit_admin_note':
- $this->edit_admin_note($id);
- break;
- case 'disk_backups_schedule_details':
- $this->show_template_disk_backups_schedule_details($id);
- break;
- case 'console':
- $this->console($id);
- break;
- default:
- $this->show_template_view();
- break;
- }
- }
- /**
- * Displays default page with virtual machine list
- *
- * @param string error message
- * @param other message
- * @return void
- */
- private function show_template_view($error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('error => ' . $error);
- $onapp = $this->get_factory();
- $hypervisor_id = onapp_get_arg('hypervisor_id');
- $hypervisor_label = onapp_get_arg('hypervisor_label');
- $user_id = onapp_get_arg('user_id');
- onapp_debug('hypervisor_id => ' . $hypervisor_id . ' hypervisor_label => ' . $hypervisor_label . ' user_id => ' . $user_id);
- onapp_permission(array('virtual_machines', 'virtual_machines.read.own', 'virtual_machines.read'));
- $virtual_machine = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $virtual_machines_array = $virtual_machine->getList();
- $virtual_machines = $virtual_machines_array;
- $vm_backup = $onapp->factory('VirtualMachine_Backup', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- /* foreach ($virtual_machines as $virtual_machine) {
- $vm_backup_obj = $vm_backup->getList($virtual_machine->_id);
- $size_and_quantity = $this->calculateBackups($vm_backup_obj);
- $vm_backups [] = $size_and_quantity;
- } */
- //TODO refactor when bug is fixed Ticket #2508
- if (!is_null($hypervisor_id)) {
- foreach ($virtual_machines as $virtual_machine)
- if ($virtual_machine->_hypervisor_id == $hypervisor_id)
- $hypervisor_vms[] = $virtual_machine;
- $virtual_machines = $hypervisor_vms;
- }
- if (!is_null($user_id)) {
- foreach ($virtual_machines as $virtual_machine)
- if ($virtual_machine->_user_id == $user_id)
- $user_vms[] = $virtual_machine;
- $virtual_machines = $user_vms;
- }
- $params = array(
- 'user_id' => $user_id,
- 'hypervisor_id' => $hypervisor_id,
- //'vm_backups' => $vm_backups,
- 'virtual_machines' => $virtual_machines,
- 'hypervisor_label' => $hypervisor_label,
- 'title' => onapp_string('VIRTUAL_MACHINES'),
- 'info_title' => onapp_string('VIRTUAL_MACHINES'),
- 'info_body' => onapp_string('VIRTUAL_MACHINE_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_view', $params);
- }
- /**
- * Displays particular virtual machine details page
- *
- * @param integer virtual Machine id
- * @param string error message
- * @param string other message
- * @return void
- */
- public function show_template_details($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- $vm_obj = $this->load('VirtualMachine', array($id));
- $vm_backup_obj = $this->getList('VirtualMachine_Backup', array($id));
- $size_and_quantity = $this->calculateBackups($vm_backup_obj);
- $params = array(
- 'virtual_machine_id' => $id,
- 'user_obj' => $this->load('User', array($vm_obj->_user_id)),
- 'backups_quantity' => $size_and_quantity['quantity'],
- 'backups_total_size' => $size_and_quantity['size'],
- 'profile_obj' => $_SESSION['profile_obj'],
- 'hypervisor_obj' => $this->load('Hypervisor', array($vm_obj->_hypervisor_id) ),
- 'vm_obj' => $vm_obj,
- 'title' => onapp_string('VIRTUAL_MACHINE_DETAILS'),
- 'info_title' => onapp_string('VIRTUAL_MACHINE_DETAILS'),
- 'info_body' => onapp_string('VIRTUAL_MACHINE_DETAILS_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_details', $params);
- }
- /**
- * Shows creating a new virtual machine page
- *
- * @param error message
- * @param other message
- * @return void
- */
- private function show_template_create($error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('error => ' . $error);
- $onapp = $this -> get_factory();
- onapp_permission(array('virtual_machines', 'virtual_machines.create'));
- $template = $onapp->factory('Template', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
-
- $params = array(
- 'network_zone_obj' => $this->getList('NetworkZone'),
- 'data_store_zone_obj' => $this->getList('DataStoreZone'),
- 'hypervisor_zones_obj' => $this->getList('HypervisorZone'),
- 'user_templates_obj' => $template->getUserTemplates(),
- 'templates_obj' => $this->getList('Template'),
- 'hypervisor_obj' => $this->getList('Hypervisor'),
- 'title' => onapp_string('CREATE_VIRTUAL_MACHINE'),
- 'info_title' => onapp_string('CREATE_VIRTUAL_MACHINE'),
- 'info_body' => onapp_string('CREATE_VIRTUAL_MACHINE_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_create', $params);
- }
- /**
- * Shows virtual machine cpu usage
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_cpu_usage($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- $onapp = $this -> get_factory();
- onapp_permission(array('virtual_machines', 'virtual_machines.power', 'virtual_machines.power.own'));
- $cpuusage = $onapp->factory('VirtualMachine_CpuUsage', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $cpuusage->_virtual_machine_id = $id; // print('<pre>');print_r($cpuusage); die();
- $list = $cpuusage->getList();
- $xaxis = '';
- $yaxis = '';
- $hourly_stat = array();
- foreach ($list as $key => $stat) {
- $hourly_stat[$key]['date'] = strtotime($stat->_created_at) * 1000;
- $hourly_stat[$key]['usage'] = number_format($stat->_cpu_time / 360 / 100, 2);
- }
- $content = '';
- foreach ($hourly_stat as $stat) {
- $content .= '[' . $stat[date] . ', ' . $stat[usage] . '],';
- }
-
- $data = "[{data: [ " . $content . "], name: 'CPU'";
- $data = str_replace('],]', ']]', $data);
-
- $params = array(
- 'virtual_machine_id' => $id,
- 'xaxis' => $xaxis,
- 'yaxis' => $yaxis,
- 'title' => onapp_string('CPU_USAGE'),
- 'info_title' => onapp_string('CPU_USAGE_FOR_THIS_VM'),
- 'info_body' => onapp_string('CPU_USAGE_FOR_THIS_VM_INFO'),
- 'data' => $data,
- );
- onapp_show_template('vm_cpuUsage', $params);
- }
- /**
- * Shows virtual machine backups
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_backup($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- onapp_permission(array('backups.read.own', 'backups.read', 'backups'));
- $params = array(
- 'virtual_machine_id' => $id,
- 'backup_obj' => $this->getList('VirtualMachine_Backup', array($id)),
- 'title' => onapp_string('BACKUPS_FOR_THIS_VM'),
- 'info_title' => onapp_string('BACKUPS_FOR_THIS_VM'),
- 'info_body' => onapp_string('BACKUPS_FOR_THIS_VM_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_backup', $params);
- }
- /**
- * Shows disk backups schedule details
- *
- * @param integer schedule id
- * @return void
- */
- private function show_template_disk_backups_schedule_details($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('schedules', 'schedules.read', 'schedules.read.own'));
- $schedule_obj = $this->load('Disk_Schedule', array($id));
- $user_obj = $this->load('User', array($schedule_obj->_user_id));
- $params = array(
- 'user_first_name' => $user_obj->_first_name,
- 'user_last_name' => $user_obj->_last_name,
- 'schedule_obj' => $schedule_obj,
- 'title' => onapp_string('SCHEDULE_DETAILS'),
- 'info_title' => onapp_string('SCHEDULE_DETAILS'),
- 'info_body' => onapp_string('SCHEDULE_DETAILS_INFO'),
- );
- onapp_show_template('vm_diskBackupsScheduleDetails', $params);
- }
- /**
- * Shows virtual machine firewall
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_firewall($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('firewall_rules.read.own', 'firewall_rules.read', 'firewall_rules'));
- $firewall_obj = $this->getList('VirtualMachine_FirewallRule', array( $id ));
- $network_interface_obj = $this->getList('VirtualMachine_NetworkInterface', array($id));
- foreach ($network_interface_obj as $network_interface)
- $network_interface_object[$network_interface->_id] = $network_interface;
- if ( ! is_null( $firewall_obj )) {
- foreach ($firewall_obj as $firewall)
- $firewall_by_network[$firewall->_network_interface_id][] = $firewall;
- }
- else
- $firewall_by_network = NULL;
-
- $params = array(
- 'firewall_by_network' => $firewall_by_network,
- 'commands' => array('ACCEPT', 'DROP'),
- 'virtual_machine_id' => $id,
- 'network_interface_obj' => $network_interface_object,
- 'firewall_obj' => $firewall_obj,
- 'title' => onapp_string('FIREWALL_RULES'),
- 'info_title' => onapp_string('FIREWALL_RULES'),
- 'info_body' => onapp_string('FIREWALL_RULES_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_firewall', $params);
- }
- /**
- * Shows virtual machine disk backups schedules
- *
- * @param integer virtual machine disk id
- * @return void
- */
- private function show_template_disk_backups_schedule($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- onapp_permission(array('schedules', 'schedules.read', 'schedules.read.own'));
- $onapp = $this->get_factory();
- $schedule = $onapp->factory('Disk_Schedule', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $schedule_obj = $schedule->getListByDiskId($id);
- $params = array(
- 'schedule_obj' => $schedule_obj,
- 'disk_id' => $id,
- 'title' => onapp_string('SCHEDULES_'),
- 'info_title' => onapp_string('SCHEDULES_'),
- 'info_body' => onapp_string('SCHEDULES_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_diskBackupsSchedule', $params);
- }
- /**
- * Shows disk backups list
- *
- * @param integer virtual machine disk id
- * @return void
- */
- private function show_template_disk_backup($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- $onapp = $this->get_factory();
- onapp_permission(array('backups.read.own', 'backups.read', 'backups'));
- $backup = $onapp->factory('VirtualMachine_Backup', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $backup_obj = $backup->diskBackups($id);
- $params = array(
- 'disk_id' => $id,
- 'virtual_machine_id' => onapp_get_arg('virtual_machine_id'),
- 'backup_obj' => $backup_obj,
- 'title' => onapp_string('BACKUPS_FOR_THIS_DISK'),
- 'info_title' => onapp_string('BACKUPS_FOR_THIS_DISK'),
- 'info_body' => onapp_string('BACKUPS_FOR_THIS_DISK_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_diskBackup', $params);
- }
- /**
- * Shows change virtual machine page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_change_owner($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.change_owner'));
- $params = array(
- 'vm_obj' => $this->load('VirtualMachine', array($id)),
- 'user_obj' => $this->getList('User'),
- 'title' => onapp_string('CHANGE_THIS_VIRTUAL_MACHINE_OWNER'),
- 'info_title' => onapp_string('CHANGE_THIS_VIRTUAL_MACHINE_OWNER'),
- 'info_body' => onapp_string('CHANGE_THIS_VIRTUAL_MACHINE_OWNER_INFO'),
- );
- onapp_show_template('vm_changeOwner', $params);
- }
- /**
- * Shows virtual machine disks list
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_disks($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- $onapp = $this->get_factory();
- onapp_permission(array('disks', 'disks.read', 'disks.read.own'));
- $disk_obj = $this->getList('Disk', array($id));
- $data_store_obj = $this->getList('DataStore');
- foreach ($data_store_obj as $data_store)
- $data_store_object[$data_store->_id] = $data_store;
- $vm_obj = $this->getList('VirtualMachine');
- foreach ($vm_obj as $vm)
- $vm_object[$vm->_id] = $vm;
- $backup = $onapp->factory('VirtualMachine_Backup', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- foreach ($disk_obj as $disk) {
- $backup_obj = $backup->diskBackups( $disk->_id );
-
- if ( ! is_null($backup_obj) )
- $backup_object[$disk->_id] = count($backup_obj);
- else
- $backup_object[$disk->_id] = 0;
- }
- $params = array(
- 'backup_quantity' => $backup_object,
- 'vm_obj' => $vm_object,
- 'data_store_obj' => $data_store_object,
- 'disk_obj' => $disk_obj,
- 'title' => onapp_string('DISK_SETTINGS'),
- 'info_title' => onapp_string('DISK_SETTINGS'),
- 'info_body' => onapp_string('DISK_SETTINGS_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_disk', $params);
- }
- /**
- * Shows virtual machine ip addresses list
- *
- * TODO doesn't work in XML ( Different structure of VirtualMachine_IpAddressJoin response! ) ticket #118
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_ip_addresses($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- onapp_permission(array('ip_address_joins', 'ip_address_joins.read', 'ip_address_joins.read.own'));
- $vm_obj = $this->load('VirtualMachine', array($id));
- foreach ($this->getList('VirtualMachine_NetworkInterface', array($id)) as $network_interface)
- $network_interface_array[$network_interface->_id] = $network_interface;
- foreach ($this->getList('Network') as $network)
- $network_array[$network->_id] = $network;
- $params = array(
- 'virtual_machine_id' => $id,
- 'hypervisor_label' => $this->load('Hypervisor', array($vm_obj->_hypervisor_id))->_label,
- 'network_obj' => $network_array,
- 'ip_address_obj' => $this->getList('VirtualMachine_IpAddressJoin', array($id)),
- 'network_interface_obj' => $network_interface_array,
- 'title' => onapp_string('IP_ADDRESSES_FOR_THIS_VIRTUAL_MACHINE'),
- 'info_title' => onapp_string('IP_ADDRESSES_FOR_THIS_VIRTUAL_MACHINE'),
- 'info_body' => onapp_string('IP_ADDRESSES_FOR_THIS_VIRTUAL_MACHINE_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_ipAddress', $params);
- }
- /**
- * Shows virtual machine backups
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_backup_convert($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('backups.convert.own', 'backups.convert', 'backups'));
- $params = array(
- 'id' => $id,
- 'title' => onapp_string('CONVERT_THIS_BACKUP_TO_TEMPLATE'),
- 'info_title' => onapp_string('CONVERT_THIS_BACKUP_TO_TEMPLATE'),
- 'info_body' => onapp_string('CONVERT_THIS_BACKUP_TO_TEMPLATE_INFO'),
- );
- onapp_show_template('vm_backupConvert', $params);
- }
- /**
- * Shows administrator's note edit page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_edit_admin_note($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- onapp_permission('virtual_machines', 'sysadmin_tools');
- $params = array(
- 'current_admin_note' => $this->load('VirtualMachine', array($id))->_admin_note,
- 'id' => $id,
- 'title' => onapp_string('EDIT_ADMIN_NOTE'),
- 'info_title' => onapp_string('EDIT_ADMIN_NOTE'),
- 'info_body' => onapp_string('EDIT_ADMIN_NOTE_INFO'),
- );
- onapp_show_template('vm_editAdminNote', $params);
- }
- /**
- * Shows virtual machine disk edit page
- *
- * @param integer virtual machine disk id
- * @return void
- */
- private function show_template_disk_edit($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('disks', 'disks.update', 'disks.update.own'));
- $params = array(
- 'disk_obj' => $this->load('Disk', array($id)),
- 'title' => onapp_string('EDIT_DISK'),
- 'info_title' => onapp_string('EDIT_DISK'),
- 'info_body' => onapp_string('EDIT_DISK_INFO'),
- );
- onapp_show_template('vm_diskEdit', $params);
- }
- /**
- * Shows virtual machine disk edit page
- *
- * @param integer virtual machine disk id
- * @return void
- */
- private function show_template_migrate($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.migrate.own', 'virtual_machines.migrate'));
- $vm_obj = $this->load('VirtualMachine', array($id));
- $params = array(
- 'virtual_machine_id' => $id,
- 'hypervisor_obj' => $this->load('Hypervisor', array($vm_obj->_hypervisor_id)),
- 'hypervisors_obj' => $this->getList('Hypervisor'),
- 'title' => onapp_string('MIGRATE_VIRTUAL_MACHINE'),
- 'info_title' => onapp_string('MIGRATE_VIRTUAL_MACHINE'),
- 'info_body' => onapp_string('MIGRATE_VIRTUAL_MACHINE_INFO'),
- );
- onapp_show_template('vm_migrate', $params);
- }
- /**
- * Shows disk backups schedule edit page
- *
- * @param integer disk backup schedule id
- * @return void
- */
- private function show_template_disk_backups_schedule_edit($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('schedules', 'schedules.update'));
- $periods = array(
- 'days' => 'Days',
- 'weeks' => 'Weeks',
- 'months' => 'Months',
- 'years' => 'Years'
- );
- $params = array(
- 'periods' => $periods,
- 'schedule_obj' => $this->load('Disk_Schedule', array($id)),
- 'title' => onapp_string('EDIT_SCHEDULE'),
- 'info_title' => onapp_string('EDIT_SCHEDULE'),
- 'info_body' => onapp_string('EDIT_SCHEDULE_INFO'),
- );
- onapp_show_template('vm_diskBackupsScheduleEdit', $params);
- }
- /**
- * Shows firewall rule edit page
- *
- * @param integer firewall id
- * @return void
- */
- private function show_template_firewall_rule_edit($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('firewall_rules', 'firewall_rules.update'));
- $virtual_machine_id = onapp_get_arg('virtual_machine_id');
- $params = array(
- 'virtual_machine_id' => $virtual_machine_id,
- 'network_interface_obj' => $this->getList('VirtualMachine_NetworkInterface', array($virtual_machine_id)),
- 'protocols' => array('TCP', 'UDP'),
- 'commands' => array('ACCEPT', 'DROP'),
- 'firewall_obj' => $this->load('VirtualMachine_FirewallRule', array($id, $virtual_machine_id)),
- 'title' => onapp_string('UPDATE_FIREWALL_RULE'),
- 'info_title' => onapp_string('UPDATE_FIREWALL_RULE'),
- 'info_body' => onapp_string('UPDATE_FIREWALL_RULE_INFO'),
- );
- onapp_show_template('vm_firewallRuleEdit', $params);
- }
- /**
- * Shows disk backups schedule create page
- *
- * @param integer disk backup schedule id
- * @return void
- */
- private function show_template_disk_backups_schedule_create($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('schedules', 'schedules.create'));
- $params = array(
- 'disk_id' => $id,
- 'title' => onapp_string('ADD_A_SCHEDULE_FOR_THIS_DISK'),
- 'info_title' => onapp_string('ADD_A_SCHEDULE_FOR_THIS_DISK'),
- 'info_body' => onapp_string('ADD_A_SCHEDULE_FOR_THIS_DISK_INFO'),
- );
- onapp_show_template('vm_diskBackupsScheduleCreate', $params);
- }
- /**
- * Shows virtual machine disk create page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_disk_create($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('disks', 'disks.create'));
- $params = array(
- 'data_store_obj' => $this->getList('DataStore'),
- 'virtual_machine_id' => $id,
- 'title' => onapp_string('ADD_NEW_DISK'),
- 'info_title' => onapp_string('ADD_NEW_DISK'),
- 'info_body' => onapp_string('ADD_NEW_DISK_INFO'),
- );
- onapp_show_template('vm_diskCreate', $params);
- }
- /**
- * Shows 'Allocate New IP Address from Global Pool' page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_ip_address_join_new($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('ip_address_joins', 'ip_address_joins.create', 'ip_address_joins.create.own'));
- $onapp = $this->get_factory();
- $vm_obj = $this->load('VirtualMachine', array($id));
- $hypervisor_obj = $this->load('Hypervisor', array($vm_obj->_hypervisor_id));
- $network_join_obj = $this->getList('Hypervisor_NetworkJoin', array($vm_obj->_hypervisor_id));
- $networkzone_join_obj = $this->getList('HypervisorZone_NetworkJoin', array($hypervisor_obj->_hypervisor_group_id));
- $network = $onapp->factory('Network', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- if (is_array($network_join_obj)) {
- foreach ($network_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- }
- }
- if (is_array($networkzone_join_obj)) {
- foreach ($networkzone_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- }
- }
- $network_interface = $onapp->factory('VirtualMachine_NetworkInterface', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $network_interface_obj = $network_interface->getList($id);
- foreach ($network_interface_obj as $network_interface_item) {
- $network_interface_object[$network_interface_item->_network_join_id] = $network_interface_item;
- }
- $ip_addresses = $onapp->factory('IpAddress', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- foreach ($network_obj_array as $interface_id => $network) {
- $ip_addresses_object = $ip_addresses->getList($network->_id);
- if ( ! is_null( $ip_addresses_object) ) {
- foreach ($ip_addresses_object as $object) {
- if ($object->_free == 1)
- $ip_addresses_array[$network_interface_object[$interface_id]->_id][$object->_id] = $object->_address . '/' . $object->_netmask . '/' . $object->_gateway;
- }
- }
-
- }
- $params = array(
- 'ip_addresses_array' => $ip_addresses_array,
- 'ip_addresses' => json_encode($ip_addresses_array),
- 'network_interface_obj' => $network_interface_obj,
- 'id' => $id,
- 'title' => onapp_string('ALLOCATE_NEW_IP_ADDRESS_ASSIGNMENT'),
- 'info_title' => onapp_string('ALLOCATE_NEW_IP_ADDRESS_ASSIGNMENT'),
- 'info_body' => onapp_string('ALLOCATE_NEW_IP_ADDRESS_ASSIGNMENT_INFO'),
- );
- onapp_show_template('vm_IpAddressJoinNew', $params);
- }
- /**
- * Shows network interface list for virtual machine
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_network_interface($id, $error = NULL) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id . ' error => ' . $error);
- onapp_permission(array('networks', 'virtual_machines.update.own', 'networks.read', 'virtual_machines'));
- $onapp = $this->get_factory();
- $vm_obj = $this->load('VirtualMachine', array($id) );
- $hypervisor_obj = $this->load('Hypervisor', array($vm_obj->_hypervisor_id) );
- $hypervisor_zone_obj = $this->load('HypervisorZone', array($hypervisor_obj->_hypervisor_group_id) );
- $ip_address_obj = $this->getList('VirtualMachine_IpAddressJoin', array($id));
- $network_interface_obj = $this->getList('VirtualMachine_NetworkInterface', array($id));
- if ( ! is_null( $network_interface_obj ) ) {
- foreach ($network_interface_obj as $network_interface)
- $network_interface_array[$network_interface->_network_join_id] = $network_interface;
- }
- else
- $network_interface_array = NULL;
- $hypervisor_network_join_obj = $this->getList('Hypervisor_NetworkJoin', array($vm_obj->_hypervisor_id));
- $hypervisor_zone_network_join_obj = $this->getList('HypervisorZone_NetworkJoin', array($hypervisor_obj->_hypervisor_group_id));
- $network = $onapp->factory('Network', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- if (is_array($hypervisor_network_join_obj)) {
- foreach ($hypervisor_network_join_obj as $network_join) {
- if ( $network_join->_networ_id ) {
- $network_obj = $network->load( $network_join->_network_id );
- }
- $hypervisor_network_interfaces[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_obj->_label;
- }
- }
- if (is_array($hypervisor_zone_network_join_obj)) {
- foreach ($hypervisor_zone_network_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $hypervisor_zone_network_interfaces[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_zone_obj->_label;
- }
- }
- $params = array(
- 'virtual_machine_id' => $vm_obj->_id,
- 'hypervisor_label' => $hypervisor_obj->_label,
- 'network_labels' => $network_labels,
- 'target_labels' => $target_labels,
- 'network_interface_obj' => $network_interface_obj,
- 'id' => $id,
- 'title' => onapp_string('NETWORK_INTERFACE_FOR_THIS_VIRTUAL_MACHINE'),
- 'info_title' => onapp_string('NETWORK_INTERFACE_FOR_THIS_VIRTUAL_MACHINE'),
- 'info_body' => onapp_string('NETWORK_INTERFACE_FOR_THIS_VIRTUAL_MACHINE_INFO'),
- 'error' => $error,
- );
- onapp_show_template('vm_networkInterface', $params);
- }
- /**
- * Shows 'Edit network interface' page
- *
- * @param integer network interface id
- * @return void
- */
- private function show_template_network_interface_edit($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('networks.update', 'networks'));
- $virtual_machine_id = onapp_get_arg('virtual_machine_id');
- $onapp = $this->get_factory();
- $network_interface_obj = $this->load('VirtualMachine_NetworkInterface', array($id, $virtual_machine_id));
- $vm_obj = $this->load('VirtualMachine', array($virtual_machine_id));
- $hypervisor_obj = $this->load('Hypervisor', array($vm_obj->_hypervisor_id));
- $hypervisor_zone_obj = $this->load('HypervisorZone', array($hypervisor_obj->_hypervisor_group_id));
- $network_join_obj = $this->getList('Hypervisor_NetworkJoin', array($vm_obj->_hypervisor_id));
- $networkzone_join_obj = $this->getList('HypervisorZone_NetworkJoin', array($hypervisor_obj->_hypervisor_group_id));
- $network = $onapp->factory('Network', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- if (is_array($network_join_obj)) {
- foreach ($network_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_obj->_label;
- }
- }
- if (is_array($networkzone_join_obj)) {
- foreach ($networkzone_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_zone_obj->_label;
- }
- }
- $params = array(
- 'target_labels' => $target_labels,
- 'hypervisor_label' => $hypervisor_obj->_label,
- 'network_interface_obj' => $network_interface_obj,
- 'network_obj' => $network_obj_array,
- 'id' => $id,
- 'title' => onapp_string('EDIT_NETWORK_INTERFACE'),
- 'info_title' => onapp_string('EDIT_NETWORK_INTERFACE'),
- 'info_body' => onapp_string('EDIT_NETWORK_INTERFACE_INFO'),
- );
- onapp_show_template('vm_networkInterfaceEdit', $params);
- }
- /**
- * Shows 'Create network interface' page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_network_interface_create($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- $onapp = $this->get_factory();
- $vm_obj = $this->load('VirtualMachine', array($id));
- $hypervisor_obj = $this->load('Hypervisor', array($vm_obj->_hypervisor_id));
- $hypervisor_zone_obj = $this->load('HypervisorZone', array($hypervisor_obj->_hypervisor_group_id));
- $network_join_obj = $this->getList('Hypervisor_NetworkJoin', array($vm_obj->_hypervisor_id));
- $networkzone_join_obj = $this->getList('HypervisorZone_NetworkJoin', array($hypervisor_obj->_hypervisor_group_id));
- $network = $onapp->factory('Network', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- if (is_array($network_join_obj)) {
- foreach ($network_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_obj->_label;
- }
- }
- if (is_array($networkzone_join_obj)) {
- foreach ($networkzone_join_obj as $network_join) {
- $network_obj = $network->load($network_join->_network_id);
- $network_obj_array[$network_join->_id] = $network_obj;
- $network_labels[$network_join->_id] = $network_obj;
- $target_labels[$network_join->_id] = $hypervisor_zone_obj->_label;
- }
- }
- $params = array(
- 'target_labels' => $target_labels,
- 'hypervisor_label' => $hypervisor_obj->_label,
- 'network_obj' => $network_obj_array,
- 'virtual_machine_id' => $id,
- 'title' => onapp_string('ADD_NEW_NETWORK_INTERFACE'),
- 'info_title' => onapp_string('ADD_NEW_NETWORK_INTERFACE'),
- 'info_body' => onapp_string('ADD_NEW_NETWORK_INTERFACE_INFO'),
- );
- onapp_show_template('vm_networkInterfaceCreate', $params);
- }
- /**
- * Shows virtual machine resource allocation page
- *
- * @param integer virtual machine id
- * @return void
- */
- private function show_template_edit($id) {
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.update.own', 'virtual_machines.update'));
- $params = array(
- 'vm_obj' => $this->load('VirtualMachine', array($id)),
- 'title' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS'),
- 'info_title' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS'),
- 'info_body' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS_INFO'),
- );
- onapp_show_template('vm_edit', $params);
- }
- /**
- * Creates a new virtual machine
- *
- * @global array $_ALIASES menu page aliases
- * @param object $onapp OnApp object
- * @return void
- */
- private function create() {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_permission(array('virtual_machines', 'virtual_machines.create'));
- $onapp = $this->get_factory();
- $virtual_machine = onapp_get_arg('virtual_machine');
- $vm_obj = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- foreach ($virtual_machine as $key => $value)
- if ($virtual_machine[$key] != '' && !is_null($virtual_machine[$key]))
- $vm_obj->$key = $value;
- $vm_obj->save();
- if (is_null($vm_obj->error)) {
- $_SESSION['message'] = 'VIRTUAL_MACHINE_HAS_BEEN_CREATED_SUCCESSFULLY';
- onapp_event_exec( 'vm_create', array( $vm_obj->_obj, $this->load( 'User', array($vm_obj->_obj->_user_id ) ) ) );
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $vm_obj->_id);
- }
- else {
- onapp_event_exec( 'vm_create_failed', array( $vm_obj->_obj, $this->load( 'User', array($vm_obj->_obj->_user_id ) ) ) );
- trigger_error ( print_r( $vm_obj->error, true ) );
- $this->show_template_view($vm_obj->error);
- }
- }
- /**
- * Startups virtual machine
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine Id
- * @return void
- */
- private function startup($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.power.own', 'virtual_machines.power'));
- $onapp = $this->get_factory();
- $virtual_machine = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $mode = onapp_get_arg('mode');
- switch ($mode) {
- case 'recovery':
- $virtual_machine->_id = $id;
- $virtual_machine->startup(true);
- break;
- default:
- $virtual_machine->_id = $id;
- $virtual_machine->startup();
- break;
- }
- if (is_null($virtual_machine->error)) {
- onapp_event_exec( 'vm_startup', array( $virtual_machine->_obj, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- $_SESSION['message'] = 'VIRTUAL_MACHINE_STARTUP_HAS_BEEN_QUEUED';
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $id);
- }
- else {
- onapp_event_exec( 'vm_startup_failed', array( $virtual_machine, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- trigger_error ( print_r( $virtual_machine->error, true ) );
- $this->show_template_view($virtual_machine->error);
- }
- }
- /**
- * Resets Virtual Machine Root Password
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine id
- * @return void
- */
- private function reset_password($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array(
- 'virtual_machines',
- 'virtual_machines.reset_root_password',
- 'virtual_machines.reset_root_password.own'
- ));
- $onapp = $this->get_factory();
- $virtual_machine = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $virtual_machine->_id = $id;
- $virtual_machine->reset_password();
- if (is_null($virtual_machine->error)) {
- onapp_event_exec( 'vm_reset_password', array( $virtual_machine->_obj, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- $_SESSION['message'] = 'VIRTUAL_MACHINE_PASSWORD_WIL_BE_CHANGED_SHORTLY';
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $id);
- }
- else {
- onapp_event_exec( 'vm_reset_password_failed', array( $virtual_machine, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- trigger_error ( print_r( $virtual_machine->error, true ) );
- $this->show_template_view($virtual_machine->error);
- }
- }
- /**
- * Reboots Virtual Machine
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine id
- * @return void
- */
- private function reboot($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.power.own', 'virtual_machines.power'));
- $onapp = $this->get_factory();
- $virtual_machine = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $mode = onapp_get_arg('mode');
- switch ($mode) {
- case 'recovery':
- $virtual_machine->_id = $id;
- $virtual_machine->reboot(true);
- break;
- default:
- $virtual_machine->_id = $id;
- $virtual_machine->reboot();
- break;
- }
- if (is_null($virtual_machine->error)) {
- onapp_event_exec( 'vm_reboot', array( $virtual_machine->_obj, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- $_SESSION['message'] = 'VIRTUAL_MACHINE_WILL_BE_REBOOTED_SHORTLY';
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $id);
- }
- else {
- onapp_event_exec( 'vm_reboot_failed', array( $virtual_machine->_obj, $this->load( 'User', array( $virtual_machine->_obj->_user_id ) ) ) );
- trigger_error ( print_r( $virtual_machine->error, true ) );
- $this->show_template_view($virtual_machine->error);
- }
- }
- /**
- * Deletes Virtual Machine
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine id
- * @return void
- */
- private function delete($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('virtual_machines', 'virtual_machines.delete', 'virtual_machines.delete.own'));
- $onapp = $this->get_factory();
- $virtual_machine = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $virtual_machine->_id = $id;
- $virtual_machine->delete();
- if (is_null($virtual_machine->error)) {
- onapp_event_exec( 'vm_delete' );
- $_SESSION['message'] = 'VIRTUAL_MACHINE_HAVE_BEEN_SQUEDULED_FOR_DESTRUCTION';
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $id);
- }
- else {
- onapp_event_exec( 'vm_delete_failed' );
- trigger_error ( print_r( $virtual_machine->error, true ) );
- $this->show_template_view($virtual_machine->error);
- }
- }
- /**
- * Disables virtual machine disk autobackups
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine disk id
- * @return void
- */
- private function autobackup_disable($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('disks', 'disks.autobackup', 'disks.autobackup.own'));
- $onapp = $this->get_factory();
- $disk = $onapp->factory('Disk', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $disk->disableAutobackup($id);
- if (is_null($disk->error)) {
- onapp_event_exec( 'disk_autobackup_disable', array( $disk->_obj ) );
- $_SESSION['message'] = 'AUTOBACKUP_HAS_BEEN_DISABLED_FOR_THIS_DISK';
- onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=disks&id=' . onapp_get_arg('virtual_machine_id'));
- }
- else {
- onapp_event_exec( 'disk_autobackup_disable_failed', array( $disk->_obj ) );
- trigger_error ( print_r( $disk->error, true ) );
- $this->show_template_disks(onapp_get_arg('virtual_machine_id'), $disk->error);
- }
- }
- /**
- * Enables virtual machine disk autobackups
- *
- * @global array $_ALIASES menu page aliases
- * @param integer virtual machine disk id
- * @return void
- */
- private function autobackup_enable($id) {
- global $_ALIASES;
- onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
- onapp_debug('id => ' . $id);
- onapp_permission(array('disks', 'disks.autobackup', 'disks.autobackup.own'));
- $onapp = $this->get_factory();
- $disk = $onapp->factory('Disk', ONAPP_WRAPPER_LOG_REPORT_ENABLE);
- $disk->enableAutobackup($id);
- if (is_null($disk->error)) {
- onapp_event_exec( 'disk_autobackup_enable', array( $disk->_obj ) );
- $_SESSION['message'] = 'AUTOBACKUP_HAS_BEEN_ENABLED_FOR_THIS_DISK';
- …
Large files files are truncated, but you can click here to view the full file