Class: Distem::NetAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/netapi/client.rb

Overview

Note:

For desc parameters, the only elements in the structure (Hash) that will be taken in account are those listed as writable in Resources Description.

Note:

Most of changes you can perform on virtual nodes resources are taking effect after stopping then starting back the resource. Changes that are applied on-the-fly are documented as this.

Distem ruby client

Constant Summary

MAX_SIMULTANEOUS_REQ =

The maximum number of simultaneous requests

50
HTTP_STATUS_OK =

The HTTP OK status value

200
@@semreq =
Lib::Semaphore.new(MAX_SIMULTANEOUS_REQ)

Instance Method Summary (collapse)

Constructor Details

- (Client) initialize(serveraddr = "localhost", port = 4567, semsize = nil)

Create a new Client and connect it to a specified REST(distem) server

Parameters:

  • serveraddr (String) (defaults to: "localhost")

    The REST server address

  • port (Numeric) (defaults to: 4567)

    The port the REST server is listening on



36
37
38
39
40
41
42
# File 'lib/distem/netapi/client.rb', line 36

def initialize(serveraddr="localhost",port=4567, semsize = nil)
  raise unless port.is_a?(Numeric)
  @serveraddr = serveraddr
  @serverurl = 'http://' + @serveraddr + ':' + port.to_s
  @resource = RestClient::Resource.new(@serverurl, :timeout => 9999, :open_timeout => 9999)
  @@semreq = Lib::Semaphore.new(semsize) if semsize and @@semreq.size != semsize
end

Instance Method Details

- (Object) event_manager_start

Start the event manager



651
652
653
# File 'lib/distem/netapi/client.rb', line 651

def event_manager_start
  post_json("/eventmanager", {})
end

- (Object) event_manager_stop

Stop the event manager and clear the event list



656
657
658
# File 'lib/distem/netapi/client.rb', line 656

def event_manager_stop
  delete_json("/eventmanager")
end

- (Object) event_random_add(resource_desc, event_type, generator_desc, first_value = nil)

Add a random generated event to a resource



641
642
643
644
645
646
647
648
# File 'lib/distem/netapi/client.rb', line 641

def event_random_add(resource_desc, event_type, generator_desc, first_value = nil)
  params = {}
  params['resource'] = resource_desc
  params['event_type'] = event_type
  params['generator'] = generator_desc
  params['first_value'] = first_value if first_value
  post_json("/events/random", params)
end

- (Object) event_trace_add(resource_desc, event_type, trace)

Add an event trace to a resource

Parameters:

  • resource_desc (Hash)

    A descrition of the affected resource

  • event_type (String)

    The type of event : 'churn', 'availability', 'bandwidth', 'latency'

  • trace (Hash)

    The trace of events



614
615
616
617
618
619
620
# File 'lib/distem/netapi/client.rb', line 614

def event_trace_add(resource_desc, event_type, trace)
  params = {}
  params['resource'] = resource_desc
  params['event_type'] = event_type
  params['trace'] = trace
  post_json("/events/trace", params)
end

- (Object) event_trace_file_add(resource_desc, event_type, trace_file)

Add an event trace to a resource from a file



632
633
634
635
636
637
638
# File 'lib/distem/netapi/client.rb', line 632

def event_trace_file_add(resource_desc, event_type, trace_file)
  params = {}
  params['resource'] = resource_desc
  params['event_type'] = event_type
  params['trace_string'] = IO.read(trace_file)
  post_json("/events/trace_string", params)
end

- (Object) event_trace_string_add(resource_desc, event_type, trace_string)

Add an event trace to a resource, but the source is a string



623
624
625
626
627
628
629
# File 'lib/distem/netapi/client.rb', line 623

def event_trace_string_add(resource_desc, event_type, trace_string)
  params = {}
  params['resource'] = resource_desc
  params['event_type'] = event_type
  params['trace_string'] = trace_string
  post_json("/events/trace_string", params)
end

- (Hash) pcpu_info(target = 'localhost')

Retrieve information about the CPU of a physical node

Parameters:

  • target (String) (defaults to: 'localhost')

    The address/name of the physical node

Returns:



136
137
138
# File 'lib/distem/netapi/client.rb', line 136

