cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sw...@apache.org
Subject [2/9] git commit: updated refs/heads/master to 143265c
Date Thu, 12 May 2016 15:06:51 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/ui/dictionary.jsp
----------------------------------------------------------------------
diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp
index ddcd181..b064299 100644
--- a/ui/dictionary.jsp
+++ b/ui/dictionary.jsp
@@ -871,6 +871,7 @@ dictionary = {
 'label.metrics.property': '<fmt:message key="label.metrics.property" />',
 'label.metrics.scope': '<fmt:message key="label.metrics.scope" />',
 'label.metrics.state': '<fmt:message key="label.metrics.state" />',
+'label.metrics.outofbandmanagementpowerstate': '<fmt:message key="label.metrics.outofbandmanagementpowerstate" />',
 'label.metrics.storagepool': '<fmt:message key="label.metrics.storagepool" />',
 'label.metrics.vm.name': '<fmt:message key="label.metrics.vm.name" />',
 'label.migrate.instance.to': '<fmt:message key="label.migrate.instance.to" />',
@@ -987,6 +988,26 @@ dictionary = {
 'label.port.forwarding': '<fmt:message key="label.port.forwarding" />',
 'label.port.forwarding.policies': '<fmt:message key="label.port.forwarding.policies" />',
 'label.port.range': '<fmt:message key="label.port.range" />',
+'label.powerstate': '<fmt:message key="label.powerstate" />',
+'label.outofbandmanagement': '<fmt:message key="label.outofbandmanagement" />',
+'label.outofbandmanagement.action.issue': '<fmt:message key="label.outofbandmanagement.action.issue" />',
+'label.outofbandmanagement.action': '<fmt:message key="label.outofbandmanagement.action" />',
+'label.outofbandmanagement.address': '<fmt:message key="label.outofbandmanagement.address" />',
+'label.outofbandmanagement.changepassword': '<fmt:message key="label.outofbandmanagement.changepassword" />',
+'label.outofbandmanagement.configure': '<fmt:message key="label.outofbandmanagement.configure" />',
+'label.outofbandmanagement.driver': '<fmt:message key="label.outofbandmanagement.driver" />',
+'label.outofbandmanagement.disable': '<fmt:message key="label.outofbandmanagement.disable" />',
+'label.outofbandmanagement.enable': '<fmt:message key="label.outofbandmanagement.enable" />',
+'label.outofbandmanagement.password': '<fmt:message key="label.outofbandmanagement.password" />',
+'label.outofbandmanagement.port': '<fmt:message key="label.outofbandmanagement.port" />',
+'label.outofbandmanagement.timeout': '<fmt:message key="label.outofbandmanagement.timeout" />',
+'label.outofbandmanagement.username': '<fmt:message key="label.outofbandmanagement.username" />',
+'message.outofbandmanagement.changepassword': '<fmt:message key="message.outofbandmanagement.changepassword" />',
+'message.outofbandmanagement.configure': '<fmt:message key="message.outofbandmanagement.configure" />',
+'message.outofbandmanagement.disable': '<fmt:message key="message.outofbandmanagement.disable" />',
+'message.outofbandmanagement.enable': '<fmt:message key="message.outofbandmanagement.enable" />',
+'message.outofbandmanagement.issue': '<fmt:message key="message.outofbandmanagement.issue" />',
+'message.outofbandmanagement.action.maintenance': '<fmt:message key="message.outofbandmanagement.action.maintenance" />',
 'label.PreSetup': '<fmt:message key="label.PreSetup" />',
 'label.prev': '<fmt:message key="label.prev" />',
 'label.previous': '<fmt:message key="label.previous" />',

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/ui/scripts/metrics.js
----------------------------------------------------------------------
diff --git a/ui/scripts/metrics.js b/ui/scripts/metrics.js
index e7b9df8..46d6b53 100644
--- a/ui/scripts/metrics.js
+++ b/ui/scripts/metrics.js
@@ -550,6 +550,19 @@
                     },
                     compact: true
                 },
+                outofbandmanagementpowerstate: {
+                    label: 'label.metrics.outofbandmanagementpowerstate',
+                    converter: function (str) {
+                        // For localization
+                        return str;
+                    },
+                    indicator: {
+                        'On': 'on',
+                        'Off': 'off',
+                        'Unknown': 'warning'
+                    },
+                    compact: true
+                },
                 instances: {
                     label: 'label.instances'
                 },
