Skip to content

Commit

Permalink
F #5112: Increase onegate functionality for VNF (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian González authored Oct 22, 2020
1 parent 344e803 commit e4577e5
Show file tree
Hide file tree
Showing 10 changed files with 617 additions and 40 deletions.
12 changes: 12 additions & 0 deletions include/RequestManagerPoolInfoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ class VirtualMachinePoolInfoExtended : public VirtualMachinePoolInfo
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */

class VirtualMachinePoolInfoSet : public RequestManagerPoolInfoFilter
{
public:
VirtualMachinePoolInfoSet();

void request_execute(
xmlrpc_c::paramList const& paramList, RequestAttributes& att) override;
};

/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */

class VirtualMachinePoolAccounting : public RequestManagerPoolInfoFilter
{
public:
Expand Down
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,8 @@ FIREEDGE_ETC_FILES="src/fireedge/fireedge-server.conf"
#-----------------------------------------------------------------------------

ONEGATE_FILES="src/onegate/onegate-server.rb \
src/onegate/config.ru"
src/onegate/config.ru \
share/onegate/onegate"

ONEGATE_BIN_FILES="src/onegate/bin/onegate-server"

Expand Down
130 changes: 112 additions & 18 deletions share/onegate/onegate
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,35 @@ module OneGate
end
end

# Virtual Router module
module VirtualRouter

def self.print(json_hash, _extended = false)
OneGate.print_header('VROUTER ' + json_hash['VROUTER']['ID'])
OneGate.print_key_value('NAME', json_hash['VROUTER']['NAME'])

vms_ids = Array(json_hash['VROUTER']['VMS']['ID'])

vms = vms_ids.join(',')

OneGate.print_key_value('VMS', vms)
puts
end

end

# Virtual Network module
module VirtualNetwork

def self.print(json_hash, _extended = false)
OneGate.print_header('VNET')
OneGate.print_key_value('ID', json_hash['VNET']['ID'])

puts
end

end

class Client
def initialize(opts={})
@vmid = ENV["VMID"]
Expand Down Expand Up @@ -473,8 +502,8 @@ module OneGate

def self.parse_json(response)
if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
else
return JSON.parse(response.body)
Expand Down Expand Up @@ -537,6 +566,10 @@ Available commands
$ onegate service show [--json][--extended]
$ onegate service scale --role ROLE --cardinality CARDINALITY
$ onegate vrouter show [--json]
$ onegate vnet show VNETID [--json][--extended]
EOT
end
end
Expand Down Expand Up @@ -576,7 +609,7 @@ OptionParser.new do |opts|
end

opts.on("-h", "--help", "Show this message") do
puts OneGate.help_str
STDERR.puts OneGate.help_str
exit
end
end.parse!
Expand All @@ -601,7 +634,7 @@ when "vm"
end
when "update"
if !options[:data] && !options[:erase]
puts "You have to provide the data as a param (--data, --erase)"
STDERR.puts 'You have to provide the data as a param (--data, --erase)'
exit -1
end

Expand All @@ -618,8 +651,8 @@ when "vm"
end

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
when "resume",
Expand Down Expand Up @@ -649,18 +682,18 @@ when "vm"
response = client.post("/vms/"+ARGV[2]+"/action", action_hash.to_json)

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
else
puts "You have to provide a VM ID"
STDERR.puts 'You have to provide a VM ID'
exit -1
end
else
puts OneGate.help_str
puts
puts "Action #{ARGV[1]} not supported"
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit -1
end
when "service"
Expand Down Expand Up @@ -693,18 +726,79 @@ when "service"
}.to_json)

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
else
puts OneGate.help_str
puts
puts "Action #{ARGV[1]} not supported"
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit -1
end
when 'vrouter'
case ARGV[1]
when 'show'
if options[:extended]
extra = {}
extra['extended'] = true

extra = URI.encode_www_form(extra)
end

response = client.get('/vrouter', extra)
json_hash = OneGate.parse_json(response)

if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualRouter.print(json_hash, true)
else
OneGate::VirtualRouter.print(json_hash)
end
end
else
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
when 'vnet'
case ARGV[1]
when 'show'
if ARGV[2]
if options[:extended]
extra = {}
extra['extended'] = true

extra = URI.encode_www_form(extra)
end

response = client.get('/vnet/'+ARGV[2], extra)
json_hash = OneGate.parse_json(response)

if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualNetwork.print(json_hash, true)
else
OneGate::VirtualNetwork.print(json_hash)
end
end
else
STDERR.puts 'You have to provide a VNET ID'
exit -1
end
else
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
else
puts OneGate.help_str
STDERR.puts OneGate.help_str
exit -1
end

14 changes: 14 additions & 0 deletions src/oca/go/src/goca/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ func (vc *VMsController) InfoExtendedFilter(f *VMFilter) (*vm.Pool, error) {
return vmPool, nil
}