def pcpu_info(target='localhost')
  get_json("/pnodes/#{target}/cpu")
end

- (Hash) pmemory_info(target = 'localhost')

Retrieve information about the memory of a physical node

Parameters:

  • target (String) (defaults to: 'localhost')

    The address/name of the physical node

Returns:



144
145
146
# File 'lib/distem/netapi/client.rb', line 144

def pmemory_info(target='localhost')
  get_json("/pnodes/#{target}/memory")
end

- (Hash) pnode_info(target = 'localhost')

Retrieve informations about a physical node

Parameters:

  • target (String) (defaults to: 'localhost')

    The address/name of the physical node

Returns:



83
84
85
# File 'lib/distem/netapi/client.rb', line 83

def pnode_info(target='localhost')
  get_json("/pnodes/#{target}")
end

- (Hash) pnode_init(target = 'localhost', desc = {}, async = false)

Initialize a physical machine (launching daemon, creating cgroups, …). This step have to be performed to be able to create virtual nodes on a machine.

Parameters:

  • target (String|Array) (defaults to: 'localhost')

    The hostname(s)/address(es) of the physical node(n)

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - PNodes.

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check the physical node status to know when the configuration is done (see #pnode_info)

Returns:



51
52
53
# File 'lib/distem/netapi/client.rb', line 51

def pnode_init(target = 'localhost', desc = {}, async=false)
  post_json("/pnodes", { :target => target, :desc => desc, :async => async })
end

- (Hash) pnode_init!(target = 'localhost', desc = {})

Asynchronious version of #pnode_init.

Returns:



58
59
60
# File 'lib/distem/netapi/client.rb', line 58

def pnode_init!(target = 'localhost', desc = {})
  return pnode_init(target,desc,true)
end

- (Hash) pnode_quit(target = 'localhost')

Quit distem on a physical machine

Parameters:

  • target (String) (defaults to: 'localhost')

    The hostname/address of the physical node

Returns:



66
67
68
# File 'lib/distem/netapi/client.rb', line 66

def pnode_quit(target='localhost')
  delete_json("/pnodes/#{target}")
end

- (Hash) pnode_update(target = 'localhost', desc = {})

Update the physical node

Parameters:

  • target (String) (defaults to: 'localhost')

    The hostname/address of the physical node

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - PNodes.

Returns:



75
76
77
# File 'lib/distem/netapi/client.rb', line 75

def pnode_update(target='localhost', desc={})
  put_json("/pnodes/#{CGI.escape(target)}", { :desc => desc })
end

- (Object) pnodes_delete_probes

Delete the probes on the pnodes



121
122
123
# File 'lib/distem/netapi/client.rb', line 121

def pnodes_delete_probes()
  delete_json("/pnodes/probes")
end

- (Hash) pnodes_get_probes_data

Get the data generated by the probes

Returns:

  • (Hash)

    Hash containing the data



128
129
130
# File 'lib/distem/netapi/client.rb', line 128

def pnodes_get_probes_data()
  return get_json("/pnodes/probes")
end

- (Array) pnodes_info

Retrieve informations about every physical nodes currently set on the platform

Returns:



97
98
99
# File 'lib/distem/netapi/client.rb', line 97

def pnodes_info()
  get_json("/pnodes")
end

- (Object) pnodes_launch_probes(desc, ref_time = nil)

Launch a set of probes on the pnodes

Parameters:

  • desc (Hash)

    Description of a set of probes



104
105
106
107
108
# File 'lib/distem/netapi/client.rb', line 104

def pnodes_launch_probes(desc, ref_time = nil)
  params = { :desc => desc }
  params[:ref_time] = ref_time if ref_time
  post_json("/pnodes/probes", params)
end

- (Array) pnodes_quit

Quit distem on every physical machine

Returns:



90
91
92
# File 'lib/distem/netapi/client.rb', line 90

def pnodes_quit()
  delete_json("/pnodes")
end

- (Object) pnodes_restart_probes

Restart the probes on the pnodes



111
112
113
# File 'lib/distem/netapi/client.rb', line 111

def pnodes_restart_probes()
  put_json("/pnodes/probes", { :state => 'restart'})
end

- (Object) pnodes_stop_probes

Stop the probes on the pnodes



116
117
118
# File 'lib/distem/netapi/client.rb', line 116

def pnodes_stop_probes()
  put_json("/pnodes/probes", { :state => 'stop'})
end

- (Object) PUT '/vnodes'



212
# File 'lib/distem/netapi/client.rb', line 212

put('/vnodes', { :name => name, :desc => desc, :async => async, :type => 'update' })

- (Object) set_global_arptable(data = nil, arp_file = nil)

Fill the ARP tables of all the Vnodes

Parameters:

  • data (Array) (defaults to: nil)

    The whole ip->mac information. Format is [[mac1,ip1],,…]

  • arp_file (String) (defaults to: nil)

    Destination file



694
695
696
697
698
699
# File 'lib/distem/netapi/client.rb', line 694

def set_global_arptable(data = nil, arp_file = nil)
  params = {}
  params['data'] = data if data
  params['arp_file'] = arp_file if arp_file
  post_json("/global_arptable", params)
end

- (Object) set_global_etchosts(data = nil)

Create a global /etc/hosts on every Vnodes

Parameters:

  • data (Array) (defaults to: nil)

    The whole hostname->ip information. Format is [[host1,ip1],,…]



674
675
676
677
678
# File 'lib/distem/netapi/client.rb', line 674

def set_global_etchosts(data = nil)
  params = {}
  params['data'] = data if data
  post_json("/global_etchosts", params)
end

- (Object) set_peers_latencies(vnodes, matrix)

Configure latencies of peers from a matrix

Parameters:

  • ordered (Array)

    vnode names

  • matrix (Array)

    of latencies



664
665
666
667
668
669
# File 'lib/distem/netapi/client.rb', line 664

def set_peers_latencies(vnodes, matrix)
  params = {}
  params['vnodes'] = vnodes
  params['matrix'] = matrix
  post_json("/peers_matrix_latencies", params)
end

- (Hash) vcpu_create(vnodename, val, unit = 'mhz', corenb = 1)

Set up a virtual CPU on the virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • val (Float)

    The frequency defined as a value in MHz or as a ratio (percentage of the physical core frequency).

  • unit (String) (defaults to: 'mhz')

    Tell if val is a frequency or a ratio (allowed values are mhz and ration)

  • corenb (Integer) (defaults to: 1)

    The number of cores to allocate (need to have enough free ones on the physical node)

Returns:



450
451
452
453
# File 'lib/distem/netapi/client.rb', line 450

def vcpu_create(vnodename, val, unit='mhz', corenb=1)
  desc = { :corenb => corenb, :val => val, :unit => unit }
  post_json("/vnodes/#{CGI.escape(vnodename)}/cpu", { :desc => desc })
end

- (Hash) vcpu_info(vnodename)

Retrive information about a virtual node CPU

Returns:



477
478
479
# File 'lib/distem/netapi/client.rb', line 477

def vcpu_info(vnodename)
  get_json("/vnodes/#{CGI.escape(vnodename)}/cpu")
end

- (Hash) vcpu_remove(vnodename)

Removing a virtual CPU on the virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

Returns:



470
471
472
# File 'lib/distem/netapi/client.rb', line 470

def vcpu_remove(vnodename)
  delete_json("/vnodes/#{CGI.escape(vnodename)}/cpu")
end

- (Hash) vcpu_update(vnodename, val, unit = 'mhz')

Note:

This setting works on-the-fly (i.e. even if the virtual node is already running)

Update a virtual CPU on the virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • val (Float)

    The frequency defined as a value in MHz or as a ratio (percentage of the physical core frequency).

  • unit (String) (defaults to: 'mhz')

    Tell if val is a frequency or a ratio (allowed values are mhz and ration)

Returns:



461
462
463
464
# File 'lib/distem/netapi/client.rb', line 461

def vcpu_update(vnodename, val, unit='mhz')
  desc = { :val => val, :unit => unit }
  put_json("/vnodes/#{CGI.escape(vnodename)}/cpu", { :desc => desc })
end

- (Hash) vfilesystem_create(vnodename, desc)

Set up the filesystem of a virtual node

Parameters:

Returns:



486
487
488
# File 'lib/distem/netapi/client.rb', line 486

def vfilesystem_create(vnodename,desc)
  post_json("/vnodes/#{CGI.escape(vnodename)}/filesystem", { :desc => desc })
end

- (String) vfilesystem_image(vnodename, target = '.')

Retrieve compressed image (tgz) of the filesystem of a node.

Parameters:

  • vnodename (String)

    The name of the virtual node

  • target (String) (defaults to: '.')

    The path to save the file, if not specified, the current directory is used

Returns:

  • (String)

    The path where the compressed image was retrieved

Raises:



512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/distem/netapi/client.rb', line 512

def vfilesystem_image(vnodename,target = '.')
  target = '.' if !target
  raise Lib::ResourceNotFoundError, File.dirname(target) unless File.exist?(File.dirname(target))
  if File.directory?(target)
    target = File.join(target,"#{vnodename}-fsimage.tar.gz")
  end
  content = get_content("/vnodes/#{CGI.escape(vnodename)}/filesystem/image")

  File.open(target, 'w') { |f|
    f.syswrite(content)
  }
  target
end

- (Hash) vfilesystem_info(vnodename)

Retrieve informations about a virtual node filesystem

Parameters:

  • vnodename (String)

    The name of the virtual node

Returns:

  • (Hash)

    The virtual node filesystem informations



503
504
505
# File 'lib/distem/netapi/client.rb', line 503

def vfilesystem_info(vnodename)
  get_json("/vnodes/#{CGI.escape(vnodename)}/filesystem")
end

- (Hash) vfilesystem_update(vnodename, desc)

Update the filesystem of a virtual node

Parameters:

Returns:



495
496
497
# File 'lib/distem/netapi/client.rb', line 495

def vfilesystem_update(vnodename,desc)
  put_json("/vnodes/#{CGI.escape(vnodename)}/filesystem", { :desc => desc })
end

- (Hash) viface_create(vnodename, name, desc)

Create a virtual network interface on the virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • name (String)

    The name of the virtual network interface to be created (have to be unique on that virtual node)

  • desc (Hash)

    Hash structured as described in Resource Description - VIface.

Returns:



367
368
369
# File 'lib/distem/netapi/client.rb', line 367

def viface_create(vnodename, name, desc)
  post_json("/vnodes/#{CGI.escape(vnodename)}/ifaces", { :name => name, :desc => desc })
end

- (Hash) viface_info(vnodename, vifacename)

Retrieve informations about a virtual network interface associated to a virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

Returns:



439
440
441
# File 'lib/distem/netapi/client.rb', line 439

def viface_info(vnodename, vifacename)
  get_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}")