@@ -633,6 +646,9 @@
                         var items = json.listhostsresponse.host;
                         if (items) {
                             $.each(items, function(idx, host) {
+                                if (host && host.outofbandmanagement) {
+                                    items[idx].outofbandmanagementpowerstate = host.outofbandmanagement.powerstate;
+                                }
                                 items[idx].cores = host.cpunumber;
                                 items[idx].cputotal = (parseFloat(host.cpunumber) * parseFloat(host.cpuspeed) / 1000.0).toFixed(2);
                                 if (host.cpuused) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index 4cb8094..1d60c12 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -8241,6 +8241,82 @@
                                                 }
                                             });
                                         }
+                                    },
+                                    enableOutOfBandManagement: {
+                                        label: 'label.outofbandmanagement.enable',
+                                        action: function (args) {
+                                            var data = {
+                                                zoneid: args.context.physicalResources[0].id
+                                            };
+                                            $.ajax({
+                                                url: createURL("enableOutOfBandManagementForZone"),
+                                                data: data,
+                                                success: function (json) {
+                                                    var jid = json.enableoutofbandmanagementforzoneresponse.jobid;
+                                                    args.response.success({
+                                                        _custom: {
+                                                            jobId: jid,
+                                                            getActionFilter: function () {
+                                                                return zoneActionfilter;
+                                                            }
+                                                        }
+                                                    });
+                                                },
+                                                error: function (json) {
+                                                    args.response.error(parseXMLHttpResponse(json));
+                                                }
+
+                                            });
+                                        },
+                                        messages: {
+                                            confirm: function (args) {
+                                                return 'message.outofbandmanagement.enable';
+                                            },
+                                            notification: function (args) {
+                                                return 'message.outofbandmanagement.enable';
+                                            }
+                                        },
+                                        notification: {
+                                            poll: pollAsyncJobResult
+                                        }
+                                    },
+                                    disableOutOfBandManagement: {
+                                        label: 'label.outofbandmanagement.disable',
+                                        action: function (args) {
+                                            var data = {
+                                                zoneid: args.context.physicalResources[0].id
+                                            };
+                                            $.ajax({
+                                                url: createURL("disableOutOfBandManagementForZone"),
+                                                data: data,
+                                                success: function (json) {
+                                                    var jid = json.disableoutofbandmanagementforzoneresponse.jobid;
+                                                    args.response.success({
+                                                        _custom: {
+                                                            jobId: jid,
+                                                            getActionFilter: function () {
+                                                                return zoneActionfilter;
+                                                            }
+                                                        }
+                                                    });
+                                                },
+                                                error: function (json) {
+                                                    args.response.error(parseXMLHttpResponse(json));
+                                                }
+
+                                            });
+                                        },
+                                        messages: {
+                                            confirm: function (args) {
+                                                return 'message.outofbandmanagement.disable';
+                                            },
+                                            notification: function (args) {
+                                                return 'message.outofbandmanagement.disable';
+                                            }
+                                        },
+                                        notification: {
+                                            poll: pollAsyncJobResult
+                                        }
                                     }
                                 },
                                 tabs: {
@@ -9058,8 +9134,17 @@
                                         url: createURL('listHosts'),
                                         data: data,
                                         success: function (json) {
+                                            var items = json.listhostsresponse.host;
+                                            if (items) {
+                                                $.each(items, function(idx, host) {
+                                                    if (host && host.outofbandmanagement) {
+                                                        items[idx].powerstate = host.outofbandmanagement.powerstate;
+                                                    }
+                                                });
+                                            }
+
                                             args.response.success({
-                                                data: json.listhostsresponse.host
+                                                data: items
                                             });
                                         },
                                         error: function (json) {
@@ -14970,7 +15055,85 @@
                                         args.complete();
                                     }
                                 }
