Skip to content

Commit

Permalink
Feature 4823 (#185)
Browse files Browse the repository at this point in the history
* F#2921 Fix DISKIO info. Accumulate values and ignore negative values for vCenter

* F#4823 Add option to specify vCenter VM folder
  • Loading branch information
n40lab authored and tinova committed Jan 20, 2017
1 parent fd8158f commit f904fdd
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 8 deletions.
3 changes: 2 additions & 1 deletion share/doc/xsd/oned.conf
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ IM_MAD = [ NAME="dummy", SUNSTONE_NAME="Testing", EXECUTABLE="one_im_dummy"]
#
# type : driver type, supported drivers: xen, kvm, xml
#
# keep_snapshots: do not remove snapshots on power on/off cycles and live
# keep_snapshots: do not remove snapshots on power on/off cycles and live
# migrations if the hypervisor supports that.
#
# imported_vms_actions : comma-separated list of actions supported
Expand Down Expand Up @@ -770,6 +770,7 @@ VM_RESTRICTED_ATTR = "MEMORY_COST"
VM_RESTRICTED_ATTR = "DISK_COST"
VM_RESTRICTED_ATTR = "PCI"
VM_RESTRICTED_ATTR = "USER_INPUTS"
VM_RESTRICTED_ATTR = "DEPLOY_FOLDER"

#VM_RESTRICTED_ATTR = "RANK"
#VM_RESTRICTED_ATTR = "SCHED_RANK"
Expand Down
1 change: 1 addition & 0 deletions share/etc/oned.conf
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ VM_RESTRICTED_ATTR = "EMULATOR"
VM_RESTRICTED_ATTR = "USER_INPUTS/CPU"
VM_RESTRICTED_ATTR = "USER_INPUTS/MEMORY"
VM_RESTRICTED_ATTR = "USER_INPUTS/VCPU"
VM_RESTRICTED_ATTR = "DEPLOY_FOLDER"

#VM_RESTRICTED_ATTR = "RANK"
#VM_RESTRICTED_ATTR = "SCHED_RANK"
Expand Down
9 changes: 9 additions & 0 deletions src/cli/one_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ module OpenNebulaHelper
:name => 'report_ready',
:large => '--report_ready',
:description => 'Sends READY=YES to OneGate, useful for OneFlow'
},
{
:name => 'deploy_folder',
:large => '--deploy_folder path',
:format => String,
:description => "In a vCenter environment sets the the VMs and Template folder where the VM will be placed in." \
" The path uses slashes to separate folders. For example: --deploy_folder \"/Management/VMs\""
}
]

Expand Down Expand Up @@ -1126,6 +1133,8 @@ def self.create_template(options, template_obj=nil)
template<<' ]' << "\n"
end
template<<"DEPLOY_FOLDER=#{options[:deploy_folder]}\n" if options[:deploy_folder]
context=create_context(options)
template<<context if context
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/etc/sunstone-views/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ features:
# will be set to the same value as VCPU, that will still be visible for the
# end users
instantiate_hide_cpu: false

# True to show an input to specify the the VMs and Template path/folder where a vCenter VM will
# deployed to
vcenter_deploy_folder: false
tabs:
dashboard-tab:
# The following widgets can be used inside any of the '_per_row' settings
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/etc/sunstone-views/admin_vcenter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ features:
# will be set to the same value as VCPU, that will still be visible for the
# end users
instantiate_hide_cpu: false

# True to show an input to specify the the VMs and Template path/folder where a vCenter VM will
# deployed to
vcenter_deploy_folder: true
tabs:
dashboard-tab:
# The following widgets can be used inside any of the '_per_row' settings
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/etc/sunstone-views/groupadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ features:
# will be set to the same value as VCPU, that will still be visible for the
# end users
instantiate_hide_cpu: false

# True to show an input to specify the the VMs and Template path/folder where a vCenter VM will
# deployed to
vcenter_deploy_folder: false
tabs:
dashboard-tab:
# The following widgets can be used inside any of the '_per_row' settings
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/etc/sunstone-views/groupadmin_vcenter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ features:
# will be set to the same value as VCPU, that will still be visible for the
# end users
instantiate_hide_cpu: true

# True to show an input to specify the the VMs and Template path/folder where a vCenter VM will
# deployed to
vcenter_deploy_folder: false
tabs:
dashboard-tab:
# The following widgets can be used inside any of the '_per_row' settings
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/etc/sunstone-views/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ features:
# will be set to the same value as VCPU, that will still be visible for the
# end users
instantiate_hide_cpu: false

# True to show an input to specify the the VMs and Template path/folder where a vCenter VM will
# deployed to
vcenter_deploy_folder: false
tabs:
dashboard-tab:
# The following widgets can be used inside any of the '_per_row' settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ define(function(require) {
memory *= 1024;
memory = memory * 24 * 30; //24 hours and 30 days
document.getElementById('total_value_memory').textContent = convertCostNumber(memory);
$(".total_memory_cost", context).show();
$(".total_memory_cost", context).show();
}

