Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/7.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangrynenko committed Dec 13, 2015
2 parents 5d8f281 + 22b8a8b commit 30323fd
Show file tree
Hide file tree
Showing 18 changed files with 1,034 additions and 411 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG #

xs 7.x-1.4, 2015-12-13
----------------------
[] ig: Added xs_action_log entity.
[] ig: Added view for user to access server actions log.
[] ig: Added view for user to access snapshot actions log.
[] ig: Added view for admin to access server all actions log.
[] ig: Added view for admin to access snapshot all actions log.
[] ig: Updated policy log to assert node access permissions.

xs 7.x-1.3, 2015-12-12
----------------------
[] ig: Replaced policy events log with a view.
Expand Down
16 changes: 16 additions & 0 deletions includes/xs.actions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function xs_actions_server_action_confirmation_form_submit($form, &$form_state)
* @return string
*/
function xs_actions_action($node, $action) {
global $user;

$vm = xs_get_vm_by_node($node);

if (!in_array($action, $vm['allowed_operations'])) {
Expand All @@ -145,34 +147,48 @@ function xs_actions_action($node, $action) {
xs_actions_action_vps_start($vm_ref);
drupal_set_message('The server has been started. Allow 1-2 minutes before attempting to connect.');
drupal_set_message('You may need to refresh this page in order to reflect server\'s power state or IP addresses.');
$log_message = t('Server started manually by !user', array('!user' => $user->name));
$log_type = XS_API_ACTION_START;
break;

case XS_API_ACTION_POWEROFF:
xs_actions_action_vps_shutdown($vm_ref);
drupal_set_message('The server is being shut down. Allow 1-2 minutes before it has shut down.');
drupal_set_message('You may need to refresh this page in order to reflect server\'s power state');
$log_message = t('Server stopped manually by !user', array('!user' => $user->name));
$log_type = XS_API_ACTION_POWEROFF;
break;

case XS_API_ACTION_REBOOT:
xs_actions_action_vps_clean_reboot($vm_ref);
drupal_set_message('The server is being rebooted. Allow 1-2 minutes for the operation to complete.');
$log_message = t('Server rebooted manually by !user', array('!user' => $user->name));
$log_type = XS_API_ACTION_REBOOT;
break;

case XS_API_ACTION_REBOOT_FORCE:
xs_actions_action_vps_hard_reboot($vm_ref);
drupal_set_message('The server has been forcefully rebooted. Allow 1-2 minutes for the operation to complete.');
$log_message = t('Server force-rebooted manually by !user', array('!user' => $user->name));
$log_type = XS_API_ACTION_REBOOT_FORCE;
break;

case XS_API_ACTION_POWEROFF_FORCE:
xs_actions_action_vps_hard_shutdown($vm_ref);
drupal_set_message('The server has been forcefully shut down. Allow 1-2 minutes for the operation to complete.');
$log_message = t('Server force-shutdown manually by !user', array('!user' => $user->name));
$log_type = XS_API_ACTION_POWEROFF_FORCE;
break;

default:
drupal_set_message('This action is not recognised', 'error');
$log_message = t('Unrecognised server action by !user', array('!user' => $user->name));
$log_type = 'error';
break;
}

xs_action_log_write($log_message, $log_type);

drupal_goto('node/' . $node->nid);
}

Expand Down
14 changes: 0 additions & 14 deletions includes/xs.pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,6 @@ function xs_settings_form_submit($form, &$form_state) {
variable_set('xs_pool_is', $form_state['values']['xs_pool_is']);
}

/**
* Renders a block of pool servers.
*
* @return string
* Rendered HTML output.
*/
function xs_admin_pool_vms() {
drupal_set_title('Available Virtual Servers');
$view = views_get_view('xs_pools_servers');
$output = $view->preview('block');

return $output;
}

/**
* Create a list of templates for administrator.
*
Expand Down
62 changes: 43 additions & 19 deletions includes/xs.snapshots.inc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ function xs_snapshots_create_snapshot_form($form, &$form_state, $node) {
'#description' => t('Give a description meaningful to you. We record the exact date and time of snapshot creation for you. Limited to 64 characters. Click Cancel to close this modal window or Create to continue with snapshot creation.'),
);

$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node,
);

$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
Expand Down Expand Up @@ -247,12 +252,11 @@ function xs_snapshots_create_snapshot_form($form, &$form_state, $node) {
* Validate handler for xs_snapshots_create_snapshot_form.
*/
function xs_snapshots_create_snapshot_form_validate($form, &$form_state) {
$nid = is_numeric(arg(1)) ? arg(1) : FALSE;
if (!$nid) {
if (empty($form_state['values']['nid'])) {
return form_set_error(NULL, 'Validation error. This form must be submitted in server context');
}

$node = node_load($nid);
$node = node_load($form_state['values']['nid']);
$form_state['storage']['xs_snapshot_create']['node'] = $node;
// Check if the user can add more snapshots.
$limit = xs_get_snapshots_limit($node);
Expand All @@ -276,6 +280,11 @@ function xs_snapshots_create_snapshot_form_submit($form, &$form_state) {
throw new Exception('Unable to create snapshot: ' . $e->getMessage());
}

xs_action_log_write(t('Created snapshot !name for !server', array(
'!name' => $form_state['values']['title'],
'!server' => $form_state['storage']['xs_snapshot_create']['node']->title,
)), 'snapshot-create');

$form_state['redirect'] = 'node/' . $form_state['storage']['xs_snapshot_create']['node']->nid . '/xs-snapshots';
}

Expand Down Expand Up @@ -360,42 +369,57 @@ function xs_actions_confirm_snapshots_form_validate($form, &$form_state) {
if (empty($form_state['values']['snapshot_uuid']) || empty($form_state['values']['action'])) {
return form_set_error(NULL, 'Unable to complete the action. Validation error');
}

// Do not allow form submission outside of node context.
if (!(is_numeric(arg(1)) && arg(0) == 'node')) {
return form_set_error(NULL, 'Validation error. Unable to submit your form outside of your server page');
}
}

/**
* Submit handler for xs_actions_confirm_snapshots_form.
*/
function xs_actions_confirm_snapshots_form_submit($form, &$form_state) {
$snapshot = xs_api_get_vm_by_uuid($form_state['values']['snapshot_uuid']);
$node = node_load($form_state['values']['nid']);

switch ($form_state['values']['action']) {
case 'destroy':
$snapshot_ref = xs_api_get_vm_ref_by_uuid($form_state['values']['snapshot_uuid']);
xs_actions_snapshot_destroy($snapshot_ref);
xs_action_log_write(t('Deleted snapshot !name for !server', array(
'!name' => $snapshot['name_label'],
'!server' => $node->title,
)), 'snapshot-destroy');
drupal_set_message('The selected snapshot was deleted successfully');
drupal_goto('node/' . $form_state['values']['nid'] . '/xs-snapshots');
break;

case 'revert':
if (is_numeric(arg(1)) && arg(0) == 'node') {
$node = node_load(arg(1));
if (xs_actions_access_callback($node)) {
module_load_include('inc', 'xs', 'includes/xs.actions');

// Load the VM.
$uuid = xs_get_vm_uuid_by_node($node);
$vm_ref = xs_api_get_vm_ref_by_uuid($uuid);
if (xs_actions_access_callback($node)) {
module_load_include('inc', 'xs', 'includes/xs.actions');

// Load the VM.
$uuid = xs_get_vm_uuid_by_node($node);
$vm_ref = xs_api_get_vm_ref_by_uuid($uuid);

// Shut down the VM.
xs_actions_action_vps_hard_shutdown($vm_ref);

// Shut down the VM.
xs_actions_action_vps_hard_shutdown($vm_ref);
// Revert to the selected snapshot.
$snapshot_ref = xs_api_get_vm_ref_by_uuid($form_state['values']['snapshot_uuid']);
xs_actions_snapshot_revert($snapshot_ref);

// Revert to the selected snapshot.
$snapshot_ref = xs_api_get_vm_ref_by_uuid($form_state['values']['snapshot_uuid']);
xs_actions_snapshot_revert($snapshot_ref);
// Start the VM.
xs_actions_action_vps_start($vm_ref);

// Start the VM.
xs_actions_action_vps_start($vm_ref);
xs_action_log_write(t('Reverted server !server to snapshot !name', array(
'!name' => $snapshot['name_label'],
'!server' => $node->title,
)), 'snapshot-revert');

drupal_set_message('Your Server has been reverted to the selected snapshot and started successfully');
}
drupal_set_message('Your Server has been reverted to the selected snapshot and started successfully');
}
drupal_goto('node/' . $form_state['values']['nid'] . '/xs-snapshots');
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function xs_snapshot_policy_output_preprocess(&$variables) {

}

$variables['policy_log_table'] = views_embed_view('xs_policy_log_runs_per_user', 'page_2', $variables['node']->nid);
$variables['policy_log_table'] = views_embed_view('xs_policy_log', 'page_2', $variables['node']->nid);
$spid = !empty($policy->spid) ? $policy->spid : NULL;
$policy_form = drupal_get_form('xs_snapshot_policy_form', $variables['node']->nid, $spid);
$variables['policy_form'] = drupal_render($policy_form);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SnapshotPolicyLog extends Entity {
public $id;
public $policy_id;
public $log;
public $type;
public $created;

public function __construct($values = array()) {
Expand Down
2 changes: 1 addition & 1 deletion modules/xs_snapshot_policy/xs_snapshot_policy.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function xs_snapshot_policy_views_data_alter(&$data) {
* Implements hook_views_query_alter().
*/
function xs_snapshot_policy_views_query_alter(&$view, &$query) {
if ($view->name == 'xs_policy_log_runs_per_user' && arg(0) == 'node' && arg(2) == 'xs-snapshot-policy' && arg(3) != 'policies-log') {
if ($view->name == 'xs_policy_log' && arg(0) == 'node' && arg(2) == 'xs-snapshot-policy' && arg(3) != 'policies-log') {
// Remove views header when in policy view.
$view->header = array();
}
Expand Down
Loading

0 comments on commit 30323fd

Please sign in to comment.