// InfoSet connects to OpenNebula and fetches a VM_POOL containing the VMs in vmIds
func (vc *VMsController) InfoSet(vmIds string, extended bool) (*vm.Pool, error) {
response, err := vc.c.Client.Call("one.vmpool.infoset", vmIds, extended)
if err != nil {
return nil, err
}
vmPool := &vm.Pool{}
err = xml.Unmarshal([]byte(response.Body()), vmPool)
if err != nil {
return nil, err
}
return vmPool, nil
}

// Info connects to OpenNebula and fetches the information of the VM
func (vc *VMController) Info(decrypt bool) (*vm.VM, error) {
response, err := vc.c.Client.Call("one.vm.info", vc.ID, decrypt)
Expand Down
15 changes: 15 additions & 0 deletions src/oca/java/src/org/opennebula/client/vm/VirtualMachinePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
private static final String ELEMENT_NAME = "VM";
private static final String INFO_METHOD = "vmpool.info";
private static final String INFO_EXTENDED_METHOD = "vmpool.infoextended";
private static final String INFO_SET_METHOD = "vmpool.infoset";
private static final String MONITORING = "vmpool.monitoring";

/**
Expand Down Expand Up @@ -133,6 +134,20 @@ public static OneResponse info_extended(Client client, int filter)
return client.call(INFO_EXTENDED_METHOD, filter, -1, -1, NOT_DONE);
}

/**
* Retrieves all of the Virtual Machines in the vm_ids list.
*
* @param client XML-RPC Client.
* @param vm_ids Comma separated list of VM IDs.
* @param extended If true the extended body is retrieved.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info_extended(Client client, int vm_ids, boolean extended)
{
return client.call(INFO_SET_METHOD, vm_ids, extended);
}

/**
* Retrieves all the Virtual Machines in the pool.
*
Expand Down
39 changes: 23 additions & 16 deletions src/oca/ruby/opennebula/virtual_machine_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class VirtualMachinePool < Pool
# Constants and Class attribute accessors
#######################################################################


VM_POOL_METHODS = {
:info => "vmpool.info",
:info_extended => "vmpool.infoextended",
:monitoring => "vmpool.monitoring",
:accounting => "vmpool.accounting",
:showback => "vmpool.showback",
:calculate_showback => "vmpool.calculateshowback"
:info => 'vmpool.info',
:info_extended => 'vmpool.infoextended',
:info_set => 'vmpool.infoset',
:monitoring => 'vmpool.monitoring',
:accounting => 'vmpool.accounting',
:showback => 'vmpool.showback',
:calculate_showback => 'vmpool.calculateshowback'
}

# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
Expand All @@ -41,7 +41,6 @@ class VirtualMachinePool < Pool
# Class constructor & Pool Methods
#######################################################################


# +client+ a Client object that represents a XML-RPC connection
# +user_id+ is to refer to a Pool with VirtualMachines from that user
def initialize(client, user_id=0)
Expand Down Expand Up @@ -102,21 +101,21 @@ def info(*args)
end

# Define info methods shortcuts for different filters
# info_all()
# info_all()
# info_all!()
# info_all_extended
# info_all_extended
# info_all_extended!()
# info_mine()
# info_mine()
# info_mine!()
# info_mine_extended
# info_mine_extended
# info_mine_extended!()
# info_group()
# info_group()
# info_group!()
# info_group_extended
# info_group_extended
# info_group_extended!()
# info_primary_group()
# info_primary_group()
# info_primary_group!()
# info_primary_group_extended
# info_primary_group_extended
# info_primary_group_extended!()
%w[mine all group primary_group].each do |ifilter|
const_name = "OpenNebula::Pool::INFO_#{ifilter.upcase}"
Expand Down Expand Up @@ -160,6 +159,14 @@ def info_search(args = {})
default_args[:query])
end

# Retrieves the set of VMs especified in vm_ids
#
# @param [String] comma separated list of vm ids.
# @param [Boolean] if true extended body is retrieved.
#
def info_set(vm_ids, extended)
xmlrpc_info(VM_POOL_METHODS[:info_set], vm_ids, extended)
end

# Retrieves the monitoring data for all the VMs in the pool
#
Expand Down
16 changes: 16 additions & 0 deletions src/onegate/etc/onegate-server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,29 @@
:service:
:show: true
:change_cardinality: true
:vrouter:
:show: true
:vnet:
:show_by_id: true

# Attrs that cannot be modified when updating a VM template
:restricted_attrs:
- SCHED_REQUIREMENTS
- SERVICE_ID
- ROLE_NAME

# Attrs of the Virtual Network template that will be retrieved
# with onegate vnet | get /vnet/:id requests.
:vnet_template_attributes:
- NETWORK_ADDRESS
- NETWORK_MASK
- GATEWAY
- GATEWAY6
- DNS
- GUEST_MTU
- CONTEXT_FORCE_IPV4
- SEARCH_DOMAIN

# Actions that cannot be performed on a VM
:restricted_actions:
#- deploy
Expand Down
Loading

0 comments on commit e4577e5

Please sign in to comment.