function _setup(context) {
Expand All @@ -137,14 +137,14 @@ define(function(require) {
context.on("change", "#CPU_COST", function() {
var cpu = document.getElementById('CPU_COST').value;
document.getElementById('total_value_cpu').textContent = convertCostNumber(cpu * 24 * 30);
$(".total_cpu_cost", context).show();
$(".total_cpu_cost", context).show();
CapacityCreate.calculatedRealCpu();
});

context.on("change", "#DISK_COST", function() {
var disk = document.getElementById('DISK_COST').value;
document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 1024 * 24 * 30);
$(".total_disk_cost", context).show();
$(".total_disk_cost", context).show();
});

context.on("change", "#LOGO", function() {
Expand Down Expand Up @@ -187,6 +187,9 @@ define(function(require) {
'VM_TEMPLATE': WizardFields.retrieveInput($("#vcenter_template_uuid", context))
};

if (Config.isFeatureEnabled("vcenter_deploy_folder")) {
templateJSON["DEPLOY_FOLDER"] = WizardFields.retrieveInput($("#vcenter_deploy_folder", context))
}
templateJSON["KEEP_DISKS_ON_DONE"] = $("#KEEP_DISKS", context).is(':checked')?"YES":"NO"
}

Expand All @@ -201,7 +204,7 @@ define(function(require) {
}

var userInputs = {};

// Retrieve Datastore Attribute
var dsInput = $(".vcenter_datastore_input", context);
if (dsInput.length > 0) {
Expand Down Expand Up @@ -275,6 +278,17 @@ define(function(require) {

delete templateJSON["KEEP_DISKS_ON_DONE"];

if (Config.isFeatureEnabled("vcenter_deploy_folder")) {
if (templateJSON["HYPERVISOR"] == 'vcenter' &&
templateJSON["DEPLOY_FOLDER"]) {
WizardFields.fillInput($("#vcenter_deploy_folder", context), templateJSON["DEPLOY_FOLDER"]);
}
} else {
$(".vcenter_deploy_folder_input", context).remove();
}

delete templateJSON["DEPLOY_FOLDER"];

if (templateJSON["HYPERVISOR"] == 'vcenter') {
var publicClouds = templateJSON["PUBLIC_CLOUD"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@
</label>
</div>
</div>
<div class="vcenter_deploy_folder_input row">
<div class="medium-6 columns">
<label for="vcenter_deploy_folder">
{{tr "Deployment Folder"}}
{{{tip (tr "If specified, the the VMs and Template folder path where the VM will be created inside the data center. The path is delimited by slashes e.g /Management/VMs. If no path is set the VM will be deployed in the same folder where the template exists.")}}}
</label>
<input type="text" id="vcenter_deploy_folder"/>
</div>
</div>
</fieldset>
<div class="row">
<div class="capacityCreate large-12 columns">{{{capacityCreateHTML}}}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define(function(require) {
var WizardFields = require('utils/wizard-fields');
var DisksResize = require('utils/disks-resize');
var NicsSection = require('utils/nics-section');
var DeployFolder = require('utils/deploy-folder');
var CapacityInputs = require('tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs');
var Config = require('sunstone-config');

Expand Down Expand Up @@ -206,6 +207,13 @@ define(function(require) {
tmp_json.PCI = pcis;
}

if (Config.isFeatureEnabled("vcenter_deploy_folder")){
if(!$.isEmptyObject(original_tmpl.TEMPLATE.PUBLIC_CLOUD.TYPE) &&
original_tmpl.TEMPLATE.PUBLIC_CLOUD.TYPE === 'vcenter'){
$.extend(tmp_json, DeployFolder.retrieveChanges($(".deployFolderContext" + template_id)));
}
}

capacityContext = $(".capacityContext" + template_id, context);
$.extend(tmp_json, CapacityInputs.retrieveChanges(capacityContext));

Expand Down Expand Up @@ -262,6 +270,10 @@ define(function(require) {
'securityGroups': Config.isFeatureEnabled("secgroups")
});

deployFolderContext = $(".deployFolderContext" + template_json.VMTEMPLATE.ID, context);
DeployFolder.setup(deployFolderContext);
DeployFolder.fill(deployFolderContext, template_json.VMTEMPLATE);

var inputs_div = $(".template_user_inputs" + template_json.VMTEMPLATE.ID, context);

UserInputs.vmTemplateInsert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
</div>
</div>
</div>
<div class="row">
<div class="medium-6 small-12 columns deployFolderContext{{element.ID}}">
<div class="provision_deploy_folder_selector">
</div>
</div>
</div>
</div>
74 changes: 74 additions & 0 deletions src/sunstone/public/app/utils/deploy-folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */

define(function(require){
var Locale = require('utils/locale');
var Config = require('sunstone-config');
var OpenNebula = require('opennebula');
var OpenNebulaImage = require('opennebula/image');
var UserInputs = require('utils/user-inputs');
var WizardFields = require('utils/wizard-fields');
var DeployFolderTemplate = require('hbs!./deploy-folder/html');

return {
'setup': _setup,
'fill': _fill,
'retrieveChanges': _retrieveChanges
};

function _setup(context) {
if (!Config.isFeatureEnabled("vcenter_deploy_folder")){
$(context).remove();
}
}

function _fill(context, element) {

if (Config.isFeatureEnabled("vcenter_deploy_folder")){
var deployFolderContext = context;
var template_public_cloud_type = element.TEMPLATE.PUBLIC_CLOUD.TYPE

if ($.isEmptyObject(template_public_cloud_type)) {
deployFolderContext.html("");
} else {
if (template_public_cloud_type === 'vcenter') {
var deploy_folder = element.TEMPLATE.DEPLOY_FOLDER
deployFolderContext.html(DeployFolderTemplate());
$("#deploy_folder_input", deployFolderContext).val(deploy_folder);
$("#deploy_folder_input", deployFolderContext).data("original_value",deploy_folder);
} else {
deployFolderContext.html("");
}
}
}
}


function _retrieveChanges(context) {

var templateJSON = WizardFields.retrieve(context);
var fields = $('[wizard_field]', context);

fields.each(function() {
var field_name = $(this).attr('wizard_field');
if (templateJSON[field_name] == $(this).data("original_value")){
delete templateJSON[field_name];
}
});

return templateJSON;
}
});
29 changes: 29 additions & 0 deletions src/sunstone/public/app/utils/deploy-folder/html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{! -------------------------------------------------------------------------- }}
{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }}
{{! }}
{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }}
{{! not use this file except in compliance with the License. You may obtain }}
{{! a copy of the License at }}
{{! }}
{{! http://www.apache.org/licenses/LICENSE-2.0 }}
{{! }}
{{! Unless required by applicable law or agreed to in writing, software }}
{{! distributed under the License is distributed on an "AS IS" BASIS, }}
{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }}
{{! See the License for the specific language governing permissions and }}
{{! limitations under the License. }}
{{! -------------------------------------------------------------------------- }}

<fieldset>
<legend>
<i class="fa fa-folder"></i> {{tr "vCenter Deployment"}}
</legend>
<div class="deployContainer">
<label for="deploy_folder_input">
{{tr "Deployment Folder"}}
{{{tip (tr "If specified, the VMs and Template folder path where the VM will be created inside the data center. The path is delimited by slashes e.g /Management/VMs. If no path is set the VM will be deployed in the same folder where the template exists.")}}}
</label>
<input type="text" name="deploy_folder_input" id="deploy_folder_input" wizard_field="DEPLOY_FOLDER"/>
</div>
</fieldset>

21 changes: 18 additions & 3 deletions src/vmm_mad/remotes/vcenter/vcenter_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,21 @@ def self.clone_vm(xml_text, hostname, datastore, ops = {})
connection = VIClient.new(hid)
vc_template = connection.find_vm_fast(uuid, ops[:ref], ops[:name])

deploy_folder = nil
deploy_folder_name = xml.root.elements["/VM/USER_TEMPLATE/DEPLOY_FOLDER"]

if !deploy_folder_name.nil?
deploy_folder_name = deploy_folder_name.text
if !deploy_folder_name.empty?
# Look for folder object
deploy_folder = connection.dc.find_folder(deploy_folder_name)
end
end

if deploy_folder.nil?
deploy_folder = vc_template.parent
end

# Find out requested and available resource pool

req_rp = nil
Expand Down Expand Up @@ -2598,7 +2613,7 @@ def self.clone_vm(xml_text, hostname, datastore, ops = {})
storage_spec = RbVmomi::VIM.StoragePlacementSpec(
type: 'clone',
cloneName: vcenter_name,
folder: vc_template.parent,
folder: deploy_folder,
podSelectionSpec: pod_spec,
vm: vc_template,
cloneSpec: clone_spec
Expand All @@ -2624,7 +2639,7 @@ def self.clone_vm(xml_text, hostname, datastore, ops = {})

begin
vm = vc_template.CloneVM_Task(
:folder => vc_template.parent,
:folder => deploy_folder,
:name => vcenter_name,
:spec => clone_spec).wait_for_completion
rescue Exception => e
Expand All @@ -2639,7 +2654,7 @@ def self.clone_vm(xml_text, hostname, datastore, ops = {})

vm.Destroy_Task.wait_for_completion
vm = vc_template.CloneVM_Task(
:folder => vc_template.parent,
:folder => deploy_folder,
:name => vcenter_name,
:spec => clone_spec).wait_for_completion
end
Expand Down

0 comments on commit f904fdd

Please sign in to comment.