function create_clone_template_deployment($cloud_image_id, $image_clone_name, $disk_size) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("create_clone", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Creating clone of image on storage", "", "", 0, 0, 0); // we got the cloudimage id here, get the image out of it $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); // get image, this is already the new logical clone // we just need to physical snapshot it and update the rootdevice $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $image_storageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; // get image storage $storage = new storage(); $storage->get_instance_by_id($image_storageid); $storage_resource_id = $storage->resource_id; // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // template_deployment $image->get_instance_by_id($image_id); // parse the volume group info in the identifier $volume_group_location = dirname($image_rootdevice); $volume_group = basename($volume_group_location); $image_location_name = basename($image_rootdevice); // set default snapshot size if (!strlen($disk_size)) { $disk_size = 5000; } // update the image rootdevice parameter $ar_image_update = array('image_rootdevice' => "/dev/{$volume_group}/{$image_clone_name}"); // For template vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a SAN backend with dedicated volumes per vm-host which all // contain all "golden-images" which are used for snapshotting. // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots // get the vm resource $vm_resource = new resource(); $vm_resource->get_instance_by_id($cloudimage->resource_id); // get the openvz host $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($vm_resource->vhostid); // san backend ? if ($vm_host_resource->id != $resource->id) { $event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS NOT available on this template host, {$resource->id} not equal {$vm_host_resource->id} !! Assuming SAN Backend", "", "", 0, 0, $appliance_id); // update the image storage id with the vm-host-resource $image_deployment = new deployment(); $image_deployment->get_instance_by_type($image_type); // loop over all storage id from type $image_type $found_image_storage = 0; $storage_list_by_type = new storage(); $storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id); foreach ($storage_id_list_by_type as $storage_id_list) { $storage_id = $storage_id_list['storage_id']; $tstorage = new storage(); $tstorage->get_instance_by_id($storage_id); if ($tstorage->resource_id == $vm_host_resource->id) { // re-create update array + new storage id $ar_image_update = array('image_rootdevice' => "/dev/{$volume_group}/{$image_clone_name}", 'image_storageid' => $tstorage->id); $event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Updating Image {$image_id} / {$image_name} with storage id {$tstorage->id}", "", "", 0, 0, $appliance_id); $found_image_storage = 1; break; } } if ($found_image_storage == 0) { $event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 2, "template_deployment-cloud-hook", "SETUP ERROR: Could not find a storage server type {$image_type} using resource {$vm_host_resource->id}. Please create one!", "", "", 0, 0, $appliance_id); $event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 2, "template_deployment-cloud-hook", "SETUP ERROR: Not cloning image {$image_id}", "", "", 0, 0, $appliance_id); return; } } else { $event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS available on this template host, {$resource->id} equal {$vm_host_resource->id}", "", "", 0, 0, $appliance_id); } $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with /dev/{$volume_group}/{$image_clone_name}", "", "", 0, 0, 0); $image->update($image_id, $ar_image_update); $image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template snap -n " . $image_location_name . " -v " . $volume_group . " -s " . $image_clone_name . " -m " . $disk_size . " --openqrm-cmd-mode background"; $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Running on {$vm_host_resource->ip} : {$image_clone_cmd}", "", "", 0, 0, 0); $resource->send_command($vm_host_resource->ip, $image_clone_cmd); }
function create_clone_kvm_lvm_deployment($cloud_image_id, $image_clone_name, $disk_size) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; // clone or snap cloud action $kvm_plugin_config = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/etc/openqrm-plugin-kvm.conf"; $store = openqrm_parse_conf($kvm_plugin_config); $kvm_plugin_cloud_create_volume_action = "snap"; if (isset($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'])) { if ($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'] == 'clone') { $kvm_plugin_cloud_create_volume_action = "clone"; } } // we got the cloudimage id here, get the image out of it $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0); // get image, this is already the new logical clone // we just need to physical snapshot it and update the rootdevice $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $imageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // get image storage $storage = new storage(); $storage->get_instance_by_id($imageid); $storage_resource_id = $storage->resource_id; // get deployment type $deployment = new deployment(); $deployment->get_instance_by_id($storage->type); // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // kvm-lvm-deployment $image->get_instance_by_id($image_id); // parse the volume group info in the identifier $volume_group_location = dirname($image_rootdevice); $volume_group = basename($volume_group_location); $image_location_name = basename($image_rootdevice); // set default snapshot size if (!strlen($disk_size)) { $disk_size = 5000; } // update the image rootdevice parameter $ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name); // For kvm vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a SAN backend with dedicated volumes per vm-host which all // contain all "golden-images" which are used for snapshotting. // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots // get the vm resource $vm_resource = new resource(); $vm_resource->get_instance_by_id($cloudimage->resource_id); // get the lxc host $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($vm_resource->vhostid); // san backend ? if ($vm_host_resource->id != $resource->id) { $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Image " . $image_id . " IS NOT available on this kvm host, " . $resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, 0); // update the image storage id with the vm-host-resource $image_deployment = new deployment(); $image_deployment->get_instance_by_type($image_type); // loop over all storage id from type $image_type $found_image = 0; $storage_list_by_type = new storage(); $storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id); foreach ($storage_id_list_by_type as $storage_id_list) { $storage_id = $storage_id_list['storage_id']; $tstorage = new storage(); $tstorage->get_instance_by_id($storage_id); if ($tstorage->resource_id == $vm_host_resource->id) { // re-create update array + new storage id $ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name, 'image_storageid' => $tstorage->id); $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Updating Image " . $image_id . " / " . $image_name . " with storage id " . $tstorage->id . ".", "", "", 0, 0, 0); $found_image = 1; break; } } if ($found_image == 0) { $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Could not find a storage server type " . $image_type . " using resource " . $vm_host_resource->id . ". Please create one!", "", "", 0, 0, 0); $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Not cloning image " . $image_id . ".", "", "", 0, 0, 0); return; } } else { $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Image " . $image_id . " IS available on this kvm host, " . $resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, 0); } $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Updating rootdevice of image " . $image_id . " / " . $image_name . " with /dev/" . $volume_group . "/" . $image_clone_name, "", "", 0, 0, 0); $image->update($image_id, $ar_image_update); $image_clone_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm " . $kvm_plugin_cloud_create_volume_action . " -n " . $image_location_name . " -v " . $volume_group . " -s " . $image_clone_name . " -m " . $disk_size . " -t " . $deployment->type . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Running : " . $image_clone_cmd, "", "", 0, 0, 0); $resource->send_command($vm_host_resource->ip, $image_clone_cmd); }
function openqrm_kvm_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $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; } $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); switch ($cmd) { case "start": // send command to assign image and start vm // NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans // check if resource type -> kvm-vm-net // $virtualization = new virtualization(); // $virtualization->get_instance_by_type("kvm-vm-net"); // $kvm_host_resource = new resource(); // $kvm_host_resource->get_instance_by_id($resource->vhostid); // if ($resource->vtype != $virtualization->id) { // $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm-vm reset_vlans_by_mac -b start -m $resource->mac"; // $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); // return; // } // check resource type -> kvm-vm-local $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm-vm-local"); if ($resource->vtype != $virtualization->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); return; } // check image is on the same storage server // get the kvm host resource $kvm_host_resource = new resource(); $kvm_host_resource->get_instance_by_id($resource->vhostid); // get the kvm resource $image = new image(); $image->get_instance_by_id($appliance->imageid); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $kvm_resource = new resource(); $kvm_resource->get_instance_by_id($storage->resource_id); if ($kvm_host_resource->id != $kvm_resource->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id); } $kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm start_by_mac -m " . $resource->mac . " -d " . $image->rootdevice . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password; $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); break; case "stop": // send command to stop the vm and deassign image // NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans // check if resource type -> kvm-vm-net // $virtualization = new virtualization(); // $virtualization->get_instance_by_type("kvm-vm-net"); // $kvm_host_resource = new resource(); // $kvm_host_resource->get_instance_by_id($resource->vhostid); // if ($resource->vtype != $virtualization->id) { // $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm reset_vlans_by_mac -b stop -m $resource->mac"; // $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); // return; // } // check resource type -> kvm-vm-local $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm-vm-local"); if ($resource->vtype != $virtualization->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); return; } // check image is on the same storage server // get the kvm host resource $kvm_host_resource = new resource(); $kvm_host_resource->get_instance_by_id($resource->vhostid); // get the kvm resource $image = new image(); $image->get_instance_by_id($appliance->imageid); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $kvm_resource = new resource(); $kvm_resource->get_instance_by_id($storage->resource_id); if ($kvm_host_resource->id != $kvm_resource->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id); } $kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm restart_by_mac -m " . $resource->mac . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); break; case "update": // check if the appliance was set to a kvm Host, if yes, auto-create the storage objects $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm"); if ($appliance->virtualization == $virtualization->id) { // KVM LVM Storage $deployment = new deployment(); $deployment->get_instance_by_name('kvm-lvm-deployment'); $storage = new storage(); $kvm_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_kvm = false; $found_kvm_id = -1; foreach ($kvm_id_list as $list) { foreach ($list as $kvm_id) { $storage->get_instance_by_id($kvm_id); if ($storage->resource_id == $appliance->resources) { $found_kvm = true; $found_kvm_id = $storage->id; break; } } } if (!$found_kvm) { $found_kvm_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $storage_fields['storage_id'] = $found_kvm_id; $storage_fields['storage_name'] = $appliance->name . "-lvm"; $storage_fields['storage_type'] = $deployment->id; $storage_fields['storage_comment'] = 'KVM LVM Storage Object for Appliance ' . $appliance->name; $storage_fields['storage_resource_id'] = $appliance->resources; $storage_fields['storage_capabilities'] = ''; $storage->add($storage_fields); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Created KVM LVM Storage Object for Appliance " . $appliance_id . "!", "", "", 0, 0, $appliance_id); } else { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "KVM LVM Storage Object for Appliance " . $appliance_id . " already existing.", "", "", 0, 0, $appliance_id); } // KVM Blockfile Storage $deployment = new deployment(); $deployment->get_instance_by_name('kvm-bf-deployment'); $storage = new storage(); $kvm_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_kvm = false; $found_kvm_id = -1; foreach ($kvm_id_list as $list) { foreach ($list as $kvm_id) { $storage->get_instance_by_id($kvm_id); if ($storage->resource_id == $appliance->resources) { $found_kvm = true; $found_kvm_id = $storage->id; break; } } } if (!$found_kvm) { $found_kvm_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $storage_fields['storage_id'] = $found_kvm_id; $storage_fields['storage_name'] = $appliance->name . "-bf"; $storage_fields['storage_type'] = $deployment->id; $storage_fields['storage_comment'] = 'KVM Blockfile Storage Object for Appliance ' . $appliance->name; $storage_fields['storage_resource_id'] = $appliance->resources; $storage_fields['storage_capabilities'] = ''; $storage->add($storage_fields); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Created KVM Blockfile Storage Object for Appliance " . $appliance_id . "!", "", "", 0, 0, $appliance_id); } else { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "KVM Blockfile Storage Object for Appliance " . $appliance_id . " already existing.", "", "", 0, 0, $appliance_id); } } break; } }
$drop_hybrid_cloud_table = "drop table hybrid_cloud_accounts"; $db = openqrm_get_db_connection(); $recordSet = $db->Execute($drop_hybrid_cloud_table); $db->Close(); // remove Cloud Host Server and Storage $virtualization = new virtualization(); $virtualization->get_instance_by_type("hybrid-cloud"); $appliance = new appliance(); $appliance->get_instance_by_virtualization_and_resource($virtualization->id, '0'); if (strlen($appliance->id)) { $appliance->remove($appliance->id); } $deployment = new deployment(); $deployment->get_instance_by_name('ami-deployment'); $storage = new storage(); $hc_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_hc = false; $found_hc_id = -1; foreach ($hc_id_list as $list) { foreach ($list as $hc_id) { $storage->get_instance_by_id($hc_id); if ($storage->resource_id == 0) { $found_hc = true; $found_hc_id = $storage->id; break; } } } if ($found_hc) { // remove all AMI Images, then the storage $image = new image();
function create_clone_kvm_bf_deployment($cloud_image_id, $image_clone_name, $disk_size) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; // we got the cloudimage id here, get the image out of it $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0); // get image, this is already the new logical clone // we just need to physical snapshot it and update the rootdevice $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $imageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // get image storage $storage = new storage(); $storage->get_instance_by_id($imageid); $storage_resource_id = $storage->resource_id; // get deployment type $deployment = new deployment(); $deployment->get_instance_by_id($storage->type); // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // kvm-bf-deployment $image->get_instance_by_id($image_id); // parse the identifiers // origin image volume name $origin_volume_name = basename($image_rootdevice); // location of the volume (path) $image_location_name = dirname($image_rootdevice); // set default snapshot size if (!strlen($disk_size)) { $disk_size = 5000; } // update the image rootdevice parameter $ar_image_update = array('image_rootdevice' => $image_location_name . "/" . $image_clone_name); // For kvm vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a NAS/Glusterfs backend with all volumes accessible for all hosts // get the vm resource $vm_resource = new resource(); $vm_resource->get_instance_by_id($cloudimage->resource_id); // get the lxc host $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($vm_resource->vhostid); // san backend ? if ($vm_host_resource->id != $resource->id) { $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS NOT available on this kvm host, " . $resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, 0); // update the image storage id with the vm-host-resource $image_deployment = new deployment(); $image_deployment->get_instance_by_type($image_type); // loop over all storage id from type $image_type $found_image = 0; $storage_list_by_type = new storage(); $storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id); foreach ($storage_id_list_by_type as $storage_id_list) { $storage_id = $storage_id_list['storage_id']; $tstorage = new storage(); $tstorage->get_instance_by_id($storage_id); if ($tstorage->resource_id == $vm_host_resource->id) { // re-create update array + new storage id $ar_image_update = array('image_rootdevice' => $image_location_name . "/" . $image_clone_name, 'image_storageid' => $tstorage->id); $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Updating Image " . $image_id . " / " . $image_name . " with storage id " . $tstorage->id . ".", "", "", 0, 0, 0); $found_image = 1; break; } } if ($found_image == 0) { $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-bf-deployment-cloud-hook.php", "SETUP ERROR: Could not find a storage server type " . $image_type . " using resource " . $vm_host_resource->id . ". Please create one!", "", "", 0, 0, 0); $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-bf-deployment-cloud-hook.php", "SETUP ERROR: Not cloning image " . $image_id . ".", "", "", 0, 0, 0); return; } } else { $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS available on this kvm host, " . $resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, 0); } $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Updating rootdevice of image " . $image_id . " / " . $image_name . " with " . $image_location_name . "/" . $image_clone_name, "", "", 0, 0, 0); $image->update($image_id, $ar_image_update); $image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm snap -n " . $origin_volume_name . " -v " . $image_location_name . " -s " . $image_clone_name . " -m " . $disk_size . " -t " . $deployment->type . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Running : " . $image_clone_cmd, "", "", 0, 0, 0); $resource->send_command($vm_host_resource->ip, $image_clone_cmd); }
function get_response() { $response = $this->response; $form = $response->get_form($this->actions_name, 'install1'); $id = $this->response->html->request()->get('image_id'); $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'); $image = new image(); $image->get_instance_by_id($id); $storage = new storage(); $deployment = new deployment(); $install_template_type = $this->response->html->request()->get('install_from_template'); if (strlen($install_template_type)) { $deployment->get_instance_by_type($install_template_type); $storage_select_arr = $storage->get_ids_by_storage_type($deployment->id); } else { $storage_select_arr = array(); } $storage_select = array(); foreach ($storage_select_arr as $storage_db) { $storage_id = $storage_db['storage_id']; $storage->get_instance_by_id($storage_id); $storage_select[] = array("value" => $storage_id, "label" => $storage_id . " - " . $storage->name); } $d['install_server']['label'] = $this->lang['form_install_server']; $d['install_server']['required'] = true; $d['install_server']['object']['type'] = 'htmlobject_select'; $d['install_server']['object']['attrib']['index'] = array('value', 'label'); $d['install_server']['object']['attrib']['id'] = 'install_server'; $d['install_server']['object']['attrib']['name'] = 'install_server'; $d['install_server']['object']['attrib']['options'] = $storage_select; $form->add($d); $response->form = $form; return $response; }