end

- (Hash) viface_remove(vnodename, vifacename)

Remove a virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the network virtual interface

Returns:



376
377
378
# File 'lib/distem/netapi/client.rb', line 376

def viface_remove(vnodename,vifacename)
  delete_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}")
end

- (Hash) viface_update(vnodename, vifacename, desc = {})

Note:

Disconnect (detach) the virtual network interface from any virtual network it's connected on if desc is empty

Update a virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VIface.

Returns:



388
389
390
# File 'lib/distem/netapi/client.rb', line 388

def viface_update(vnodename, vifacename, desc = {})
  put_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}", { :desc => desc })
end

- (Hash) vinput_info(vnodename, vifacename)

Retrive the traffic description on the input of a specified virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

Returns:



409
410
411
# File 'lib/distem/netapi/client.rb', line 409

def vinput_info(vnodename, vifacename)
  get_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}/input")
end

- (Hash) vinput_update(vnodename, vifacename, desc = {})

Note:

The vtraffic description is updated on-the-fly (even if the virtual node is running)

Note:

Reset the vtraffic description if desc is empty

Update the traffic description on the input of a specified virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VTraffic.

Returns:



400
401
402
# File 'lib/distem/netapi/client.rb', line 400

def vinput_update(vnodename, vifacename, desc = {})
  put_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}/input", { :desc => desc })