+                            },
+
+                            enableOutOfBandManagement: {
+                                label: 'label.outofbandmanagement.enable',
+                                action: function (args) {
+                                    var data = {
+                                        clusterid: args.context.clusters[0].id,
+                                    };
+                                    $.ajax({
+                                        url: createURL("enableOutOfBandManagementForCluster"),
+                                        data: data,
+                                        success: function (json) {
+                                            var jid = json.enableoutofbandmanagementforclusterresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return clusterActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+                                    });
+                                },
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.enable';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.enable';
+                                    }
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            },
+
+                            disableOutOfBandManagement: {
+                                label: 'label.outofbandmanagement.disable',
+                                action: function (args) {
+                                    var data = {
+                                        clusterid: args.context.clusters[0].id,
+                                    };
+                                    $.ajax({
+                                        url: createURL("disableOutOfBandManagementForCluster"),
+                                        data: data,
+                                        success: function (json) {
+                                            var jid = json.disableoutofbandmanagementforclusterresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return clusterActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+
+                                    });
+                                },
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.disable';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.disable';
+                                    }
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
                             }
+
                         },
 
                         tabs: {
@@ -15328,7 +15491,15 @@
                                 'Alert': 'off',
                                 'Error': 'off'
                             }
-                        }
+                        },
+                        powerstate: {
+                            label: 'label.powerstate',
+                            indicator: {
+                                'On': 'on',
+                                'Off': 'off',
+                                'Unknown': 'warning'
+                            },
+                        },
                     },
 
                     dataProvider: function (args) {
@@ -15355,13 +15526,20 @@
                             //Instances menu > Instance detailView > View Hosts
                             array1.push("&id=" + args.context.instances[0].hostid);
                         }
