Skip to content
Snippets Groups Projects
Commit 92c844af authored by Yas Naoi's avatar Yas Naoi
Browse files

Refactored.

parent f8e99942
No related branches found
No related tags found
No related merge requests found
...@@ -5,4 +5,3 @@ package = Cloud ...@@ -5,4 +5,3 @@ package = Cloud
; UI Scripts ; UI Scripts
scripts[] = js/cloud.js scripts[] = js/cloud.js
...@@ -5,4 +5,3 @@ dependencies[] = cloud ...@@ -5,4 +5,3 @@ dependencies[] = cloud
dependencies[] = cloud_server_templates dependencies[] = cloud_server_templates
dependencies[] = cloud_pricing dependencies[] = cloud_pricing
dependencies[] = aws_ec2_lib dependencies[] = aws_ec2_lib
...@@ -12,10 +12,13 @@ ...@@ -12,10 +12,13 @@
* Listing page for all the clouds in the system * Listing page for all the clouds in the system
*/ */
function aws_cloud_list() { function aws_cloud_list() {
drupal_add_js(cloud_get_module_base() . 'js/cloud.js', 'module'); drupal_add_js(cloud_get_module_base() . 'js/cloud.js', 'module');
$output = '';
$output = '';
$output .= drupal_get_form('aws_cloud_add_button'); $output .= drupal_get_form('aws_cloud_add_button');
$output .= theme('aws_cloud_list'); $output .= theme('aws_cloud_list');
return $output; return $output;
} }
...@@ -29,6 +32,7 @@ function aws_cloud_add_button() { ...@@ -29,6 +32,7 @@ function aws_cloud_add_button() {
'#value' => t('Add Cloud'), '#value' => t('Add Cloud'),
'#submit' => array('aws_cloud_add_cloud'), '#submit' => array('aws_cloud_add_cloud'),
); );
return $form; return $form;
} }
...@@ -38,11 +42,15 @@ function aws_cloud_add_button() { ...@@ -38,11 +42,15 @@ function aws_cloud_add_button() {
* to the Add Cloud Form. * to the Add Cloud Form.
*/ */
function _aws_cloud_base_cloud_options() { function _aws_cloud_base_cloud_options() {
$data = aws_cloud_get_cloud_data(); $data = aws_cloud_get_cloud_data();
$return = array(); $return = array();
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$return[$key] = $value['name']; $return[$key] = $value['name'];
} }
return $return; return $return;
} }
...@@ -50,27 +58,33 @@ function _aws_cloud_base_cloud_options() { ...@@ -50,27 +58,33 @@ function _aws_cloud_base_cloud_options() {
* Function renders the cloud add/edit form * Function renders the cloud add/edit form
*/ */
function aws_cloud_edit($cloud_name = NULL) { function aws_cloud_edit($cloud_name = NULL) {
$output = ''; $output = '';
if ($cloud_name) { if ($cloud_name) {
$cloud_data = aws_cloud_get_cloud($cloud_name); $cloud_data = aws_cloud_get_cloud($cloud_name);
$output = drupal_get_form('aws_cloud_add_form', $cloud_data, 'edit'); $output = drupal_get_form('aws_cloud_add_form', $cloud_data, 'edit');
} }
else { else {
$edit = array( $edit = array(
'base_cloud' => '', 'base_cloud' => '',
'cloud_name' => '', 'cloud_name' => '',
'cloud_display_name' => '', 'cloud_display_name' => '',
'api_version' => '', 'api_version' => '',
'host_uri' => '', 'host_uri' => '',
'aws_access_key' => '', 'aws_access_key' => '',
'aws_secret_key' => '', 'aws_secret_key' => '',
'user_id' => '', 'user_id' => '',
'image_upload_url' => '', 'image_upload_url' => '',
'image_register_url' => '', 'image_register_url' => '',
'certificate' => '', 'certificate' => '',
); );
$output = drupal_get_form('aws_cloud_add_form', $edit); $output = drupal_get_form('aws_cloud_add_form', $edit);
} }
return $output; return $output;
} }
...@@ -78,10 +92,12 @@ function aws_cloud_edit($cloud_name = NULL) { ...@@ -78,10 +92,12 @@ function aws_cloud_edit($cloud_name = NULL) {
* Cloud form * Cloud form
*/ */
function aws_cloud_add_form($form_state, $edit = array(), $op = '') { function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
$form['cloud'] = array( $form['cloud'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#description' => 'Use this form to add a new cloud here', '#description' => 'Use this form to add a new cloud here',
); );
$form['cloud']['destination'] = array( $form['cloud']['destination'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#name' => 'destination', '#name' => 'destination',
...@@ -107,6 +123,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -107,6 +123,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
} }
if ($op == 'edit') { if ($op == 'edit') {
$form['cloud']['base_cloud_display'] = array( $form['cloud']['base_cloud_display'] = array(
'#type' => 'item', '#type' => 'item',
'#title' => t('Base Cloud'), '#title' => t('Base Cloud'),
...@@ -144,7 +161,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -144,7 +161,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
$form['cloud']['base_cloud'] = array( $form['cloud']['base_cloud'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Base Cloud'), '#title' => t('Base Cloud'),
'#description' => t('Select the cloud type'), '#description' => t('Select the cloud type for pre-defined billing model for hourly rate'),
'#required' => TRUE, '#required' => TRUE,
'#options' => _aws_cloud_base_cloud_options(), '#options' => _aws_cloud_base_cloud_options(),
'#default_value' => $edit['base_cloud'], '#default_value' => $edit['base_cloud'],
...@@ -153,16 +170,17 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -153,16 +170,17 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
$form['cloud']['cloud_name'] = array( $form['cloud']['cloud_name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Cloud Name'), '#title' => t('Cloud Name'),
'#description' => t('Machine name: e.g. amazon_ec2_east'), '#description' => t('Cloud name as an identifier: e.g. amazon_ec2_east - The Cloud Name must contain only lowercase letters, numbers, and underscores. Space cannot be included.'),
'#required' => TRUE, '#required' => TRUE,
'#default_value' => $edit['cloud_name'], '#default_value' => $edit['cloud_name'],
); );
} }
$form['cloud']['cloud_display_name'] = array( $form['cloud']['cloud_display_name'] = array(
'#title' => t('Cloud Display Name'), '#title' => t('Cloud Display Name'),
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Cloud Display Name'), '#title' => t('Cloud Display Name'),
'#description' => t('e.g. Amazon EC2 East'), '#description' => t('e.g. AWS US East (or AWS Virgina), AWS US West (or AWS California), AWS EU West (or AWS Ireland), AWS AP Southeast (or AWS Singapore), AWS AP Northeast (or AWS Tokyo), OpenStack, Eucalyptus'),
'#required' => TRUE, '#required' => TRUE,
'#default_value' => $edit['cloud_display_name'], '#default_value' => $edit['cloud_display_name'],
); );
...@@ -179,7 +197,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -179,7 +197,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
$form['cloud']['host_uri'] = array( $form['cloud']['host_uri'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('API URI'), '#title' => t('API URI'),
'#description' => t("'http://' is NOT required: e.g. ec2.amazonaws.com / ec2.us-west-1.amazonaws.com / ec2.eu-west-1.amazonaws.com / ec2.ap-southeast-1.amazonaws.com / ec2.ap-northeast-1.amazonaws.com"), '#description' => t("'http://' is NOT required: e.g. ec2.amazonaws.com / ec2.us-west-1.amazonaws.com / ec2.eu-west-1.amazonaws.com / ec2.ap-southeast-1.amazonaws.com / ec2.ap-northeast-1.amazonaws.com / 192.168.0.1:8773/services/Cloud"),
'#size' => 50, '#size' => 50,
'#maxlength' => 255, '#maxlength' => 255,
'#required' => TRUE, '#required' => TRUE,
...@@ -239,7 +257,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -239,7 +257,7 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
$form['cloud']['certificate'] = array( $form['cloud']['certificate'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('X.509 Certificate'), '#title' => t('X.509 Certificate'),
'#description' => t('X.509 Certificate to use'), '#description' => t('X.509 Certificate to use. You can temporarily put dummy string if you do not use Bundle Image capability.'),
'#rows' => 17, '#rows' => 17,
'#size' => 66, '#size' => 66,
'#required' => TRUE, '#required' => TRUE,
...@@ -266,18 +284,23 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') { ...@@ -266,18 +284,23 @@ function aws_cloud_add_form($form_state, $edit = array(), $op = '') {
* Make sure the cloud_name is unique * Make sure the cloud_name is unique
*/ */
function aws_cloud_add_form_validate($form, &$form_state) { function aws_cloud_add_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == 'Create') { if ($form_state['values']['op'] == 'Create') {
$cloud_name = $form_state['values']['cloud_name']; $cloud_name = $form_state['values']['cloud_name'];
if (!preg_match('!^[a-z0-9_]+$!', $cloud_name)) { if (!preg_match('!^[a-z0-9_]+$!', $cloud_name)) {
form_set_error('cloud_name', t('The Cloud Name must contain only lowercase letters, numbers, and underscores.')); form_set_error('cloud_name', t('The Cloud Name must contain only lowercase letters, numbers, and underscores.'));
} }
$db_check = cloud_check_cloud_name($cloud_name); $db_check = cloud_check_cloud_name($cloud_name);
if (count($db_check)) { if (count($db_check)) {
form_set_error('cloud_name', t('The Cloud Name chosen is not unique')); form_set_error('cloud_name', t('The Cloud Name chosen is not unique'));
} }
//check to make sure //check to make sure
$uri_check = aws_cloud_check_host_uri($form_state['values']['host_uri'], $form_state['values']['user_id']); $uri_check = aws_cloud_check_host_uri($form_state['values']['host_uri'], $form_state['values']['user_id']);
if ($uri_check != FALSE) { if ($uri_check != FALSE) {
form_set_error('host_uri', t('The API URI and User ID combination is in use already.')); form_set_error('host_uri', t('The API URI and User ID combination is in use already.'));
} }
} }
...@@ -295,6 +318,7 @@ function aws_cloud_add_form_submit($form, &$form_state) { ...@@ -295,6 +318,7 @@ function aws_cloud_add_form_submit($form, &$form_state) {
//set the extra data only on create //set the extra data only on create
if ($op == 'Create') { if ($op == 'Create') {
//get all the extra data from the base cloud //get all the extra data from the base cloud
$extra_data = aws_cloud_get_cloud_data($form_state['values']['base_cloud']); $extra_data = aws_cloud_get_cloud_data($form_state['values']['base_cloud']);
$data = array(); $data = array();
...@@ -346,7 +370,9 @@ function aws_cloud_add_cloud($form, &$form_state) { ...@@ -346,7 +370,9 @@ function aws_cloud_add_cloud($form, &$form_state) {
* Confirm the deletion of the cloud * Confirm the deletion of the cloud
*/ */
function aws_cloud_delete_submit($form, &$form_state) { function aws_cloud_delete_submit($form, &$form_state) {
$destination = ''; $destination = '';
if (isset($_REQUEST['destination'])) { if (isset($_REQUEST['destination'])) {
$destination = drupal_get_destination(); $destination = drupal_get_destination();
unset($_REQUEST['destination']); unset($_REQUEST['destination']);
...@@ -358,10 +384,12 @@ function aws_cloud_delete_submit($form, &$form_state) { ...@@ -358,10 +384,12 @@ function aws_cloud_delete_submit($form, &$form_state) {
* Confirm delete form * Confirm delete form
*/ */
function aws_cloud_confirm_delete(&$form_state, $cloud_name) { function aws_cloud_confirm_delete(&$form_state, $cloud_name) {
$form['cloud_name'] = array( $form['cloud_name'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $cloud_name, '#value' => $cloud_name,
); );
return confirm_form($form, t('Are you sure you want to delete the cloud %cloud?', array('%cloud' => $cloud_name)), return confirm_form($form, t('Are you sure you want to delete the cloud %cloud?', array('%cloud' => $cloud_name)),
'admin/settings/clouds/' . $cloud_name, 'admin/settings/clouds/' . $cloud_name,
t('All related cloud information will be deleted. This action cannot be undone.'), t('All related cloud information will be deleted. This action cannot be undone.'),
...@@ -372,6 +400,7 @@ function aws_cloud_confirm_delete(&$form_state, $cloud_name) { ...@@ -372,6 +400,7 @@ function aws_cloud_confirm_delete(&$form_state, $cloud_name) {
* Delete the cloud and its data * Delete the cloud and its data
*/ */
function aws_cloud_confirm_delete_submit($form, &$form_state) { function aws_cloud_confirm_delete_submit($form, &$form_state) {
cloud_delete($form_state['values']['cloud_name']); cloud_delete($form_state['values']['cloud_name']);
drupal_set_message(t('%cloud has been deleted.', array('%cloud' => $form_state['values']['cloud_name']))); drupal_set_message(t('%cloud has been deleted.', array('%cloud' => $form_state['values']['cloud_name'])));
$form_state['redirect'] = AWS_CLOUD_LIST_PAGE; $form_state['redirect'] = AWS_CLOUD_LIST_PAGE;
...@@ -393,7 +422,9 @@ function theme_aws_cloud_list() { ...@@ -393,7 +422,9 @@ function theme_aws_cloud_list() {
$sort_string = tablesort_sql($header); $sort_string = tablesort_sql($header);
$clouds = aws_cloud_get_all_clouds($sort_string); $clouds = aws_cloud_get_all_clouds($sort_string);
$rows = array(); $rows = array();
foreach ($clouds as $cloud) { foreach ($clouds as $cloud) {
$action_data = cloud_display_action('images/edit', t('Edit'), 'admin/settings/clouds/' . $cloud['cloud_name'] . '/edit', array()); $action_data = cloud_display_action('images/edit', t('Edit'), 'admin/settings/clouds/' . $cloud['cloud_name'] . '/edit', array());
$action_data .= cloud_display_action('images/icon_delete', t('Delete'), 'admin/settings/clouds/' . $cloud['cloud_name'] . '/delete', array()); $action_data .= cloud_display_action('images/icon_delete', t('Delete'), 'admin/settings/clouds/' . $cloud['cloud_name'] . '/delete', array());
$row = array( $row = array(
...@@ -402,7 +433,8 @@ function theme_aws_cloud_list() { ...@@ -402,7 +433,8 @@ function theme_aws_cloud_list() {
$cloud['host_uri'], $cloud['host_uri'],
$cloud['user_id'], $cloud['user_id'],
); );
$row[] = array('data' => $action_data, 'class' => 'action-column');
$row[] = array('data' => $action_data, 'class' => 'action-column');
$rows[] = $row; $rows[] = $row;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment