rafaelweingartner closed pull request #2437: [CLOUDSTACK-10257]Create 
template/volume does not allow to specify HVM requirements
URL: https://github.com/apache/cloudstack/pull/2437
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index 606fed45d27..923ab76b5bf 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -2622,3 +2622,186 @@ $.validator.addMethod("allzonesonly", function(value, 
element){
 
 },
 "All Zones cannot be combined with any other zone");
+
+cloudStack.createTemplateMethod = function (isSnapshot){
+       return {
+        label: 'label.create.template',
+        messages: {
+            confirm: function(args) {
+                return 'message.create.template';
+            },
+            notification: function(args) {
+                return 'label.create.template';
+            }
+        },
+        createForm: {
+            title: 'label.create.template',
+            preFilter: cloudStack.preFilter.createTemplate,
+            desc: '',
+            preFilter: function(args) {
+                if (args.context.volumes[0].hypervisor == "XenServer") {
+                    if (isAdmin()) {
+                        
args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').css('display', 
'inline-block');
+                    }
+                }
+            },
+            fields: {
+                name: {
+                    label: 'label.name',
+                    validation: {
+                        required: true
+                    }
+                },
+                displayText: {
+                    label: 'label.description',
+                    validation: {
+                        required: true
+                    }
+                },
+                xenserverToolsVersion61plus: {
+                    label: 'label.xenserver.tools.version.61.plus',
+                    isBoolean: true,
+                    isChecked: function (args) {
+                        var b = false;
+                        var vmObj;
+                        $.ajax({
+                            url: createURL("listVirtualMachines"),
+                            data: {
+                                id: args.context.volumes[0].virtualmachineid
+                            },
+                            async: false,
+                            success: function(json) {
+                                vmObj = 
json.listvirtualmachinesresponse.virtualmachine[0];
+                            }
+                        });
+                        if (vmObj == undefined) { //e.g. VM has failed over
+                            if (isAdmin()) {
+                                $.ajax({
+                                    url: createURL('listConfigurations'),
+                                    data: {
+                                        name: 'xenserver.pvdriver.version'
+                                    },
+                                    async: false,
+                                    success: function (json) {
+                                        if 
(json.listconfigurationsresponse.configuration != null && 
json.listconfigurationsresponse.configuration[0].value == 'xenserver61') {
+                                            b = true;
+                                        }
+                                    }
+                                });
+                            }
+                        } else {
+                             if ('details' in vmObj && 
'hypervisortoolsversion' in vmObj.details) {
+                                 if (vmObj.details.hypervisortoolsversion == 
'xenserver61')
+                                     b = true;
+                                 else
+                                     b = false;
+                             }
+                        }
+                        return b;
+                    },
+                    isHidden: true
+                },
+                osTypeId: {
+                    label: 'label.os.type',
+                    select: function(args) {
+                        $.ajax({
+                            url: createURL("listOsTypes"),
+                            dataType: "json",
+                            async: true,
+                            success: function(json) {
+                                var ostypes = json.listostypesresponse.ostype;
+                                var items = [];
+                                $(ostypes).each(function() {
+                                    items.push({
+                                        id: this.id,
+                                        description: this.description
+                                    });
+                                });
+                                args.response.success({
+                                    data: items
+                                });
+                            }
+                        });
+                    }
+                },
+                isPublic: {
+                    label: 'label.public',
+                    isBoolean: true
+                },
+                isPasswordEnabled: {
+                    label: 'label.password.enabled',
+                    isBoolean: true
+                },
+                isFeatured: {
+                    label: 'label.featured',
+                    isBoolean: true
+                },
+                isdynamicallyscalable: {
+                    label: 'label.dynamically.scalable',
+                    isBoolean: true
+                },
+                requireshvm: {
+                    label: 'label.hvm',
+                    docID: 'helpRegisterTemplateHvm',
+                    isBoolean: true,
+                    isHidden: false,
+                    isChecked: false
+                }
+            }
+        },
+        action: function(args) {
+            var data = {
+                name: args.data.name,
+                displayText: args.data.displayText,
+                osTypeId: args.data.osTypeId,
+                isPublic: (args.data.isPublic == "on"),
+                passwordEnabled: (args.data.isPasswordEnabled == "on"),
+                isdynamicallyscalable: (args.data.isdynamicallyscalable == 
"on"),
+                requireshvm: (args.data.requireshvm == "on")
+            };
+            
+            if(isSnapshot){
+               data.snapshotid = args.context.snapshots[0].id;
+            } else{
+               data.volumeId = args.context.volumes[0].id;
+            }
+            if (args.$form.find('.form-item[rel=isFeatured]').css("display") 
!= "none") {
+                $.extend(data, {
+                    isfeatured: (args.data.isFeatured == "on")
+                });
+            }
+
+            //XenServer only (starts here)
+            if 
(args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').length > 0) {
+                if 
(args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').css("display") 
!= "none") {
+                    $.extend(data, {
+                        'details[0].hypervisortoolsversion': 
(args.data.xenserverToolsVersion61plus == "on") ? "xenserver61" : "xenserver56"
+                    });
+                }
+            }
+            //XenServer only (ends here)
+
+            $.ajax({
+                url: createURL('createTemplate'),
+                data: data,
+                success: function(json) {
+                    var jid = json.createtemplateresponse.jobid;
+                    args.response.success({
+                        _custom: {
+                            jobId: jid,
+                            getUpdatedItem: function(json) {
+                                return {}; //no properties in this volume 
needs to be updated
+                            },
+                            getActionFilter: function() {
+                                return volumeActionfilter;
+                            }
+                        }
+                    });
+                }
+            });
+        },
+        notification: {
+            poll: pollAsyncJobResult
+        }
+    };
+};
\ No newline at end of file
diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js
index 1cba7505491..4a2f053382a 100644
--- a/ui/scripts/storage.js
+++ b/ui/scripts/storage.js
@@ -1302,175 +1302,8 @@
                                 }
                             },
 
-                            createTemplate: {
-                                label: 'label.create.template',
-                                messages: {
-                                    confirm: function(args) {
-                                        return 'message.create.template';
-                                    },
-                                    notification: function(args) {
-                                        return 'label.create.template';
-                                    }
-                                },
-                                createForm: {
-                                    title: 'label.create.template',
-                                    preFilter: 
cloudStack.preFilter.createTemplate,
-                                    desc: '',
-                                    preFilter: function(args) {
-                                        if (args.context.volumes[0].hypervisor 
== "XenServer") {
-                                            
args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').css('display', 
'inline-block');
-
-                                        }
-                                    },
-                                    fields: {
-                                        name: {
-                                            label: 'label.name',
-                                            validation: {
-                                                required: true
-                                            }
-                                        },
-                                        displayText: {
-                                            label: 'label.description',
-                                            validation: {
-                                                required: true
-                                            }
-                                        },
-                                        xenserverToolsVersion61plus: {
-                                            label: 
'label.xenserver.tools.version.61.plus',
-                                            isBoolean: true,
-                                            isChecked: function (args) {
-                                                var b = false;
-                                                var vmObj;
-                                                $.ajax({
-                                                    url: 
createURL("listVirtualMachines"),
-                                                    data: {
-                                                        id: 
args.context.volumes[0].virtualmachineid
-                                                    },
-                                                    async: false,
-                                                    success: function(json) {
-                                                        vmObj = 
json.listvirtualmachinesresponse.virtualmachine[0];
-                                                    }
-                                                });
-                                                if (vmObj == undefined) { 
//e.g. VM has failed over
-                                                    if (isAdmin()) {
-                                                        $.ajax({
-                                                            url: 
createURL('listConfigurations'),
-                                                            data: {
-                                                                name: 
'xenserver.pvdriver.version'
-                                                            },
-                                                            async: false,
-                                                            success: function 
(json) {
-                                                                if 
(json.listconfigurationsresponse.configuration != null && 
json.listconfigurationsresponse.configuration[0].value == 'xenserver61') {
-                                                                    b = true;
-                                                                }
-                                                            }
-                                                        });
-                                                    }
-                                                } else {
-                                                     if ('details' in vmObj && 
'hypervisortoolsversion' in vmObj.details) {
-                                                         if 
(vmObj.details.hypervisortoolsversion == 'xenserver61')
-                                                             b = true;
-                                                         else
-                                                             b = false;
-                                                     }
-                                                }
-                                                return b;
-                                            },
-                                            isHidden: true
-                                        },
-                                        osTypeId: {
-                                            label: 'label.os.type',
-                                            select: function(args) {
-                                                $.ajax({
-                                                    url: 
createURL("listOsTypes"),
-                                                    dataType: "json",
-                                                    async: true,
-                                                    success: function(json) {
-                                                        var ostypes = 
json.listostypesresponse.ostype;
-                                                        var items = [];
-                                                        
$(ostypes).each(function() {
-                                                            items.push({
-                                                                id: this.id,
-                                                                description: 
this.description
-                                                            });
-                                                        });
-                                                        args.response.success({
-                                                            data: items
-                                                        });
-                                                    }
-                                                });
-                                            }
-                                        },
-                                        isPublic: {
-                                            label: 'label.public',
-                                            isBoolean: true
-                                        },
-                                        isPasswordEnabled: {
-                                            label: 'label.password.enabled',
-                                            isBoolean: true
-                                        },
-                                        isFeatured: {
-                                            label: 'label.featured',
-                                            isBoolean: true
-                                        },
-                                        isdynamicallyscalable: {
-                                            label: 
'label.dynamically.scalable',
-                                            isBoolean: true
-                                        }
-                                    }
-                                },
-                                action: function(args) {
-                                    var data = {
-                                        volumeId: args.context.volumes[0].id,
-                                        name: args.data.name,
-                                        displayText: args.data.displayText,
-                                        osTypeId: args.data.osTypeId,
-                                        isPublic: (args.data.isPublic == "on"),
-                                        passwordEnabled: 
(args.data.isPasswordEnabled == "on"),
-                                        isdynamicallyscalable: 
(args.data.isdynamicallyscalable == "on")
-
-                                    };
-
-                                    if 
(args.$form.find('.form-item[rel=isFeatured]').css("display") != "none") {
-                                        $.extend(data, {
-                                            isfeatured: (args.data.isFeatured 
== "on")
-                                        });
-                                    }
-
-                                    //XenServer only (starts here)
-                                    if 
(args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').length > 0) {
-                                        if 
(args.$form.find('.form-item[rel=xenserverToolsVersion61plus]').css("display") 
!= "none") {
-                                            $.extend(data, {
-                                                
'details[0].hypervisortoolsversion': (args.data.xenserverToolsVersion61plus == 
"on") ? "xenserver61" : "xenserver56"
-                                            });
-                                        }
-                                    }
-                                    //XenServer only (ends here)
-
-                                    $.ajax({
-                                        url: createURL('createTemplate'),
-                                        data: data,
-                                        success: function(json) {
-                                            var jid = 
json.createtemplateresponse.jobid;
-                                            args.response.success({
-                                                _custom: {
-                                                    jobId: jid,
-                                                    getUpdatedItem: 
function(json) {
-                                                        return {}; //no 
properties in this volume needs to be updated
-                                                    },
-                                                    getActionFilter: 
function() {
-                                                        return 
volumeActionfilter;
-                                                    }
-                                                }
-                                            });
-                                        }
-                                    });
-                                },
-                                notification: {
-                                    poll: pollAsyncJobResult
-                                }
-                            },
-
+                            createTemplate: 
cloudStack.createTemplateMethod(false),
+                            
                             migrateToAnotherStorage: {
                                 label: 
'label.migrate.volume.to.primary.storage',
                                 messages: {
@@ -2102,103 +1935,7 @@
                     detailView: {
                         name: 'Snapshot detail',
                         actions: {
-                            createTemplate: {
-                                label: 'label.create.template',
-                                messages: {
-                                    confirm: function(args) {
-                                        return 'message.create.template';
-                                    },
-                                    notification: function(args) {
-                                        return 'label.create.template';
-                                    }
-                                },
-                                createForm: {
-                                    title: 'label.create.template',
-                                    desc: '',
-                                    fields: {
-                                        name: {
-                                            label: 'label.name',
-                                            validation: {
-                                                required: true
-                                            }
-                                        },
-                                        displayText: {
-                                            label: 'label.description',
-                                            validation: {
-                                                required: true
-                                            }
-                                        },
-                                        osTypeId: {
-                                            label: 'label.os.type',
-                                            select: function(args) {
-                                                $.ajax({
-                                                    url: 
createURL("listOsTypes"),
-                                                    dataType: "json",
-                                                    async: true,
-                                                    success: function(json) {
-                                                        var ostypes = 
json.listostypesresponse.ostype;
-                                                        var items = [];
-                                                        
$(ostypes).each(function() {
-                                                            items.push({
-                                                                id: this.id,
-                                                                description: 
this.description
-                                                            });
-                                                        });
-                                                        args.response.success({
-                                                            data: items
-                                                        });
-                                                    }
-                                                });
-                                            }
-                                        },
-                                        isPublic: {
-                                            label: 'label.public',
-                                            isBoolean: true
-                                        },
-                                        isPasswordEnabled: {
-                                            label: 'label.password.enabled',
-                                            isBoolean: true
-                                        },
-                                        isdynamicallyscalable: {
-                                            label: 
'label.dynamically.scalable',
-                                            isBoolean: true
-                                        }
-                                    }
-                                },
-                                action: function(args) {
-                                    var data = {
-                                        snapshotid: 
args.context.snapshots[0].id,
-                                        name: args.data.name,
-                                        displayText: args.data.displayText,
-                                        osTypeId: args.data.osTypeId,
-                                        isPublic: (args.data.isPublic == "on"),
-                                        passwordEnabled: 
(args.data.isPasswordEnabled == "on"),
-                                        isdynamicallyscalable: 
(args.data.isdynamicallyscalable == "on")
-                                    };
-
-                                    $.ajax({
-                                        url: createURL('createTemplate'),
-                                        data: data,
-                                        success: function(json) {
-                                            var jid = 
json.createtemplateresponse.jobid;
-                                            args.response.success({
-                                                _custom: {
-                                                    jobId: jid,
-                                                    getUpdatedItem: 
function(json) {
-                                                        return {}; //nothing 
in this snapshot needs to be updated
-                                                    },
-                                                    getActionFilter: 
function() {
-                                                        return 
snapshotActionfilter;
-                                                    }
-                                                }
-                                            });
-                                        }
-                                    });
-                                },
-                                notification: {
-                                    poll: pollAsyncJobResult
-                                }
-                            },
+                            createTemplate: 
cloudStack.createTemplateMethod(true),
 
                             createVolume: {
                                 label: 'label.action.create.volume',


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to