-
                         $.ajax({
                             url: createURL("listHosts&type=Routing" + array1.join("") + "&page=" + args.page + "&pagesize=" + pageSize),
                             dataType: "json",
                             async: true,
                             success: function (json) {
                                 var items = json.listhostsresponse.host;
+                                if (items) {
+                                    $.each(items, function(idx, host) {
+                                        if (host && host.outofbandmanagement) {
+                                            items[idx].powerstate = host.outofbandmanagement.powerstate;
+                                        }
+                                    });
+                                }
+
                                 args.response.success({
                                     actionFilter: hostActionfilter,
                                     data: items
@@ -15998,6 +16176,7 @@
                                 }
                             },
 
+
                             dedicate: {
                                 label: 'label.dedicate.host',
                                 messages: {
@@ -16347,13 +16526,331 @@
                                         args.complete();
                                     }
                                 }
+                            },
+
+                            blankOutOfBandManagement: {
+                                label: '',
+                                action: function (args) {
+                                }
+                            },
+
+                            configureOutOfBandManagement: {
+                                label: 'label.outofbandmanagement.configure',
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.configure';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.configure';
+                                    }
+                                },
+                                createForm: {
+                                    title: 'label.outofbandmanagement.configure',
+                                    fields: {
+                                        address: {
+                                            label: 'label.outofbandmanagement.address',
+                                            validation: {
+                                                required: true
+                                            }
+                                        },
+                                        port: {
+                                            label: 'label.outofbandmanagement.port',
+                                            validation: {
+                                                required: true
+                                            }
+                                        },
+                                        username: {
+                                            label: 'label.outofbandmanagement.username',
+                                            validation: {
+                                                required: false
+                                            }
+                                        },
+                                        password: {
+                                            label: 'label.outofbandmanagement.password',
+                                            isPassword: true,
+                                            validation: {
+                                                required: false
+                                            },
+                                        },
+                                        driver: {
+                                            label: 'label.outofbandmanagement.driver',
+                                            validation: {
+                                                required: true
+                                            },
+                                            select: function (args) {
+                                                var oobm = args.context.hosts[0].outofbandmanagement;
+                                                if (oobm) {
+                                                    args.$form.find('input[name=address]').val(oobm.address);
+                                                    args.$form.find('input[name=port]').val(oobm.port);
+                                                    args.$form.find('input[name=username]').val(oobm.username);
+
+                                                    args.$form.find('input[name=address]').change(function() {
+                                                        $this.find('input[name=address]').val(oobm.address);
+                                                    });
+                                                }
+
+                                                var items = [];
+                                                items.push({
+                                                    id: 'ipmitool',
+                                                    description: 'ipmitool - ipmitool based shell driver'
+                                                });
+                                                args.response.success({
+                                                    data: items
+                                                });
+                                            }
+                                        }
+                                    }
+                                },
+                                action: function (args) {
+                                    var data = args.data;
+                                    data.hostid = args.context.hosts[0].id;
+
+                                    $.ajax({
+                                        url: createURL('configureOutOfBandManagement'),
+                                        data: data,
+                                        dataType: 'json',
+                                        success: function (json) {
+                                            var response = json.configureoutofbandmanagementresponse;
+                                            args.response.success({
+                                                actionFilter: hostActionfilter,
+                                                data: response
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+                                    });
+                                },
+                                notification: {
+                                    poll: function (args) {
+                                        args.complete();
+                                    }
+                                }
+                            },
+
+                            enableOutOfBandManagement: {
+                                label: 'label.outofbandmanagement.enable',
+                                action: function (args) {
+                                    var data = {
+                                        hostid: args.context.hosts[0].id,
+                                    };
+                                    $.ajax({
+                                        url: createURL("enableOutOfBandManagementForHost"),
+                                        data: data,
+                                        success: function (json) {
+                                            var jid = json.enableoutofbandmanagementforhostresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return hostActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+
+                                    });
+                                },
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.enable';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.enable';
+                                    }
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            },
+
+                            disableOutOfBandManagement: {
+                                label: 'label.outofbandmanagement.disable',
+                                action: function (args) {
+                                    var data = {
+                                        hostid: args.context.hosts[0].id,
+                                    };
+                                    $.ajax({
+                                        url: createURL("disableOutOfBandManagementForHost"),
+                                        data: data,
+                                        success: function (json) {
+                                            var jid = json.disableoutofbandmanagementforhostresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return hostActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+
+                                    });
+                                },
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.disable';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.disable';
+                                    }
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            },
+
+                            issueOutOfBandManagementPowerAction: {
+                                label: 'label.outofbandmanagement.action.issue',
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.issue';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.issue';
+                                    }
+                                },
+                                createForm: {
+                                    title: 'label.outofbandmanagement.action.issue',
+                                    desc: function(args) {
+                                          var host = args.context.hosts[0];
+                                          if (host.resourcestate == 'Maintenance' || host.resourcestate == 'PrepareForMaintenance' || host.resourcestate == 'ErrorInMaintenance') {
+                                              return _l('message.outofbandmanagement.action.maintenance');
+                                          }
+                                    },
+                                    fields: {
+                                        action: {
+                                            label: 'label.outofbandmanagement.action',
+                                            validation: {
+                                                required: true
+                                            },
+                                            select: function (args) {
+                                                var items = [];
+                                                items.push({
+                                                    id: 'ON',
+                                                    description: 'ON - turn on host'
+                                                });
+                                                items.push({
+                                                    id: 'OFF',
+                                                    description: 'OFF - turn off host'
+                                                });
+                                                items.push({
+                                                    id: 'CYCLE',
+                                                    description: 'CYCLE - power cycle the host'
+                                                });
+                                                items.push({
+                                                    id: 'RESET',
+                                                    description: 'RESET - power reset the host'
+                                                });
+                                                items.push({
+                                                    id: 'SOFT',
+                                                    description: 'SOFT - soft shutdown the host using ACPI etc'
+                                                });
+                                                items.push({
+                                                    id: 'STATUS',
+                                                    description: 'STATUS - update power status of the host'
+                                                });
+                                                args.response.success({
+                                                    data: items
+                                                });
+                                            }
+                                        },
+                                    }
+                                },
+                                action: function (args) {
+                                    var data = args.data;
+                                    data.hostid = args.context.hosts[0].id;
+                                    $.ajax({
+                                        url: createURL('issueOutOfBandManagementPowerAction'),
+                                        data: data,
+                                        dataType: 'json',
+                                        success: function (json) {
+                                            var jid = json.issueoutofbandmanagementpoweractionresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return hostActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+                                    });
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            },
+
+                            changeOutOfBandManagementPassword: {
+                                label: 'label.outofbandmanagement.changepassword',
+                                messages: {
+                                    confirm: function (args) {
+                                        return 'message.outofbandmanagement.changepassword';
+                                    },
+                                    notification: function (args) {
+                                        return 'message.outofbandmanagement.changepassword';
+                                    }
+                                },
+                                createForm: {
+                                    title: 'label.outofbandmanagement.changepassword',
+                                    fields: {
+                                        password: {
+                                            label: 'label.outofbandmanagement.password',
+                                            isPassword: true,
+                                            validation: {
+                                                required: false
+                                            },
+                                        },
+                                    }
+                                },
+                                action: function (args) {
+                                    var data = args.data;
+                                    data.hostid = args.context.hosts[0].id;
+                                    $.ajax({
+                                        url: createURL('changeOutOfBandManagementPassword'),
+                                        data: data,
+                                        dataType: 'json',
+                                        success: function (json) {
+                                            var jid = json.changeoutofbandmanagementpasswordresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid,
+                                                    getActionFilter: function () {
+                                                        return hostActionfilter;
+                                                    }
+                                                }
+                                            });
+                                        },
+                                        error: function (json) {
+                                            args.response.error(parseXMLHttpResponse(json));
+                                        }
+                                    });
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
                             }
+
                         },
                         tabFilter: function (args) {
                             var hiddenTabs =[];
-                            if (args.context.hosts[0].gpugroup == null) {
+                            var host = args.context.hosts[0];
+                            if (host.gpugroup == null) {
                                 hiddenTabs.push("gpu");
                             }
+                            if (host.outofbandmanagement == null || !host.outofbandmanagement.enabled) {
+                                hiddenTabs.push("outofbandmanagement");
+                            }
                             return hiddenTabs;
                         },
                         tabs: {
@@ -16390,6 +16887,9 @@
                                     state: {
                                         label: 'label.state'
                                     },
+                                    powerstate: {
+                                        label: 'label.powerstate'
+                                    },
                                     type: {
                                         label: 'label.type'
                                     },
@@ -16501,6 +17001,10 @@
                                         async: true,
                                         success: function (json) {
                                             var item = json.listhostsresponse.host[0];
+                                            if (item && item.outofbandmanagement) {
+                                                item.powerstate = item.outofbandmanagement.powerstate;
+                                            }
+
                                             $.ajax({
                                                 url: createURL("listDedicatedHosts&hostid=" + args.context.hosts[0].id),
                                                 dataType: "json",
@@ -16532,6 +17036,44 @@
                                 }
                             },
 
+                            outofbandmanagement: {
+                                title: 'label.outofbandmanagement',
+                                fields: {
+                                    powerstate: {
+                                        label: 'label.powerstate'
+                                    },
+                                    driver: {
+                                        label: 'label.outofbandmanagement.driver'
+                                    },
+                                    username: {
+                                        label: 'label.outofbandmanagement.username'
+                                    },
+                                    address: {
+                                        label: 'label.outofbandmanagement.address'
+                                    },
+                                    port: {
+                                        label: 'label.outofbandmanagement.port'
+                                    }
+                                },
+                                dataProvider: function (args) {
+                                    $.ajax({
+                                        url: createURL("listHosts&id=" + args.context.hosts[0].id),
+                                        dataType: "json",
+                                        async: true,
+                                        success: function (json) {
+                                            var host = json.listhostsresponse.host[0];
+                                            var oobm = {};
+                                            if (host && host.outofbandmanagement) {
+                                                oobm = host.outofbandmanagement;
+                                            }
+                                            args.response.success({
+                                                data: oobm
+                                            });
+                                        }
+                                    });
+                                }
+                            },
+
                             stats: {
                                 title: 'label.statistics',
                                 fields: {
@@ -20807,6 +21349,13 @@
         allowedActions.push("disable");
 
         allowedActions.push("remove");
+
+        if (jsonObj.hasOwnProperty('resourcedetails') && jsonObj['resourcedetails'].hasOwnProperty('outOfBandManagementEnabled') && jsonObj['resourcedetails']['outOfBandManagementEnabled'] == 'false') {
+            allowedActions.push("enableOutOfBandManagement");
+        } else {
+            allowedActions.push("disableOutOfBandManagement");
+        }
+
         return allowedActions;
     }
 
@@ -20892,6 +21441,12 @@
 
         allowedActions.push("remove");
 
+        if (jsonObj.hasOwnProperty('resourcedetails') && jsonObj['resourcedetails'].hasOwnProperty('outOfBandManagementEnabled') && jsonObj['resourcedetails']['outOfBandManagementEnabled'] == 'false') {
+            allowedActions.push("enableOutOfBandManagement");
+        } else {
+            allowedActions.push("disableOutOfBandManagement");
+        }
+
         return allowedActions;
     }
 
@@ -20928,6 +21483,16 @@
             allowedActions.push("remove");
         }
 
+        allowedActions.push("blankOutOfBandManagement");
+        allowedActions.push("configureOutOfBandManagement");
+        if (jsonObj.hasOwnProperty("outofbandmanagement") && jsonObj.outofbandmanagement.enabled) {
+            allowedActions.push("issueOutOfBandManagementPowerAction");
+            allowedActions.push("changeOutOfBandManagementPassword");
+            allowedActions.push("disableOutOfBandManagement");
+        } else {
+            allowedActions.push("enableOutOfBandManagement");
+        }
+
         if ((jsonObj.state == "Down" || jsonObj.state == "Alert" || jsonObj.state == "Disconnected") && ($.inArray("remove", allowedActions) == -1)) {
             allowedActions.push("remove");
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/utils/src/main/java/com/cloud/utils/fsm/StateMachine2.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/fsm/StateMachine2.java b/utils/src/main/java/com/cloud/utils/fsm/StateMachine2.java
index 431d961..f03974a 100644
--- a/utils/src/main/java/com/cloud/utils/fsm/StateMachine2.java
+++ b/utils/src/main/java/com/cloud/utils/fsm/StateMachine2.java
@@ -45,10 +45,20 @@ public class StateMachine2<S, E, V extends StateObject<S>> {
 
     }
 
+    public void addInitialTransition(E event, S toState) {
+        addTransition(null, event, toState);
+    }
+
     public void addTransition(S currentState, E event, S toState) {
       addTransition(new Transition<S, E>(currentState, event, toState, null));
     }
 
+    @SafeVarargs
+    public final void addTransitionFromStates(E event, S toState, S... fromStates) {
+        for (S fromState : fromStates) {
+            addTransition(fromState, event, toState);
+        }
+    }
 
     public void addTransition(Transition<S, E> transition) {
       S currentState = transition.getCurrentState();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessResult.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessResult.java b/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessResult.java
new file mode 100644
index 0000000..b50a7ab
--- /dev/null
+++ b/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessResult.java
@@ -0,0 +1,46 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+package org.apache.cloudstack.utils.process;
+
+public final class ProcessResult {
+    private final String stdOutput;
+    private final String stdError;
+    private final int returnCode;
+
+    public ProcessResult(String stdOutput, String stdError, int returnCode) {
+        this.stdOutput = stdOutput;
+        this.stdError = stdError;
+        this.returnCode = returnCode;
+    }
+
+    public String getStdOutput() {
+        return stdOutput;
+    }
+
+    public String getStdError() {
+        return stdError;
+    }
+
+    public int getReturnCode() {
+        return returnCode;
+    }
+
+    public boolean isSuccess() {
+        return returnCode == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessRunner.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessRunner.java b/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessRunner.java
new file mode 100644
index 0000000..c8ea6bf
--- /dev/null
+++ b/utils/src/main/java/org/apache/cloudstack/utils/process/ProcessRunner.java
@@ -0,0 +1,115 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+//
+
+package org.apache.cloudstack.utils.process;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.io.CharStreams;
+import org.apache.log4j.Logger;
+import org.joda.time.Duration;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public final class ProcessRunner {
+    public static final Logger LOG = Logger.getLogger(ProcessRunner.class);
+
+    // Default maximum timeout of 5 minutes for any command
+    public static final Duration DEFAULT_MAX_TIMEOUT = new Duration(5 * 60 * 1000);
+    private final ExecutorService executor;
+
+    public ProcessRunner(ExecutorService executor) {
+        this.executor = executor;
+    }
+
+    /**
+     * Executes a process with provided list of commands with a max default timeout
+     * of 5 minutes
+     * @param commands list of string commands
+     * @return returns process result
+     */
+    public ProcessResult executeCommands(final List<String> commands) {
+        return executeCommands(commands, DEFAULT_MAX_TIMEOUT);
+    }
+
+    /**
+     * Executes a process with provided list of commands with a given timeout that is less
+     * than or equal to DEFAULT_MAX_TIMEOUT
+     * @param commands list of string commands
+     * @param timeOut timeout duration
+     * @return returns process result
+     */
+    public ProcessResult executeCommands(final List<String> commands, final Duration timeOut) {
+        Preconditions.checkArgument(commands != null && timeOut != null
+                && timeOut.getStandardSeconds() > 0L
+                && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0)
+                && executor != null);
+
+        int retVal = -2;
+        String stdOutput = null;
+        String stdError = null;
+
+        try {
+            final Process process = new ProcessBuilder().command(commands).start();
+            final Future<Integer> processFuture = executor.submit(new Callable<Integer>() {
+                @Override
+                public Integer call() throws Exception {
+                    return process.waitFor();
+                }
+            });
+            try {
+                retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS);
+            } catch (ExecutionException e) {
+                retVal = -2;
+                stdError = e.getMessage();
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Failed to complete the requested command due to execution error: " + e.getMessage());
+                }
+            } catch (TimeoutException e) {
+                retVal = -1;
+                stdError = "Operation timed out, aborted";
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Failed to complete the requested command within timeout: " + e.getMessage());
+                }
+            } finally {
+                if (Strings.isNullOrEmpty(stdError)) {
+                    stdOutput = CharStreams.toString(new InputStreamReader(process.getInputStream()));
+                    stdError = CharStreams.toString(new InputStreamReader(process.getErrorStream()));
+                }
+                process.destroy();
+            }
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Process standard output: " + stdOutput);
+                LOG.trace("Process standard error output: " + stdError);
+            }
+        } catch (IOException | InterruptedException e) {
+            stdError = e.getMessage();
+            LOG.error("Exception caught error running commands: " + e.getMessage());
+        }
+        return new ProcessResult(stdOutput, stdError, retVal);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07564469/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java
----------------------------------------------------------------------
diff --git a/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java b/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java
new file mode 100644
index 0000000..b5e6e04
--- /dev/null
+++ b/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java
@@ -0,0 +1,69 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+//
+
+package org.apache.cloudstack.utils.process;
+
+import com.cloud.utils.concurrency.NamedThreadFactory;
+import com.google.common.base.Strings;
+import org.joda.time.Duration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Arrays;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ProcessTest {
+
+    private static final ExecutorService executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("IpmiToolDriverTest"));
+    private static final ProcessRunner RUNNER = new ProcessRunner(executor);
+
+    @Test
+    public void testProcessRunner() {
+        ProcessResult result = RUNNER.executeCommands(Arrays.asList("ls", "/tmp"));
+        Assert.assertEquals(result.getReturnCode(), 0);
+        Assert.assertTrue(Strings.isNullOrEmpty(result.getStdError()));
+        Assert.assertTrue(result.getStdOutput().length() > 0);
+    }
+
+    @Test
+    public void testProcessRunnerWithTimeout() {
+        ProcessResult result = RUNNER.executeCommands(Arrays.asList("sleep", "5"), Duration.standardSeconds(1));
+        Assert.assertNotEquals(result.getReturnCode(), 0);
+        Assert.assertTrue(result.getStdError().length() > 0);
+        Assert.assertEquals(result.getStdError(), "Operation timed out, aborted");
+    }
+
+    @Test
+    public void testProcessRunnerWithTimeoutAndException() {
+        ProcessResult result = RUNNER.executeCommands(Arrays.asList("ls", "/some/dir/that/should/not/exist"), Duration.standardSeconds(2));
+        Assert.assertNotEquals(result.getReturnCode(), 0);
+        Assert.assertTrue(result.getStdError().length() > 0);
+        Assert.assertNotEquals(result.getStdError(), "Operation timed out, aborted");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testProcessRunnerWithMoreThanMaxAllowedTimeout() {
+        RUNNER.executeCommands(Arrays.asList("ls", "/some/dir/that/should/not/exist"), ProcessRunner.DEFAULT_MAX_TIMEOUT.plus(1000));
+        Assert.fail("Illegal argument exception was expected");
+    }
+}


Mime
View raw message