end

- (Hash) vmem_create(vnodename, mem, swap = nil)

Create a new memory limitation

Parameters:

  • mem (String)

    The required amount of RAM

  • swap (String) (defaults to: nil)

    The required amount of swap

Returns:

  • (Hash)

    The memory limitation



685
686
687
688
# File 'lib/distem/netapi/client.rb', line 685

def vmem_create(vnodename, mem, swap = nil)
  desc = { :mem => mem, :swap => swap}
  post_json("/vnodes/#{CGI.escape(vnodename)}/vmem", { :desc => desc })
end

- (Hash) vnetwork_create(name, address, opts = nil)

Create a new virtual network

Parameters:

  • name (String)

    The name of the virtual network (unique)

  • address (String)

    The address (CIDR format: 10.0.8.0/24) the virtual network will work with

  • options (Hash)

    used to store vxlan_id and number of pnodes (should not be used directly)

Returns:



532
533
534
535
536
# File 'lib/distem/netapi/client.rb', line 532

def vnetwork_create(name, address, opts = nil)
  desc = { :name => name, :address => address }
  desc[:opts] = opts if opts
  post_json('/vnetworks', desc)
end

- (Object) vnetwork_create_routing_interface(address, netmask)

Create a routing interface on a PNode (Should not be called directly)

