function __construct($openqrm, $response) { $this->response = $response; $this->file = $openqrm->file(); $this->openqrm = $openqrm; $this->user = $openqrm->user(); $this->id = $this->response->html->request()->get('hybrid_cloud_id'); $this->response->add('hybrid_cloud_id', $this->id); $this->region = $response->html->request()->get('region'); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $this->hc = $hc; }
function __construct($openqrm, $response) { $this->response = $response; $this->file = $openqrm->file(); $this->openqrm = $openqrm; $this->user = $openqrm->user(); $this->id = $this->response->html->request()->get('hybrid_cloud_id'); $this->response->add('hybrid_cloud_id', $this->id); $this->filter = $this->response->html->request()->get('hybrid_cloud_ami_filter'); if (!strlen($this->filter)) { $this->filter = "a"; } $this->response->add('hybrid_cloud_ami_filter', $this->filter); $this->region = $response->html->request()->get('region'); $this->ami_type = $response->html->request()->get('ami_type'); if (!strlen($this->ami_type)) { $this->ami_type = 'public'; } $this->response->add('ami_type', $this->ami_type); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $this->hc = $hc; $deployment = $this->openqrm->deployment(); $deployment->get_instance_by_type('ami-deployment'); $this->deployment = $deployment; }
function __construct($openqrm, $response) { $this->response = $response; $this->file = $openqrm->file(); $this->openqrm = $openqrm; $this->id = $this->response->html->request()->get('hybrid_cloud_id'); $this->response->add('hybrid_cloud_id', $this->id); $this->region = $response->html->request()->get('region'); # bucket $this->bucket_name = $this->response->html->request()->get('bucket_name'); $this->response->add('bucket_name', $this->bucket_name); # hybrid-cloud account $this->id = $this->response->html->request()->get('hybrid_cloud_id'); $this->response->add('hybrid_cloud_id', $this->id); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); # s3 object require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/S3.php'; $s3 = new S3($hc->access_key, $hc->secret_key); $this->s3 = $s3; }
function get_hybrid_cloud_appliance_link($appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $p_appliance = new appliance(); $p_appliance->get_instance_by_id($appliance_id); $p_resource = new resource(); $p_resource->get_instance_by_id($p_appliance->resources); $virtualization = new virtualization(); $virtualization->get_instance_by_id($p_appliance->virtualization); if ($virtualization->type != "hybrid-cloud-vm-local") { return; } // get hybrid-cloud account $hybrid_cloud_acl_id = $p_resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("get_hybrid_cloud_appliance_link", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-link-hook.php", "Could not find Hybrid-Cloud Account for resource " . $p_resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'Dashboard'; $a->css = 'badge'; $a->target = '_BLANK'; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $a->href = 'https://console.aws.amazon.com/ec2/'; } if ($hc->account_type == 'lc-openstack') { $a->href = 'http://' . $hc->host . '/project/instances/'; } $plugin_link = $a->get_string(); return $plugin_link; }
function openqrm_hybrid_cloud_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $RootDir; $openqrm_server = new openqrm_server(); $appliance_id = $appliance_fields["appliance_id"]; $appliance_name = $appliance_fields["appliance_name"]; $resource = new resource(); $resource->get_instance_by_id($appliance_fields["appliance_resources"]); $appliance_ip = $resource->ip; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); // check appliance values, maybe we are in update and they are incomplete if ($appliance->imageid == 1) { return; } if ($resource->id == "-1" || $resource->id == "" || !isset($resource->vtype)) { return; } $event->log("openqrm_hybrid_cloud_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-appliance-hook.php", "Handling " . $cmd . " event " . $appliance_id . "/" . $appliance_name . "/" . $appliance_ip, "", "", 0, 0, $appliance_id); // check resource type -> hybrid-cloud-strorage-vm $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); switch ($virtualization->type) { case "hybrid-cloud-vm-local": $image = new image(); $image->get_instance_by_id($appliance->imageid); // get hybrid-cloud account $hybrid_cloud_acl_id = $resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("openqrm_hybrid_cloud_appliance", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-hook.php", "Could not find Hybrid-Cloud Account for resource " . $resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $statfile = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/" . $hybrid_cloud_acl_id . ".run_instances.hostname"; switch ($cmd) { case "start": // send command to assign image and start instance $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm run "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $resource->hostname; $command .= ' -a ' . $image->rootdevice; $command .= ' -ii ' . $image->id; $command .= ' -ia ' . $appliance->name; $command .= ' --openqrm-cmd-mode background'; // wait for hostname statfile if (file_exists($statfile)) { unlink($statfile); } $openqrm_server->send_command($command, NULL, true); while (!file_exists($statfile)) { usleep(10000); clearstatcache(); } // special hostname handling for aws + euca if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $resource_new_hostname = file_get_contents($statfile); $resource_new_hostname = trim($resource_new_hostname); unlink($statfile); // update hostname in resource $resource_fields["resource_hostname"] = $resource_new_hostname; $resource->update_info($resource->id, $resource_fields); } // reset image_isactive -> AMI are cloned anyway $image->set_active(1); break; case "stop": // send command to stop the vm and deassign image $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm terminate "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $resource->hostname; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); // special hostname handling for aws + euca if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $resource_new_hostname = $hc->account_type . $resource->id; // update hostname in resource $resource_fields["resource_hostname"] = $resource_new_hostname; $resource->update_info($resource->id, $resource_fields); } break; } break; } }
function imtarget() { $h = array(); $h['image_icon']['title'] = ' '; $h['image_icon']['sortable'] = false; $h['image_id']['title'] = $this->lang['table_id']; $h['image_name']['title'] = $this->lang['table_name']; $h['image_version']['title'] = $this->lang['table_version']; $h['image_type']['title'] = $this->lang['table_deployment']; $h['image_isactive']['title'] = $this->lang['table_isactive']; $h['image_comment']['title'] = $this->lang['table_comment']; $h['image_comment']['sortable'] = false; $h['edit']['title'] = ' '; $h['edit']['sortable'] = false; $image = new image(); $params = $this->response->get_array($this->actions_name, 'target'); $b = array(); $table = $this->response->html->tablebuilder('hybridcloud_imtarget', $params); $table->offset = 0; $table->sort = 'image_id'; $table->limit = 10; $table->order = 'ASC'; $table->max = $image->get_count(); $table->init(); $image_arr = $image->display_overview(0, 10000, $table->sort, $table->order); $image_icon = "/openqrm/base/img/image.png"; foreach ($image_arr as $index => $image_db) { // prepare the values for the array $image = new image(); $image->get_instance_by_id($image_db["image_id"]); if ($image->type === 'lvm-nfs-deployment' || $image->type === 'nfs-deployment') { $image_comment = $image_db["image_comment"]; if (!strlen($image_comment)) { $image_comment = "-"; } $image_version = $image_db["image_version"]; if (!strlen($image_version)) { $image_version = " "; } // edit $a = $this->response->html->a(); $a->title = $this->lang['action_import']; $a->label = $this->lang['action_import']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, 'imparams') . '&image_id=' . $image->id; $image_edit = $a->get_string(); // set the active icon $isactive_icon = "/openqrm/base/img/enable.png"; if ($image_db["image_isactive"] == 1) { $isactive_icon = "/openqrm/base/img/disable.png"; } $image_isactive_icon = "<img src=" . $isactive_icon . " width='24' height='24' alt='State'>"; $b[] = array('image_icon' => "<img width='24' height='24' src='" . $image_icon . "'>", 'image_id' => $image_db["image_id"], 'image_name' => $image_db["image_name"], 'image_version' => $image_version, 'image_type' => $image_db["image_type"], 'image_isactive' => $image_isactive_icon, 'image_comment' => $image_comment, 'edit' => $image_edit); } } $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = false; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100)); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'target', false)->get_elements(); $d['table'] = $table; return $d; }
function add() { $response = $this->get_response(); $form = $response->form; $errors = array(); if (!$form->get_errors() && $this->response->submit()) { $group_name = $form->get_request('name'); if (!strlen($group_name)) { $errors[] = $this->lang['error_name']; } $group_description = $form->get_request('description'); if (!strlen($group_description)) { $errors[] = $this->lang['error_description']; } $group_vpc_parameter = ''; $group_vpc = $form->get_request('vpc'); if (strlen($group_vpc)) { $group_vpc_parameter = ' -c ' . $group_vpc; } if (count($errors) > 0 || $form->get_errors()) { $response->error = join('<br>', $errors); } else { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $openqrm = new openqrm_server(); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group create'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' -gn ' . $group_name; $command .= ' -gd ' . $group_description; $command .= $group_vpc_parameter; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm->send_command($command, NULL, true); sleep(4); $response->msg = sprintf($this->lang['msg_added_group'], $group_name); //$ev = new event(); //$ev->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", $command, "", "", 0, 0, 0); } } return $response; }
function __reload() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-keypair describe'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -c ' . $hc->rc_config; $command .= ' -t ' . $hc->account_type; $command .= ' -ir ' . $this->response->html->request()->get('region'); $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc->id . '.describe_keypair.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $openqrm = new openqrm_server(); $openqrm->send_command($command); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
function remove() { $response = $this->get_response(); $group_name = $response->html->request()->get('group_name'); $form = $response->form; $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); $d['param_f']['label'] = $group_name; $d['param_f']['object']['type'] = 'htmlobject_input'; $d['param_f']['object']['attrib']['type'] = 'checkbox'; $d['param_f']['object']['attrib']['name'] = 'group_name'; $d['param_f']['object']['attrib']['value'] = $group_name; $d['param_f']['object']['attrib']['checked'] = true; $form->add($d); if (!$form->get_errors() && $response->submit()) { $errors = array(); $message = array(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group remove'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' -gn ' . $group_name; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); $message[] = sprintf($this->lang['msg_removed'], $group_name); if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } sleep(4); } return $response; }
function edit() { // filter $alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; $alphabet_arr = explode(",", $alphabet); $filter_str = ''; foreach ($alphabet_arr as $index => $character) { $a = $this->response->html->a(); $a->label = $character; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "edit", 'hybrid_cloud_snapshot_filter', $character); if ($this->filter === $character) { $a->css = 'edit current'; } $filter_str .= $a->get_string(); } $d['filter'] = $filter_str; // public or own AMIs ? $snapshot_type_switch = ''; $snapshot_type_switch_cmd_parameter = ''; if ($this->snapshot_type == 'public') { $a = $this->response->html->a(); $a->label = $this->lang['table_private_snapshot']; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "edit", "snapshot_type", "private"); $a->css = 'edit'; $snapshot_type_switch = $a->get_string(); $snapshot_type_switch_cmd_parameter = ' -ap public'; } else { if ($this->snapshot_type == 'private') { $a = $this->response->html->a(); $a->label = $this->lang['table_public_snapshot']; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "edit", "snapshot_type", "public"); $a->css = 'edit'; $snapshot_type_switch = $a->get_string(); $snapshot_type_switch_cmd_parameter = ' -ap private'; $d['filter'] = ''; } } $d['snapshot_type_switch'] = $snapshot_type_switch; $h = array(); $h['snapshot']['title'] = $this->lang['table_snapshot']; $h['volume']['title'] = $this->lang['table_path']; $h['state']['title'] = $this->lang['table_state']; $h['from']['title'] = $this->lang['table_date']; $h['description']['title'] = $this->lang['table_comment']; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_snapshots.log'; if ($this->file->exists($file)) { $this->file->remove($file); } require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); if (!strlen($this->filter)) { $this->filter = "a"; } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ebs describe_snapshots'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -f ' . $this->filter; $command .= ' -ar ' . $this->region; $command .= $snapshot_type_switch_cmd_parameter; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { // e.g. SNAPSHOT@snap-fb1aecd3@vol-02747728@completed@2013-01-18T19:22:01+0000@100%@647496772601@1@pvlinux-centos-5.5-x86_1.3.0.156_130118_135827 $tmp = explode('@', $v); $snapshot = $tmp[1]; $volume = $tmp[2]; $state = $tmp[3]; $from = $tmp[4]; $description = $tmp[8]; // remove only for own snapshots if ($this->snapshot_type == 'public') { $remove = ''; } else { if ($this->snapshot_type == 'private') { $a = $this->response->html->a(); $a->label = $this->lang['action_remove_snapshot']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "remove", "snapshot_name", $snapshot); $a->css = 'edit'; $remove = $a->get_string(); } } $b[] = array('snapshot' => $snapshot, 'volume' => $volume, 'state' => $state, 'from' => $from, 'description' => $description, 'remove' => $remove); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_snap_edit', $params); $table->offset = 0; $table->sort = 'snapshot'; $table->limit = 100; $table->order = 'ASC'; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'edit', false)->get_elements(); $d['table'] = $table; return $d; }
function get_response() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $response = $this->response; $form = $response->get_form($this->actions_name, 'snap'); $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); $d['description']['label'] = sprintf($this->lang['form_description'], $this->volume_name); $d['description']['required'] = true; $d['description']['object']['type'] = 'htmlobject_input'; $d['description']['object']['attrib']['id'] = 'description'; $d['description']['object']['attrib']['name'] = 'description'; $d['description']['object']['attrib']['type'] = 'text'; $d['description']['object']['attrib']['value'] = ''; $d['description']['object']['attrib']['maxlength'] = 255; $form->add($d); $response->form = $form; return $response; }
function remove() { $response = $this->get_response(); $accounts = $response->html->request()->get($this->identifier_name); $form = $response->form; if ($accounts !== '') { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $resource = new hybrid_cloud(); $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); $i = 0; foreach ($accounts as $id) { $name = $resource->get_name($id); $d['param_f' . $i]['label'] = $name; $d['param_f' . $i]['object']['type'] = 'htmlobject_input'; $d['param_f' . $i]['object']['attrib']['type'] = 'checkbox'; $d['param_f' . $i]['object']['attrib']['name'] = $this->identifier_name . '[' . $i . ']'; $d['param_f' . $i]['object']['attrib']['value'] = $id; $d['param_f' . $i]['object']['attrib']['checked'] = true; $i++; } $form->add($d); if (!$form->get_errors() && $response->submit()) { $hc = new hybrid_cloud(); $errors = array(); $message = array(); foreach ($accounts as $id) { $hc->get_instance_by_id($id); $hc->remove($id); $form->remove($this->identifier_name . '[' . $id . ']'); $message[] = sprintf($this->lang['msg_removed'], $hc->account_name); } if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } } } else { $response->msg = ''; } return $response; }
function get_response() { $size_select_arr = array(); for ($n = 1; $n <= 1024; $n++) { $size_select_arr[] = array($n, $n); } $type_select_arr = array(); $type_select_arr[] = array('standard', 'standard'); $type_select_arr[] = array('io1', 'io1'); $iops_select_arr = array(); for ($n = 100; $n <= 4000; $n = $n + 100) { $iops_select_arr[] = array($n, $n); } $snapshot_select_arr = array(); $snapshot_select_arr[] = array('', ''); $availability_zones_select_arr = array(); if (file_exists($this->statfile)) { $lines = explode("\n", file_get_contents($this->statfile)); if (count($lines) >= 1) { foreach ($lines as $line) { if ($line !== '') { $line = explode('@', $line); switch ($line[0]) { case 'ZONES': $availability_zones_select_arr[] = array($line[1], $line[1] . " / " . $line[2]); break; case 'SNAPSHOTS': $snapshot_select_arr[] = array($line[1], $line[1] . " / " . $line[2]); break; } } } } } require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $response = $this->response; $form = $response->get_form($this->actions_name, 'add'); $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); $d['snapshot']['label'] = $this->lang['form_snapshot']; $d['snapshot']['required'] = false; $d['snapshot']['object']['type'] = 'htmlobject_select'; $d['snapshot']['object']['attrib']['name'] = 'snapshot'; $d['snapshot']['object']['attrib']['index'] = array(0, 1); $d['snapshot']['object']['attrib']['options'] = $snapshot_select_arr; $a = $this->response->html->a(); $a->label = $this->lang['form_snapshots']; $a->handler = 'onclick="wait();"'; $a->css = 'add'; $a->href = 'index.php?plugin=hybrid-cloud&controller=hybrid-cloud-snapshot&hybrid_cloud_id=' . $this->id . '®ion=' . $this->region; $d['snapshot_list'] = $a->get_string(); $d['availability_zone']['label'] = $this->lang['form_availability_zone']; $d['availability_zone']['required'] = true; $d['availability_zone']['object']['type'] = 'htmlobject_select'; $d['availability_zone']['object']['attrib']['name'] = 'availability_zone'; $d['availability_zone']['object']['attrib']['index'] = array(0, 1); $d['availability_zone']['object']['attrib']['options'] = $availability_zones_select_arr; $d['size']['label'] = $this->lang['form_size']; $d['size']['required'] = true; $d['size']['object']['type'] = 'htmlobject_select'; $d['size']['object']['attrib']['name'] = 'size'; $d['size']['object']['attrib']['index'] = array(0, 1); $d['size']['object']['attrib']['options'] = $size_select_arr; $d['type']['label'] = $this->lang['form_type']; $d['type']['required'] = true; $d['type']['object']['type'] = 'htmlobject_select'; $d['type']['object']['attrib']['name'] = 'type'; $d['type']['object']['attrib']['index'] = array(0, 1); $d['type']['object']['attrib']['options'] = $type_select_arr; $d['type']['object']['attrib']['selected'] = array('stanard'); $d['iops']['label'] = $this->lang['form_iops']; $d['iops']['required'] = true; $d['iops']['object']['type'] = 'htmlobject_select'; $d['iops']['object']['attrib']['name'] = 'iops'; $d['iops']['object']['attrib']['index'] = array(0, 1); $d['iops']['object']['attrib']['options'] = $iops_select_arr; $form->add($d); $response->form = $form; return $response; }
function add() { $response = $this->get_response(); $form = $response->form; $errors = array(); if (!$form->get_errors() && $this->response->submit()) { $protocol = $form->get_request('protocol'); $portnumber = $form->get_request('port_number'); if (count($errors) > 0 || $form->get_errors()) { $response->error = join('<br>', $errors); } else { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $openqrm = new openqrm_server(); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group add_perm'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' -gn ' . $this->group_name; $command .= ' -pt ' . $protocol; $command .= ' -pp ' . $portnumber; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm->send_command($command, NULL, true); sleep(4); $response->msg = sprintf($this->lang['msg_added_permission'], $protocol . '/' . $portnumber, $this->group_name); //$ev = new event(); //$ev->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", $command, "", "", 0, 0, 0); } } return $response; }
function edit() { $h = array(); $h['type']['title'] = ' '; $h['type']['sortable'] = false; $h['buckets']['title'] = $this->lang['table_name']; $h['count']['title'] = $this->lang['table_file_count']; $h['select']['title'] = ' '; $h['select']['sortable'] = false; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $a = $this->response->html->a(); $a->label = $this->lang['action_add_s3_bucket']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add"); $d['add_s3_bucket'] = $a->get_string(); $buckets = $this->s3->listBuckets(true); $b = array(); foreach ($buckets['buckets'] as $k => $v) { if ($v !== '') { $name = $v['name']; $remove_bucket = ''; $file_count = count($this->s3->getBucket($name)); if ($file_count == 0) { $a = $this->response->html->a(); $a->label = $this->lang['action_remove_s3_bucket']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "remove") . '&bucket_name=' . $name; $remove_bucket = $a->get_string(); } $a = $this->response->html->a(); $a->label = $this->lang['action_select_s3_bucket']; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "files") . '&bucket_name=' . $name; $select_bucket = $a->get_string(); $type_icon = ''; $b[] = array('type' => $type_icon, 'buckets' => $name, 'count' => $file_count, 'select' => $select_bucket, 'remove' => $remove_bucket); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_s3_edit', $params); $table->form_action = $this->response->html->thisfile; $table->offset = 0; $table->sort = 'name'; $table->limit = 10; $table->order = 'ASC'; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'edit', false)->get_elements(); $d['table'] = $table; return $d; }
function __reload_instance_configuration() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ebs instance_configuration'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->response->html->request()->get('region'); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc->id . '.attach_volume_configuration.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
function get_response() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $response = $this->response; $form = $response->get_form($this->actions_name, 'attach'); $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); // instance select $instance_select_array = array(); if (file_exists($this->statfile)) { $lines = explode("\n", file_get_contents($this->statfile)); if (count($lines) >= 1) { foreach ($lines as $line) { if ($line !== '') { $line = explode('@', $line); switch ($line[0]) { case 'INSTANCE': $instance_select_array[] = array($line[1], $line[1]); break; } } } } } // device select $device_select_array[] = array("/dev/sdf", "/dev/sdf"); $device_select_array[] = array("/dev/sdg", "/dev/sdg"); $device_select_array[] = array("/dev/sdh", "/dev/sdh"); $device_select_array[] = array("/dev/sdi", "/dev/sdi"); $device_select_array[] = array("/dev/sdj", "/dev/sdj"); $device_select_array[] = array("/dev/sdk", "/dev/sdk"); $device_select_array[] = array("/dev/sdl", "/dev/sdl"); $device_select_array[] = array("/dev/sdm", "/dev/sdm"); $device_select_array[] = array("/dev/sdn", "/dev/sdn"); $device_select_array[] = array("/dev/sdo", "/dev/sdo"); $device_select_array[] = array("/dev/sdp", "/dev/sdp"); $device_select_array[] = array("/dev/sdq", "/dev/sdq"); $device_select_array[] = array("/dev/sdr", "/dev/sdr"); $device_select_array[] = array("/dev/sds", "/dev/sds"); $device_select_array[] = array("/dev/sdt", "/dev/sdt"); $device_select_array[] = array("/dev/sdu", "/dev/sdu"); $device_select_array[] = array("/dev/sdv", "/dev/sdv"); $device_select_array[] = array("/dev/sdw", "/dev/sdw"); $device_select_array[] = array("/dev/sdx", "/dev/sdx"); $device_select_array[] = array("/dev/sdy", "/dev/sdy"); $device_select_array[] = array("/dev/sdz", "/dev/sdz"); $d['instances']['label'] = $this->lang['form_instance_name']; $d['instances']['required'] = true; $d['instances']['object']['type'] = 'htmlobject_select'; $d['instances']['object']['attrib']['name'] = 'instances'; $d['instances']['object']['attrib']['index'] = array(0, 1); $d['instances']['object']['attrib']['options'] = $instance_select_array; $d['devices']['label'] = $this->lang['form_device_name']; $d['devices']['required'] = true; $d['devices']['object']['type'] = 'htmlobject_select'; $d['devices']['object']['attrib']['name'] = 'devices'; $d['devices']['object']['attrib']['index'] = array(0, 1); $d['devices']['object']['attrib']['options'] = $device_select_array; $form->add($d); $response->form = $form; return $response; }
function get_response() { $this->response->add('hybrid_cloud_id', $this->response->html->request()->get('hybrid_cloud_id')); $this->response->add('image_id', $this->response->html->request()->get('image_id')); $response = $this->response; $form = $response->get_form($this->actions_name, 'extarget'); $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $submit = $form->get_elements('cancel'); $submit->handler = 'onclick="cancel();"'; $form->add($submit, 'cancel'); $d['name']['label'] = $this->lang['form_name']; $d['name']['required'] = true; $d['name']['validate']['regex'] = '/^[a-z0-9]+$/i'; $d['name']['validate']['errormsg'] = sprintf($this->lang['error_name'], 'a-z0-9'); $d['name']['object']['type'] = 'htmlobject_input'; $d['name']['object']['attrib']['name'] = 'name'; $d['name']['object']['attrib']['id'] = 'name'; $d['name']['object']['attrib']['type'] = 'text'; $d['name']['object']['attrib']['css'] = 'namegen'; $d['name']['object']['attrib']['customattribs'] = 'data-prefix="export" data-length="6"'; $d['name']['object']['attrib']['maxlength'] = 50; $d['name']['object']['attrib']['minlength'] = 8; $size[] = array('500', '500 MB'); $size[] = array('1000', '1 GB'); $size[] = array('2000', '2 GB'); $size[] = array('3000', '3 GB'); $size[] = array('4000', '4 GB'); $size[] = array('5000', '5 GB'); $size[] = array('10000', '10 GB'); $d['size']['label'] = $this->lang['form_size']; $d['size']['object']['type'] = 'htmlobject_select'; $d['size']['object']['attrib']['name'] = 'size'; $d['size']['object']['attrib']['index'] = array(0, 1); $d['size']['object']['attrib']['options'] = $size; $arch[] = array('x86_64'); $arch[] = array('i368'); $d['arch']['label'] = $this->lang['form_architecture']; $d['arch']['object']['type'] = 'htmlobject_select'; $d['arch']['object']['attrib']['name'] = 'arch'; $d['arch']['object']['attrib']['index'] = array(0, 0); $d['arch']['object']['attrib']['options'] = $arch; $d['public_key_file']['label'] = $this->lang['form_public_key_file']; $d['public_key_file']['required'] = true; $d['public_key_file']['object']['type'] = 'htmlobject_input'; $d['public_key_file']['object']['attrib']['id'] = 'public_key_file'; $d['public_key_file']['object']['attrib']['name'] = 'public_key_file'; $d['public_key_file']['object']['attrib']['type'] = 'text'; $d['public_key_file']['object']['attrib']['value'] = ''; $d['public_key_file']['object']['attrib']['maxlength'] = 255; $d['private_key_file']['label'] = $this->lang['form_private_key_file']; $d['private_key_file']['required'] = true; $d['private_key_file']['object']['type'] = 'htmlobject_input'; $d['private_key_file']['object']['attrib']['id'] = 'private_key_file'; $d['private_key_file']['object']['attrib']['name'] = 'private_key_file'; $d['private_key_file']['object']['attrib']['type'] = 'text'; $d['private_key_file']['object']['attrib']['value'] = ''; $d['private_key_file']['object']['attrib']['maxlength'] = 255; $d['user_id']['label'] = $this->lang['form_user_id']; $d['user_id']['required'] = true; $d['user_id']['object']['type'] = 'htmlobject_input'; $d['user_id']['object']['attrib']['id'] = 'user_id'; $d['user_id']['object']['attrib']['name'] = 'user_id'; $d['user_id']['object']['attrib']['type'] = 'text'; $d['user_id']['object']['attrib']['value'] = ''; $d['user_id']['object']['attrib']['maxlength'] = 255; $form->add($d); $response->form = $form; require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $response->hc = $hc; $img = $this->openqrm->image(); $img->get_instance_by_id($this->response->html->request()->get('image_id')); $response->image = $img; return $response; }
function openqrm_hybrid_cloud_resource_virtual_command($cmd, $resource_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $resource_id = $resource_fields["resource_id"]; $resource = new resource(); $resource->get_instance_by_id($resource_id); $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); switch ($virtualization->type) { case "hybrid-cloud": $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Handling " . $cmd . " command of resource " . $resource->id, "", "", 0, 0, 0); // noop break; case "hybrid-cloud-vm-local": $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Handling " . $cmd . " command of resource " . $resource->id, "", "", 0, 0, 0); $openqrm_server = new openqrm_server(); // get hybrid-cloud account $hybrid_cloud_acl_id = $resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Could not find Hybrid-Cloud Account for resource " . $resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } switch ($cmd) { case "reboot": $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm restart "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= ' -in ' . $resource->hostname; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); break; case "halt": $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm stop "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= ' -in ' . $resource->hostname; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); break; } break; } }
function files() { $h = array(); $h['files']['title'] = $this->lang['table_files']; $h['time']['title'] = $this->lang['table_time']; $h['size']['title'] = $this->lang['table_size']; $h['url']['title'] = $this->lang['table_url']; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $a = $this->response->html->a(); $a->label = $this->lang['action_add_s3_file']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "upload"); $d['add_s3_upload'] = $a->get_string(); $files = $this->s3->getBucket($this->bucket_name); $b = array(); foreach ($files as $v) { if ($v !== '') { $name = $v['name']; $time = $v['time']; $size = $v['size']; // $hash = $v['hash']; if ($size == 0) { $size = '0'; } $time = date(DATE_RFC822, $time); $url = 'https://s3.amazonaws.com/' . $this->bucket_name . '/' . $name; $a = $this->response->html->a(); $a->label = $url; $a->css = ''; $a->target = '_BLANK'; $a->href = $url; $file_url = $a->get_string(); $file_formatted = $this->response->html->customtag('code'); $file_formatted->add($file_url); $a = $this->response->html->a(); $a->label = $this->lang['action_remove_s3_file']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "delete") . '&file_name=' . $name; $remove_file = $a->get_string(); $b[] = array('files' => $name, 'time' => $time, 'size' => $size, 'url' => $file_formatted, 'remove' => $remove_file); } } $params = $this->response->get_array($this->actions_name, 'files'); $table = $this->response->html->tablebuilder('hybridcloud_s3_files', $params); $table->form_action = $this->response->html->thisfile; $table->offset = 0; $table->sort = 'name'; $table->limit = 10; $table->order = 'ASC'; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'import', false)->get_elements(); $d['table'] = $table; return $d; }
function add() { $response = $this->get_response(); $form = $response->form; if (!$form->get_errors() && $this->response->submit()) { $fi = $form->get_request(); $hc_account_name = $fi['hybrid_cloud_account_name']; $hc_account_type = $form->get_static('type'); $hc_account_type = $hc_account_type['0']; $fi['hybrid_cloud_account_type'] = $hc_account_type; $hc_authentication = ''; if ($hc_account_type == 'aws' || $hc_account_type == 'euca') { $hc_access_key = $fi['hybrid_cloud_access_key']; $hc_secret_key = $fi['hybrid_cloud_secret_key']; $hc_authentication = ' -O ' . $hc_access_key . ' -W ' . $hc_secret_key; } if ($hc_account_type == 'lc-openstack') { $hc_username = $fi['hybrid_cloud_username']; $hc_password = $fi['hybrid_cloud_password']; $hc_host = $fi['hybrid_cloud_host']; $hc_port = $fi['hybrid_cloud_port']; $hc_tenant = $fi['hybrid_cloud_tenant']; $hc_endpoint = $fi['hybrid_cloud_endpoint']; $hc_authentication = ' -u ' . $hc_username . ' -p ' . $hc_password . ' -q ' . $hc_host . ' -x ' . $hc_port . ' -g ' . $hc_tenant . ' -e ' . $hc_endpoint; } // check if account data is valid and working $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc_account_name . '.acl_check.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-account check'; $command .= ' -n ' . $hc_account_name; $command .= ' -t ' . $hc_account_type; $command .= $hc_authentication; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $pos = strpos($content, "success"); if ($pos === false) { $response->msg = sprintf($this->lang['msg_add_fail'], $fi['hybrid_cloud_account_name']); } else { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $fi['hybrid_cloud_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $hc->add($fi); $response->msg = sprintf($this->lang['msg_added'], $fi['hybrid_cloud_account_name']); } $this->file->remove($file); } return $response; }
function fence_hybrid_cloud_vm_local($host_resource_id, $mac) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Fencing Cloud VM " . $mac, "", "", 0, 0, 0); $origin_resource = new resource(); $origin_resource->get_instance_by_mac($mac); // get hybrid-cloud account from origin resource $hybrid_acl_id = $origin_resource->get_resource_capabilities("HCACL"); $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_acl_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $openqrm = new openqrm_server(); $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm fence "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -im ' . $mac; $command .= ' --openqrm-cmd-mode background'; $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Running {$command}", "", "", 0, 0, 0); $openqrm->send_command($command, NULL, true); $rufields["resource_hostname"] = $hc->account_type . $origin_resource->id; $origin_resource->update_info($origin_resource->id, $rufields); // debug // echo "1:".$command; }
function __reload_configuration() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; $hc_authentication .= ' -ir ' . $this->response->html->request()->get('region'); } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm configuration'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc->id . '.describe_configuration.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
function remove_hybrid_cloud_vm_local($host_resource_id, $name, $mac) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-cloud-hook", "Removing Cloud VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0); $openqrm = new openqrm_server(); $cloud_resource = new resource(); $cloud_resource->get_instance_by_mac($mac); $hc_default_account_id = $cloud_resource->get_resource_capabilities("HCACL"); $cloud_resource_hostname = $cloud_resource->hostname; if (strlen($hc_default_account_id)) { // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! found Cloud Account ".$hc_default_account_id." from resource config", "", "", 0, 0, 0); } else { $file = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf"; $ini = openqrm_parse_conf($file); $hc_default_account_id = $ini['OPENQRM_PLUGIN_HYBRID_CLOUD_DEFAULT_ACCOUNT']; // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! got Cloud Account ".$hc_default_account_id." from plugin config", "", "", 0, 0, 0); } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hc_default_account_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $openqrm = new openqrm_server(); $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm remove "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $cloud_resource_hostname; $command .= ' --openqrm-cmd-mode background'; // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "Running $command", "", "", 0, 0, 0); $openqrm->send_command($command, NULL, true); }
function select() { $h = array(); $h['hybrid_cloud_id']['title'] = $this->lang['table_id']; $h['hybrid_cloud_id']['hidden'] = true; $h['hybrid_cloud_account_name']['title'] = $this->lang['table_name']; $h['hybrid_cloud_account_name']['hidden'] = true; $h['hybrid_cloud_account_type']['title'] = $this->lang['table_type']; $h['hybrid_cloud_account_type']['hidden'] = true; $h['data']['title'] = ' '; $h['data']['sortable'] = false; $h['hybrid_cloud_description']['title'] = $this->lang['table_description']; $h['hybrid_cloud_description']['sortable'] = false; $h['action_buttons']['title'] = ' '; $h['action_buttons']['sortable'] = false; $h['edit']['title'] = ' '; $h['edit']['sortable'] = false; $params = $this->response->get_array($this->actions_name, 'select'); $b = array(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $resource = new hybrid_cloud(); $table = $this->response->html->tablebuilder('accounts', $params); $table->offset = 0; $table->sort = 'hybrid_cloud_id'; $table->limit = 10; $table->order = 'ASC'; $table->max = $resource->get_count('all'); $table->init(); $resources = $resource->display_overview($table->offset, $table->limit, $table->sort, $table->order); foreach ($resources as $k => $v) { $account_type = $v["hybrid_cloud_account_type"]; if ($account_type == "aws" || $account_type == "euca") { $a = $this->response->html->a(); $a->title = $this->lang['action_ami']; $a->label = $this->lang['action_ami']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-ami&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $ami = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_instance']; $a->label = $this->lang['action_instance']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-vm&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $instance = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_snapshots']; $a->label = $this->lang['action_snapshots']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-snapshot&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $snapshots = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_volumes']; $a->label = $this->lang['action_volumes']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-volume&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $volumes = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_keypair']; $a->label = $this->lang['action_keypair']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-keypair&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $keypair = $a->get_string(); $group = ''; if ($account_type == "euca") { $a = $this->response->html->a(); $a->title = $this->lang['action_group']; $a->label = $this->lang['action_group']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-group&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $group = $a->get_string(); } $a = $this->response->html->a(); $a->title = $this->lang['action_s3']; $a->label = $this->lang['action_s3']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-s3&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $s3 = $a->get_string(); $i = $this->response->html->a(); $i->title = $this->lang['action_import']; $i->label = $this->lang['action_import']; $i->handler = 'onclick="wait();"'; $i->css = 'btn'; $i->href = $this->response->get_url($this->actions_name, "import") . '&hybrid_cloud_id=' . $v["hybrid_cloud_id"]; $import = $i->get_string(); $e = $this->response->html->a(); $e->title = $this->lang['action_export']; $e->label = $this->lang['action_export']; $e->handler = 'onclick="wait();"'; $e->css = 'btn'; $e->href = $this->response->get_url($this->actions_name, "export") . '&hybrid_cloud_id=' . $v["hybrid_cloud_id"]; $export = $e->get_string(); $c = $this->response->html->a(); $c->title = $this->lang['action_dashboard']; $c->label = $this->lang['action_dashboard']; $c->css = 'btn'; $c->target = '_BLANK'; $c->href = 'https://console.aws.amazon.com/ec2/'; $ec2console = $c->get_string(); $actions = $instance . $keypair . $group . "<br>" . $ami . $import . $export . "<br>" . $s3 . $volumes . $snapshots . "<br>" . $ec2console; } if ($account_type == "lc-openstack") { $a = $this->response->html->a(); $a->title = $this->lang['action_ami']; $a->label = $this->lang['action_ami']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-ami&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $ami = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_instance']; $a->label = $this->lang['action_instance']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-vm&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $instance = $a->get_string(); $lc_hc = new hybrid_cloud(); $lc_hc->get_instance_by_id($v["hybrid_cloud_id"]); $a = $this->response->html->a(); $a->title = $this->lang['action_dashboard']; $a->label = $this->lang['action_dashboard']; $a->css = 'btn'; $a->target = '_BLANK'; $a->href = 'http://' . $lc_hc->host . '/project/instances/'; $dashboard = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_keypair']; $a->label = $this->lang['action_keypair']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-keypair&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $keypair = $a->get_string(); $a = $this->response->html->a(); $a->title = $this->lang['action_group']; $a->label = $this->lang['action_group']; $a->handler = 'onclick="wait();"'; $a->css = 'btn'; $a->href = '/openqrm/base/index.php?plugin=hybrid-cloud&controller=hybrid-cloud-group&hybrid_cloud_id=' . $v["hybrid_cloud_id"] . '®ion=' . $this->region; $group = $a->get_string(); $actions = $instance . $keypair . $group . "<br>" . $ami . $dashboard; } $a = $this->response->html->a(); $a->title = $this->lang['action_edit']; $a->label = $this->lang['action_edit']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, "edit") . '&hybrid_cloud_id=' . $v["hybrid_cloud_id"]; $edit = $a->get_string(); if (!isset($v["hybrid_cloud_description"])) { $v["hybrid_cloud_description"] = ' '; } $data = '<b>' . $this->lang['table_id'] . '</b>: ' . $v["hybrid_cloud_id"] . '<br>'; $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $v["hybrid_cloud_account_name"] . '<br>'; $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $v["hybrid_cloud_account_type"]; $b[] = array('hybrid_cloud_id' => $v["hybrid_cloud_id"], 'hybrid_cloud_account_name' => $v["hybrid_cloud_account_name"], 'hybrid_cloud_account_type' => $v["hybrid_cloud_account_type"], 'data' => $data, 'hybrid_cloud_description' => $v["hybrid_cloud_description"], 'action_buttons' => $actions, 'edit' => $edit); } $add = $this->response->html->a(); $add->title = $this->lang['action_add']; $add->label = $this->lang['action_add']; $add->handler = 'onclick="wait();"'; $add->css = 'add'; $add->href = $this->response->get_url($this->actions_name, "add"); $table->form_action = $this->response->html->thisfile; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = false; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; $table->actions_name = $this->actions_name; $table->actions = array(array('remove' => $this->lang['action_remove'])); $table->identifier = 'hybrid_cloud_id'; $table->identifier_name = $this->identifier_name; $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100)); $d['table'] = $table; $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements(); $d['add'] = $add->get_string(); return $d; }
function edit() { $h = array(); $h['volume']['title'] = $this->lang['table_volume']; $h['id']['title'] = $this->lang['table_id']; $h['snapshot']['title'] = $this->lang['table_snapshot']; $h['zone']['title'] = $this->lang['table_zone']; $h['state']['title'] = $this->lang['table_state']; $h['date']['title'] = $this->lang['table_date']; $h['type']['title'] = $this->lang['table_type']; $h['snap']['title'] = ' '; $h['snap']['sortable'] = false; $h['attach']['title'] = ' '; $h['attach']['sortable'] = false; $h['detach']['title'] = ' '; $h['detach']['sortable'] = false; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_volumes.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $a = $this->response->html->a(); $a->label = $this->lang['action_add_volume']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add"); $d['add_volume'] = $a->get_string(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ebs describe_volumes'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { // e.g. VOLUME vol-1a2b3c4d 30 snap-1a2b3c4d us-west-2a available YYYY-MM-DDTHH:MM:SS+0000 standard $tmp = explode('@', $v); $volume = $tmp[1]; $id = $tmp[2]; $snapshot = $tmp[3]; $zone = $tmp[4]; $state = $tmp[5]; $date = $tmp[6]; $type = $tmp[7]; $a = $this->response->html->a(); $a->label = $this->lang['action_snap_volume']; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "snap", "volume_name", $volume); $a->css = 'edit'; $snap = $a->get_string(); if ($state == 'available') { $a = $this->response->html->a(); $a->label = $this->lang['action_attach_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "attach", "volume_name", $volume); $a->css = 'edit'; $attach = $a->get_string(); $a = $this->response->html->a(); $a->label = $this->lang['action_remove_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "remove", "volume_name", $volume); $a->css = 'edit'; $remove = $a->get_string(); } else { $a = $this->response->html->a(); $a->label = $this->lang['action_detach_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "detach", "volume_name", $volume); $a->css = 'edit'; $attach = $a->get_string(); $remove = ''; } $b[] = array('volume' => $volume, 'id' => $id, 'snapshot' => $snapshot, 'zone' => $zone, 'state' => $state, 'date' => $date, 'type' => $type, 'snap' => $snap, 'attach' => $attach, 'remove' => $remove); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_import_edit', $params); $table->offset = 0; $table->sort = 'volume'; $table->limit = 200; $table->order = 'ASC'; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'edit', false)->get_elements(); $d['table'] = $table; return $d; }
function select() { $h = array(); $h['state']['title'] = $this->lang['table_state']; $h['name']['title'] = $this->lang['table_name']; $h['region']['title'] = $this->lang['table_region']; $h['ami']['title'] = $this->lang['table_ami']; $h['type']['title'] = $this->lang['table_type']; $h['public']['title'] = $this->lang['table_public_ip']; $h['private']['title'] = $this->lang['table_private_ip']; $h['import']['title'] = ' '; $h['import']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_instances.log'; if ($this->file->exists($file)) { $this->file->remove($file); } require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ir ' . $this->region; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { $tmp = explode('@', $v); $name = $tmp[1]; $ami = $tmp[2]; $public_hostname = $tmp[3]; $private_hostname = $tmp[4]; $state = $tmp[5]; $keypair = $tmp[6]; $unknown1 = $tmp[7]; $unknown2 = $tmp[8]; $type = $tmp[9]; $date = $tmp[10]; $region = $tmp[11]; $unknown4 = $tmp[12]; $unknown5 = $tmp[13]; $unknown6 = $tmp[14]; $monitoring = $tmp[15]; $public_ip = $tmp[16]; $private_ip = $tmp[17]; $unknown7 = $tmp[18]; $unknown8 = $tmp[19]; $store = $tmp[20]; $unknown9 = $tmp[21]; $unknown10 = $tmp[22]; $unknown11 = $tmp[23]; $unknown12 = $tmp[24]; $hvm = $tmp[25]; $virt_type = $tmp[26]; $mac = ''; $select_for_import = ''; if ($state == 'idle') { $state_icon = "/openqrm/base/img/idle.png"; } else { if ($state == 'running') { $state_icon = "/openqrm/base/img/active.png"; // select for import $a = $this->response->html->a(); $a->label = $this->lang['action_import']; $a->title = $this->lang['action_import']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, 'imtarget') . '&instance_name=' . $name . '&instance_public_ip=' . $public_ip . '&instance_public_hostname=' . $public_hostname . '&instance_keypair=' . $keypair; $select_for_import = $a->get_string(); } else { $state_icon = "/openqrm/base/img/error.png"; } } $b[] = array('state' => "<img width=24 height=24 src=" . $state_icon . ">", 'name' => $name, 'region' => $region, 'ami' => $ami, 'type' => $type, 'public' => $public_hostname, 'private' => $private_ip, 'import' => $select_for_import); } } $params = $this->response->get_array($this->actions_name, 'import'); $table = $this->response->html->tablebuilder('hybridcloud_import', $params); $table->offset = 0; $table->sort = 'id'; $table->limit = 10; $table->order = 'ASC'; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'import', false)->get_elements(); $d['table'] = $table; return $d; }
function openqrm_hybrid_cloud_monitor() { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $openqrm_server; global $BaseDir; global $RootDir; $now = $_SERVER['REQUEST_TIME']; // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook DISABLED for now!!!", "", "", 0, 0, 0); // return; // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook", "", "", 0, 0, 0); $last_stats = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/last_statistics"; if (file_exists($last_stats)) { $last_host_stats = file_get_contents($last_stats); $secs_after_last_host_stat = $now - $last_host_stats; if ($secs_after_last_host_stat > 35) { file_put_contents($last_stats, $now); $server = new openqrm_server(); $hc = new hybrid_cloud(); $hc_account_arr = $hc->get_ids(); foreach ($hc_account_arr as $id) { $hc_account_id = $id['hybrid_cloud_id']; $hc->get_instance_by_id($hc_account_id); $hc_authentication = ''; // for every ec2/euca cloud account monitor every configured region if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hybrid_cloud_conf = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf'; $hybrid_cloud_conf_arr = openqrm_parse_conf($hybrid_cloud_conf); $region_arr = explode(",", $hybrid_cloud_conf_arr['OPENQRM_PLUGIN_HYBRID_CLOUD_REGIONS']); $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } // one region for openstack if ($hc->account_type == 'lc-openstack') { $region_arr = array("OpenStack"); $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } foreach ($region_arr as $region) { $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor - checking Cloud statistics for Account " . $hc->account_name . " - " . $region, "", "", 0, 0, 0); $statfile = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/" . $hc_account_id . ".instances_statistics.log"; $command = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe --statistics true'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= ' -ir ' . $region; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; if (file_exists($statfile)) { unlink($statfile); } $server->send_command($command, NULL, true); while (!file_exists($statfile)) { usleep(10000); clearstatcache(); } $content = file_get_contents($statfile); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { $tmp = explode('@', $v); $name = $tmp[1]; $ami = $tmp[2]; $public_hostname = $tmp[3]; $private_hostname = $tmp[4]; $state = $tmp[5]; $keypair = $tmp[6]; $unknown1 = $tmp[7]; $unknown2 = $tmp[8]; $type = $tmp[9]; $date = $tmp[10]; $region = $tmp[11]; $unknown4 = $tmp[12]; $unknown5 = $tmp[13]; $unknown6 = $tmp[14]; $monitoring = $tmp[15]; $public_ip = $hc->format_ip_address($tmp[16]); $private_ip = $hc->format_ip_address($tmp[17]); $unknown7 = $tmp[18]; $unknown8 = $tmp[19]; $store = $tmp[20]; $unknown9 = $tmp[21]; $unknown10 = $tmp[22]; $unknown11 = $tmp[23]; $unknown12 = $tmp[24]; $hvm = $tmp[25]; $virt_type = $tmp[26]; $mac = ''; // check for idle instances $resource = new resource(); if ($state == 'idle') { $mac = $tmp[30]; $resource->get_instance_by_mac($mac); $resource_fields["resource_state"] = 'active'; $resource_fields["resource_lastgood"] = $now; $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type); $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type); $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type); $resource_fields["resource_memused"] = "0"; $resource_fields["resource_load"] = "0"; // restore mgmt ip $resource_fields["resource_ip"] = $resource->network; $resource->update_info($resource->id, $resource_fields); } else { if ($state == 'running') { // check if existing, if not auto-create resource, image and appliance if ($resource->exists_by_name($name)) { // update stats $resource->get_instance_id_by_hostname($name); $resource->get_instance_by_id($resource->id); $resource_fields["resource_state"] = 'active'; $resource_fields["resource_lastgood"] = $now; $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type); $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type); $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type); $resource_fields["resource_memused"] = $resource_fields["resource_memtotal"]; $resource_fields["resource_load"] = "1"; if (strlen($public_ip) && $resource->ip != $public_ip) { // set public ip, update early and run nagios hook $resource_fields["resource_ip"] = $public_ip; $resource->update_info($resource->id, $resource_fields); // nagios enabled and started ? if (file_exists($RootDir . "/plugins/nagios3/.running")) { $virtualization = new virtualization(); $virtualization->get_instance_by_type("hybrid-cloud-vm-local"); $hc_appliance = new appliance(); $hc_appliance->get_instance_by_virtualization_and_resource($virtualization->id, $resource->id); if (strlen($hc_appliance->name)) { // special nagios classes require_once $RootDir . "/plugins/nagios3/class/nagios3_service.class.php"; require_once $RootDir . "/plugins/nagios3/class/nagios3_host.class.php"; // get the nagios service checks $nagios_host = new nagios3_host(); $nagios_host->get_instance_by_appliance_id($hc_appliance->id); $active_nagios_services = explode(',', $nagios_host->appliance_services); $nagios_service_list = ''; foreach ($active_nagios_services as $service_id) { $nagios_service = new nagios3_service(); $nagios_service->get_instance_by_id($service_id); $nagios_service_list = $nagios_service_list . "," . $nagios_service->port; } $nagios_service_list = substr($nagios_service_list, 1); if (strlen($nagios_service_list)) { // appliance has nagios service checks configured $nagios_appliance_stop_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $hc_appliance->name . " --openqrm-cmd-mode background"; $server->send_command($nagios_appliance_stop_cmd, NULL, true); sleep(2); $nagios_appliance_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager add -n " . $hc_appliance->name . " -i " . $public_ip . " -p " . $nagios_service_list . " --openqrm-cmd-mode background"; $server->send_command($nagios_appliance_start_cmd, NULL, true); } } } // nagios finished } $resource->update_info($resource->id, $resource_fields); } else { // through error for now $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "New Resource detected with name " . $name . "!", "", "", 0, 0, 0); } } } } } unlink($statfile); } } } } else { file_put_contents($last_stats, $now); } }
function imparams() { $response = $this->get_response(); $form = $response->form; if (!$form->get_errors() && $this->response->submit()) { $request = $form->get_request(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $image = new image(); $image->get_instance_by_id($this->image_id); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $resource = new resource(); $resource->get_instance_by_id($storage->resource_id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-migration import_instance'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -p ' . $this->instance_public_hostname; $command .= ' -k ' . $this->response->html->request()->get('ssh_key_file'); $command .= ' -t ' . $hc->account_type; $command .= ' -x ' . $this->instance_name; $command .= ' -s ' . $resource->ip . ":" . $image->rootdevice; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); $msg = sprintf($this->lang['msg_imported'], $this->instance_name, $hc->account_name, $image->name); $response->msg = $msg; // $event = new event(); // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", $command, "", "", 0, 0, 0); } return $response; }