mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
be8bd682c0
commit
1d51724851
@ -18,71 +18,90 @@ module SunstoneVMHelper
|
||||
|
||||
class << self
|
||||
|
||||
def state_to_str(id, lcm_id)
|
||||
id = id.to_i
|
||||
state_str = VirtualMachine::VM_STATE[id]
|
||||
NIC_ATTRS = %w[
|
||||
IP
|
||||
EXTERNAL_IP
|
||||
IP6
|
||||
IP6_GLOBAL
|
||||
IP6_ULA
|
||||
VROUTER_IP
|
||||
VROUTER_IP6_GLOBAL
|
||||
VROUTER_IP6_ULA
|
||||
]
|
||||
|
||||
if state_str == 'ACTIVE'
|
||||
lcm_id = lcm_id.to_i
|
||||
return VirtualMachine::LCM_STATE[lcm_id]
|
||||
def state_to_str(id, lcm_id)
|
||||
id = id.to_i
|
||||
state_str = VirtualMachine::VM_STATE[id]
|
||||
|
||||
if state_str == 'ACTIVE'
|
||||
lcm_id = lcm_id.to_i
|
||||
return VirtualMachine::LCM_STATE[lcm_id]
|
||||
end
|
||||
|
||||
state_str
|
||||
end
|
||||
|
||||
return state_str
|
||||
end
|
||||
def get_ips(vm_resource)
|
||||
vm = vm_resource.to_hash['VM']
|
||||
ips = []
|
||||
vm_nics = []
|
||||
|
||||
def get_ips(vm)
|
||||
ips = []
|
||||
template_nic = vm['TEMPLATE']['NIC']
|
||||
template_pci = vm['TEMPLATE']['PCI']
|
||||
|
||||
vm_nics = []
|
||||
vm_nics = [template_nic].flatten unless template_nic.nil?
|
||||
|
||||
if !vm['TEMPLATE']['NIC'].nil?
|
||||
vm_nics = [vm['TEMPLATE']['NIC']].flatten
|
||||
end
|
||||
vm_nics = [vm_nics, template_pci].flatten unless template_pci.nil?
|
||||
|
||||
if !vm['TEMPLATE']['PCI'].nil?
|
||||
vm_nics = [vm_nics, vm['TEMPLATE']['PCI']].flatten
|
||||
end
|
||||
vm_nics.each do |nic|
|
||||
NIC_ATTRS.each do |attr|
|
||||
next unless nic.key?(attr)
|
||||
|
||||
vm_nics.each do |nic|
|
||||
%w[IP EXTERNAL_IP IP6_GLOBAL IP6_ULA IP6
|
||||
VROUTER_IP VROUTER_IP6_GLOBAL VROUTER_IP6_ULA].each do |attr|
|
||||
if nic.key?(attr)
|
||||
ips.push(nic[attr])
|
||||
end
|
||||
|
||||
next if nic['ALIAS_IDS'].nil?
|
||||
|
||||
nic['ALIAS_IDS'].split(',').each do |alias_id|
|
||||
NIC_ATTRS.each do |attr|
|
||||
alias_ip = vm_resource["/VM/TEMPLATE
|
||||
/NIC_ALIAS[NIC_ID='#{alias_id}']/#{attr}"]
|
||||
|
||||
next if alias_ip.nil?
|
||||
|
||||
ips.push("* #{alias_ip}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
VirtualMachine::EXTERNAL_IP_ATTRS.each do |attr|
|
||||
external_ip = vm['MONITORING'][attr]
|
||||
VirtualMachine::EXTERNAL_IP_ATTRS.each do |attr|
|
||||
external_ip = vm['MONITORING'][attr]
|
||||
|
||||
next unless external_ip.nil? && ips.include?(external_ip)
|
||||
|
||||
if !external_ip.nil? && !ips.include?(external_ip)
|
||||
ips.push(external_ip)
|
||||
end
|
||||
|
||||
ips
|
||||
end
|
||||
|
||||
return ips
|
||||
end
|
||||
def get_remote_info(vm_resource)
|
||||
info = {
|
||||
:id => vm_resource['/VM/ID'],
|
||||
:name => vm_resource['/VM/NAME'],
|
||||
:state => state_to_str(vm_resource['/VM/STATE'],
|
||||
vm_resource['/VM/LCM_STATE']),
|
||||
:start_time => vm_resource['/VM/STIME'],
|
||||
:networks => get_ips(vm_resource)
|
||||
}
|
||||
|
||||
service_id = vm_resource['/VM/USER_TEMPLATE/SERVICE_ID']
|
||||
|
||||
def get_remote_info(vm_resource)
|
||||
vm = vm_resource.to_hash['VM']
|
||||
info[:service_id] = service_id if service_id
|
||||
|
||||
service_id = vm['USER_TEMPLATE']['SERVICE_ID']
|
||||
info
|
||||
end
|
||||
|
||||
info = {
|
||||
:id => vm['ID'],
|
||||
:name => vm['NAME'],
|
||||
:state => state_to_str(vm['STATE'], vm['LCM_STATE']),
|
||||
:start_time => vm['STIME'],
|
||||
:networks => get_ips(vm)
|
||||
}
|
||||
|
||||
info[:service_id] = service_id if service_id
|
||||
|
||||
return info
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
117
src/sunstone/public/app/templates/helpers/contains.js
Normal file
117
src/sunstone/public/app/templates/helpers/contains.js
Normal file
@ -0,0 +1,117 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2021, 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) {
|
||||
/**
|
||||
* Block helper that renders the block if `collection` has the
|
||||
* given `value`, using strict equality (`===`) for comparison,
|
||||
* otherwise the inverse block is rendered (if specified). If a
|
||||
* `startIndex` is specified and is negative, it is used as the
|
||||
* offset from the end of the collection.
|
||||
*
|
||||
* ```handlebars
|
||||
* <!-- array = ['a', 'b', 'c'] -->
|
||||
* {{#contains array "d"}}
|
||||
* This will not be rendered.
|
||||
* {{else}}
|
||||
* This will be rendered.
|
||||
* {{/contains}}
|
||||
* ```
|
||||
* @param {Array|Object|String} `collection` The collection to iterate over.
|
||||
* @param {any} `value` The value to check for.
|
||||
* @param {Number} `[startIndex=0]` Optionally define the starting index.
|
||||
* @param {Object} `options` Handlebars provided options object.
|
||||
* @block
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var Handlebars = require('hbs/handlebars');
|
||||
|
||||
function isFunction(val) {
|
||||
return typeof val === 'function';
|
||||
};
|
||||
|
||||
function isObject(val) {
|
||||
return typeof val === 'object';
|
||||
};
|
||||
|
||||
function isOptions(val) {
|
||||
return isObject(val) && isObject(val.hash);
|
||||
};
|
||||
|
||||
function isBlock(options) {
|
||||
return isOptions(options) && isFunction(options.fn) && isFunction(options.inverse)
|
||||
};
|
||||
|
||||
function getValue(val, context, options) {
|
||||
if (isOptions(val)) {
|
||||
return getValue(null, val, options);
|
||||
}
|
||||
|
||||
if (isOptions(context)) {
|
||||
return getValue(val, {}, context);
|
||||
}
|
||||
|
||||
if (isBlock(options)) {
|
||||
return !!val ? options.fn(context) : options.inverse(context);
|
||||
}
|
||||
|
||||
return val;
|
||||
};
|
||||
|
||||
var contains = function(collection, value, startIndex, options) {
|
||||
if (typeof startIndex === 'object') {
|
||||
options = startIndex;
|
||||
startIndex = undefined;
|
||||
}
|
||||
|
||||
let val = (collection === null || value === null || isNaN(collection.length))
|
||||
? false
|
||||
: collection.indexOf(value, startIndex) !== -1;
|
||||
|
||||
return getValue(val, this, options);
|
||||
};
|
||||
|
||||
Handlebars.registerHelper('contains', contains);
|
||||
|
||||
return contains;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
{{!-- SERVICE --}}
|
||||
{{#if service }}
|
||||
<span>(Part of: {{ service.NAME }})</span>
|
||||
<span>(Part of: {{ service.NAME }})</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
@ -66,12 +66,21 @@
|
||||
</a>
|
||||
<ul class="menu" style="
|
||||
max-height: 10em;
|
||||
max-width: 12em;
|
||||
max-width: 15em;
|
||||
overflow-y: auto;
|
||||
padding: 0.5em;
|
||||
">
|
||||
{{#each networks}}
|
||||
<li>
|
||||
<a style="color:gray">{{ this }}</a>
|
||||
<p title="{{this}}" style="
|
||||
margin:0;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
{{#contains this '*'}} padding-left:1em; {{/contains}}
|
||||
">
|
||||
{{ this }}
|
||||
</p>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -35,12 +35,10 @@ define(function(require) {
|
||||
var json = atob(info_encode)
|
||||
var info = JSON.parse(json)
|
||||
|
||||
// state class
|
||||
var stateId = OpenNebulaVM.STATES[info.state]
|
||||
var lcmStateId = OpenNebulaVM.LCM_STATES[info.state]
|
||||
var stateClass = OpenNebulaVM.stateClass(stateId) || OpenNebulaVM.lcmStateClass(lcmStateId)
|
||||
|
||||
// get service from cache or sync
|
||||
var service = OpenNebulaService.getService(info.service_id)
|
||||
|
||||
return $.extend(info, { stateClass, service })
|
||||
|
Loading…
x
Reference in New Issue
Block a user