Parameters:

  • address (String)

    The address of the interface

  • netmask (String)

    The netmask of the interface



541
542
543
# File 'lib/distem/netapi/client.rb', line 541

def vnetwork_create_routing_interface(address, netmask)
  put_json('/vnetworks', {:address => address, :netmask => netmask})
end

- (Hash) vnetwork_info(vnetname)

Retrieve informations about a virtual network

Parameters:

  • vnetname (String)

    The name of the virtual network

Returns:



557
558
559
# File 'lib/distem/netapi/client.rb', line 557

def vnetwork_info(vnetname)
  get_json("/vnetworks/#{CGI.escape(vnetname)}")
end

- (Hash) vnetwork_remove(vnetname)

Remove a virtual network, that will disconnect every virtual node connected on it and remove it's virtual routes.

Parameters:

  • vnetname (String)

    The name of the virtual network

Returns:



549
550
551
# File 'lib/distem/netapi/client.rb', line 549

def vnetwork_remove(vnetname)
  delete_json("/vnetworks/#{CGI.escape(vnetname)}")
end

- (Array) vnetworks_info

Retrieve informations about every virtual network currently set on the platform

Returns:



570
571
572
# File 'lib/distem/netapi/client.rb', line 570

def vnetworks_info()
  get_json("/vnetworks")
end

- (Array) vnetworks_remove

Remove every virtual network

Returns:



564
565
566
# File 'lib/distem/netapi/client.rb', line 564

def vnetworks_remove()
  delete_json("/vnetworks")
end

- (Hash) vnode_create(name, desc = {}, ssh_key = {}, async = false)

Create a new virtual node

Parameters:

  • name (String)

    The name of the virtual node which should be unique

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VNodes.

  • ssh_key (Hash) (defaults to: {})

    SSH key pair to be copied on the virtual node (also adding the public key to .ssh/authorized_keys). Note that every SSH keys located on the physical node which hosts this virtual node are also copied in .ssh/ directory of the node (copied key have a specific filename prefix). The key are copied in .ssh/ directory of SSH user (see Daemon::Admin#SSH_USER and Distem::Node::Container::SSH_KEY_FILENAME)

    Format: Hash.

    Structure:

    {
      "public" : "KEYHASH",
      "private" : "KEYHASH"
    }

    Both of public and private parameters are optional

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



163
164
165
# File 'lib/distem/netapi/client.rb', line 163

def vnode_create(name, desc = {}, ssh_key={}, async=false)
  post_json("/vnodes/#{CGI.escape(name)}", { :desc => desc, :ssh_key => ssh_key, :async => async })
end

- (String) vnode_execute(vnodename, command)

Execute and get the result of a command on a virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • command (String)

    The command to be executed

Returns:

  • (String)

    The result of the command (Array of string if multilines)



348
349
350
# File 'lib/distem/netapi/client.rb', line 348

def vnode_execute(vnodename, command)
  post_json("/vnodes/#{CGI.escape(vnodename)}/commands", { :command => command })
end

- (Hash) vnode_freeze(vnodename, async = false)

Freeze a virtual node, but without deleting its data

Parameters:

  • vnodename (String)

    The name of the virtual node

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



296
297
298
# File 'lib/distem/netapi/client.rb', line 296

def vnode_freeze(vnodename, async=false)
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :async => async, :type => 'freeze'})
end

- (Hash) vnode_info(vnodename)

Retrieve informations about a virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

Returns:



219
220
221
# File 'lib/distem/netapi/client.rb', line 219

def vnode_info(vnodename)
  get_json("/vnodes/#{CGI.escape(vnodename)}")
end

- (Hash) vnode_mode(vnodename, gateway = true)

Set the mode of a virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

  • gateway (Boolean) (defaults to: true)

    Gateway mode: add the ability to forward traffic

Returns:



331
332
333
334
# File 'lib/distem/netapi/client.rb', line 331

def vnode_mode(vnodename,gateway=true)
  desc = { :mode => gateway ? Resource::VNode::MODE_GATEWAY : Resource::VNode::MODE_NORMAL }
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :desc => desc, :type => 'update' })
end

- (Hash) vnode_remove(vnodename)

Note:

“Cascade” removing: remove all the vroutes in which this virtual node apears as gateway

Remove the virtual node

Parameters:

  • vnodename (String)

    The name of the virtual node

Returns:



182
183
184
# File 'lib/distem/netapi/client.rb', line 182

def vnode_remove(vnodename)
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :type => 'remove'})
end

- (Hash) vnode_start(vnodename, async = false)

Note:

A physical node (that have enought physical resources (CPU,…)) will be automatically allocated if there is none set as host at the moment

Note:

The filesystem archive will be copied on the hosting physical node.

Note:

A filesystem image must have been set (see #vnode_create or #vfilesystem_create/#vfilesystem_update).

Start a virtual node.

Parameters:

  • vnodename (String)

    The name of the virtual node

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



232
233
234
235
# File 'lib/distem/netapi/client.rb', line 232

def vnode_start(vnodename, async=false)
  desc = { :status => Resource::Status::RUNNING }
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :desc => desc, :async => async, :type => 'update' })
end

- (Hash) vnode_start!(vnodename)

Same as #vnode_start but in asynchronious mode

Returns:



240
241
242
# File 'lib/distem/netapi/client.rb', line 240

def vnode_start!(vnodename)
  return vnode_start(vnodename,true)
end

- (Hash) vnode_stop(vnodename, async = false)

Note:

The host association for this virtual node will be cancelled, if you start the virtual node directcly after stopping it, the hosting physical node will be chosen randomly (to set it manually, see host field, #vnode_update)

Stopping a virtual node, deleting it's data from the hosting physical node.

Parameters:

  • vnodename (String)

    The name of the virtual node

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



271
272
273
274
# File 'lib/distem/netapi/client.rb', line 271

def vnode_stop(vnodename, async=false)
  desc = { :status => Resource::Status::DOWN }
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :desc => desc, :async => async, :type => 'stop' })
end

- (Hash) vnode_stop!(vnodename)

Same as #vnode_stop but in asynchronious mode

Returns:



279
280
281
# File 'lib/distem/netapi/client.rb', line 279

def vnode_stop!(vnodename)
  return vnode_stop(vnodename, true)
end

- (Hash) vnode_unfreeze(vnodename, async = false)

Unfreeze a virtual node, but without deleting its data

Parameters:

  • vnodename (String)

    The name of the virtual node

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



314
315
316
# File 'lib/distem/netapi/client.rb', line 314

def vnode_unfreeze(vnodename, async=false)
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :async => async, :type => 'unfreeze'})
end

- (Hash) vnode_update(vnodename, desc = {}, async = false)

Update a virtual node description

Parameters:

  • vnodename (String)

    The name of the virtual node

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VNodes.

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



201
202
203
# File 'lib/distem/netapi/client.rb', line 201

def vnode_update(vnodename, desc = {}, async=false)
  put_json("/vnodes/#{CGI.escape(vnodename)}", { :desc => desc, :async => async, :type => 'update' })
end

- (Array) vnodes_create(names, desc = {}, ssh_key = {}, async = false)

Create new virtual nodes

Parameters:

  • names (Array)

    The names of the virtual nodes which should be unique

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VNodes.

  • ssh_key (Hash) (defaults to: {})

    SSH key pair to be copied on the virtual node (also adding the public key to .ssh/authorized_keys). Note that every SSH keys located on the physical node which hosts this virtual node are also copied in .ssh/ directory of the node (copied key have a specific filename prefix). The key are copied in .ssh/ directory of SSH user (see Daemon::Admin#SSH_USER and Distem::Node::Container::SSH_KEY_FILENAME)

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



173
174
175
# File 'lib/distem/netapi/client.rb', line 173

def vnodes_create(names, desc = {}, ssh_key={}, async=false)
  post_json('/vnodes', { :names => names , :desc => desc, :ssh_key => ssh_key, :async => async })
end

- (Hash) vnodes_execute(names, command)

Execute and get the result of a command on a set of virtual nodes

Parameters:

  • names (Array)

    Array of virtual nodes

  • command (String)

    The command to be executed

Returns:

  • (Hash)

    The result of the command (one entry by vnode)



357
358
359
# File 'lib/distem/netapi/client.rb', line 357

def vnodes_execute(names, command)
  post_json("/commands", { :names => names, :command => command })
end

- (Array) vnodes_freeze(names = nil, async = false)

Freeze some virtual nodes

Parameters:

  • names (Array) (defaults to: nil)

    The names of the virtual nodes

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



305
306
307
# File 'lib/distem/netapi/client.rb', line 305

def vnodes_freeze(names = nil, async=false)
  put_json("/vnodes", { :names => names, :async => async, :type => 'freeze' })
end

- (Array) vnodes_info

Retrieve informations about every virtual nodes currently set on the platform

Returns:



339
340
341
# File 'lib/distem/netapi/client.rb', line 339

def vnodes_info()
  get_json("/vnodes")
end

- (Array) vnodes_remove(names = nil)

Remove the virtual vnodes, or every if names is nil

Returns:



189
190
191
192
193
# File 'lib/distem/netapi/client.rb', line 189

def vnodes_remove(names = nil)
  params = { :type => 'remove'}
  params[:names] = names if names
  put_json("/vnodes", params)
end

- (Hash) vnodes_start(names, async = false)

Note:

A physical node (that have enought physical resources (CPU,…)) will be automatically allocated if there is none set as host at the moment

Note:

The filesystem archive will be copied on the hosting physical node.

Note:

A filesystem image must have been set (see #vnode_create or #vfilesystem_create/#vfilesystem_update).

Start several virtual nodes

Parameters:

  • names (Array)

    The names of the virtual nodes

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual nodes status to know when node is configured (see #vnode_info)

Returns:



253
254
255
256
# File 'lib/distem/netapi/client.rb', line 253

def vnodes_start(names, async=false)
  desc = { :status => Resource::Status::RUNNING }
  put_json('/vnodes', { :names => names , :desc => desc, :async => async, :type => 'update' })
end

- (Hash) vnodes_start!(names)

Same as #vnodes_start but in asynchronious mode

Returns:



261
262
263
# File 'lib/distem/netapi/client.rb', line 261

def vnodes_start!(names)
  return vnodes_start(names,true)
end

- (Hash) vnodes_stop(names = nil, async = false)

Stop given virtal nodes

Parameters:

  • names (Array) (defaults to: nil)

    The name of the virtual nodes

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:

  • (Hash)

    The description of the virtual nodes



287
288
289
# File 'lib/distem/netapi/client.rb', line 287

def vnodes_stop(names = nil, async=false)
  put_json("/vnodes", { :names => names, :async => async, :type => 'stop' })
end

- (Array) vnodes_unfreeze(names = nil, async = false)

Unfreeze some virtual nodes

Parameters:

  • names (Array) (defaults to: nil)

    The names of the virtual nodes

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



323
324
325
# File 'lib/distem/netapi/client.rb', line 323

def vnodes_unfreeze(names = nil, async=false)
  put_json("/vnodes", { :names => names, :async => async, :type => 'unfreeze' })
end

- (Hash) vnodes_update(name, desc = {}, async = false)

Update several virtual node descriptions

Parameters:

  • names (Array)

    The names of the virtual node

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VNodes.

  • async (Boolean) (defaults to: false)

    Asynchronious mode, check virtual node status to know when node is configured (see #vnode_info)

Returns:



211
212
213
# File 'lib/distem/netapi/client.rb', line 211

def vnodes_update(name, desc = {}, async=false)
  put('/vnodes', { :name => name, :desc => desc, :async => async, :type => 'update' })
end

- (Hash) voutput_info(vnodename, vifacename)

Retrive the traffic description on the output of a specified virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

Returns:



430
431
432
# File 'lib/distem/netapi/client.rb', line 430

def voutput_info(vnodename, vifacename)
  get_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}/output")
end

- (Hash) voutput_update(vnodename, vifacename, desc = {})

Note:

The vtraffic description is updated on-the-fly (even if the virtual node is running)

Note:

Reset the vtraffic description if desc is empty

Update the traffic description on the output of a specified virtual network interface

Parameters:

  • vnodename (String)

    The name of the virtual node

  • vifacename (String)

    The name of the virtual network interface

  • desc (Hash) (defaults to: {})

    Hash structured as described in Resource Description - VTraffic.

Returns:



421
422
423
# File 'lib/distem/netapi/client.rb', line 421

def voutput_update(vnodename, vifacename, desc = {})
  put_json("/vnodes/#{CGI.escape(vnodename)}/ifaces/#{CGI.escape(vifacename)}/output", { :desc => desc })
end

- (Hash) vplatform_create(data, format = 'JSON', rootfs = nil)

Create an set a platform with backup data

Parameters:

  • format (String) (defaults to: 'JSON')

    The input data format

  • data (String)

    Data structured as described in resources_desc.

  • rootfs (String) (defaults to: nil)

    The rootfs to boot vnodes

Returns:



597
598
599
# File 'lib/distem/netapi/client.rb', line 597

def vplatform_create(data,format = 'JSON',rootfs = nil)
  post_json("/vplatform", { 'format' => format, 'data' => data, 'rootfs' => rootfs })
end

- (String) vplatform_info

Get the full description of the platform

Returns:

  • (String)

    The description in the wished format



604
605
606
607
# File 'lib/distem/netapi/client.rb', line 604

def vplatform_info()
  ret = get_json("/vplatform")
  return JSON.pretty_generate(ret)
end

- (Array) vroute_complete

Create all possible virtual routes between all the virtual networks, automagically choosing the virtual nodes to use as gateways

Returns:



588
589
590
# File 'lib/distem/netapi/client.rb', line 588

def vroute_complete()
  post_json("/vnetworks/routes/complete", { })
end

- (Hash) vroute_create(srcnet, dstnet, gateway)

Create a new virtual route between two virtual networks (“<dstnet> is accessible from <srcnet> using <gateway>”)

Parameters:

  • srcnet (String)

    The name of the source virtual network

  • dstnet (String)

    The name of the destination virtual network

  • gateway (String)

    The name of the virtual node to use as gateway (this node have to be connected on both of the previously mentioned networks), the node is automatically set in gateway mode

Returns:



580
581
582
583
# File 'lib/distem/netapi/client.rb', line 580

def vroute_create(srcnet,dstnet,gateway)
  post_json("/vnetworks/#{CGI.escape(srcnet)}/routes",
    { :destnetwork => dstnet, :gatewaynode => gateway })
end

- (Object) wait_vnodes(opts = {})

Wait a set of vnodes (or all) by checking that a given port (22 by default) is open. Should not be used directly after vnode_start! or vnodes_start!

Parameters:

  • Options. (Hash)

    Format is {'vnodes' => vnodes, 'timeout' => timeout, 'port' => port }. vnodes can be a single node (String) or several nodes (Array), if not specified, all the vnodes are considered. timeout is an integer value specified in seconds, if not specified the default value is 600 seconds. port is an integer value, if not specified the default value is 22 (SSH port).

Returns:

  • true if the vnodes are ready or false if the timeout has been reached



705
706
707
# File 'lib/distem/netapi/client.rb', line 705

def wait_vnodes(opts = {})
  return (post_json('/wait_vnodes', {'opts' => opts}) == ['true'])
end