Class: Distem::NetAPI::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/distem/netapi/server.rb

Overview

Note:

Every method of the REST API should return HTTP Status following this rule:

  • 200: OK

  • 400: Parameter error

  • 404: Resource error

  • 500: Shell error (check the logs)

  • 501: Not implemented yet

In addition, the HTTP Header 'X-Application-Error-Code' contains more informations about a specific error

Note:

Default return HTTP Content-Types is application/json

Note:

desc query parameters should be in JSON hashtables format. Also, Every HTTP/POST parameter is optional by default (it's specified in the documentation otherwise).

Note:

For desc query parameters, the only elements in the structure (JSON 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.

Note:

In this page, in routes/paths described such as /resource/:name, :name should be remplaced by a value that describe the resource to target (sample: /resource/test). Also, in routes/paths, the '?' char means that the precedent char -in the path- is optional, so /resource/? means that the resource should be access either by the routes/paths /resource and /resource/ .

Note:

Returned data are JSON Hash of the corresponding object described in Resources Description.

Direct Known Subclasses

CoordinatorServer, PnodeServer

Constant Summary

HTTP_HEADER_ERR =
'X-Application-Error-Code'
HTTP_STATUS_OK =
200
HTTP_STATUS_NOT_FOUND =
404
HTTP_STATUS_BAD_REQUEST =
400
HTTP_STATUS_INTERN_SERV_ERROR =
500
HTTP_STATUS_NOT_IMPLEMENTED =
501

Instance Method Summary (collapse)

Constructor Details

- (Server) initialize

Returns a new instance of Server



50
51
52
# File 'lib/distem/netapi/server.rb', line 50

def initialize()
  super
end

Instance Method Details

- (Object) check

Try to catch and wrapp every kind of exception



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/distem/netapi/server.rb', line 79

def check
  # >>> FIXME: remove retries hack
#        retries = 2
  begin
    yield
  rescue JSON::ParserError, Lib::ParameterError => pe
    @status = HTTP_STATUS_BAD_REQUEST
    @headers[HTTP_HEADER_ERR] = get_http_err_desc(pe)
=begin
  rescue Lib::ResourceNotFoundError, Lib::BusyResourceError => re
    if retries >= 0
      sleep(0.5)
      retries -= 1
      retry
    else
      @status = HTTP_STATUS_NOT_FOUND
      @headers[HTTP_HEADER_ERR] = get_http_err_desc(re)
    end
=end
  rescue Lib::ResourceError => re
    @status = HTTP_STATUS_NOT_FOUND
    @headers[HTTP_HEADER_ERR] = get_http_err_desc(re)
  rescue Lib::NotImplementedError => ni
    @status = HTTP_STATUS_NOT_IMPLEMENTED
    @headers[HTTP_HEADER_ERR] = get_http_err_desc(ni)
  rescue Lib::ShellError => se
    @status = HTTP_STATUS_INTERN_SERV_ERROR
    @headers[HTTP_HEADER_ERR] = get_http_err_desc(se)
  rescue Lib::ClientError => ce
    @status = ce.num
    @headers[HTTP_HEADER_ERR] = ce.desc
    @body = ce.body
  end
end

- (Object) DELETE '/eventmanager/?'

Stop the event manager and clear the event list



780
781
782
783
784
785
# File 'lib/distem/netapi/server.rb', line 780

delete '/eventmanager/?' do
  check do
    @daemon.event_manager_stop
    @body = ""
  end
end

- (Object) DELETE '/pnodes/?'

Quit distem on all the physical machines (remove everything that was created)



210
211
212
213
214
215
216
# File 'lib/distem/netapi/server.rb', line 210

delete '/pnodes/?' do
  check do
    @body = @daemon.pnodes_quit()
  end

  return result!
end

- (Object) DELETE '/pnodes/:pnode/?'

Quit distem on a physical machine (remove everything that was created)



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/distem/netapi/server.rb', line 197

delete '/pnodes/:pnode/?' do
  check do
    @body = @daemon.pnode_quit(params['pnode'])
  end

  Thread.new {
    sleep 2
    exit!
  }
  return result!
end

- (Object) DELETE '/pnodes/probes'

Delete the probes



149
150
151
152
153
154
# File 'lib/distem/netapi/server.rb', line 149

delete '/pnodes/probes' do
  check do
    @daemon.pnodes_delete_probes()
    @body = ""
  end
end

- (Object) DELETE '/vnetworks/?'

Delete every virtual networks



647
648
649
650
651
652
653
# File 'lib/distem/netapi/server.rb', line 647

delete '/vnetworks/?' do
  check do
    @body = @daemon.vnetworks_remove()
  end

  return result!
end

- (Object) DELETE '/vnetworks/:vnetname/?'

Delete the virtual network



629
630
631
632
633
634
635
# File 'lib/distem/netapi/server.rb', line 629

delete '/vnetworks/:vnetname/?' do
  check do
    @body = @daemon.vnetwork_remove(CGI.unescape(params['vnetname']))
  end

  return result!
end

- (Object) DELETE '/vnodes/:vnodename/cpu/?'

Remove virtual CPU of a virtual node



567
568
569
570
571
572
573
# File 'lib/distem/netapi/server.rb', line 567

delete '/vnodes/:vnodename/cpu/?' do
  check do
    @body = @daemon.vcpu_remove(CGI.unescape(params['vnodename']))
  end

  return result!
end

- (Object) DELETE '/vnodes/:vnodename/ifaces/:ifacename/?'

Remove a specified virtual network interface



452
453
454
455
456
457
458
459
# File 'lib/distem/netapi/server.rb', line 452

delete '/vnodes/:vnodename/ifaces/:ifacename/?' do
  check do
    @body = @daemon.viface_remove(CGI.unescape(params['vnodename']),
      CGI.unescape(params['ifacename']))
  end

  return result!
end

- (Object) GET '/pnodes/?'

Get the list of the the currently created physical nodes



219
220
221
222
223
224
225
# File 'lib/distem/netapi/server.rb', line 219

get '/pnodes/?' do
  check do
    @body = @daemon.pnodes_get()
  end

  return result!
end

- (Object) GET '/pnodes/:pnode/?'

Get the description of a physical node



174
175
176
177
178
179
180
# File 'lib/distem/netapi/server.rb', line 174

get '/pnodes/:pnode/?' do
  check do
    @body = @daemon.pnode_get(params['pnode'])
  end

  return result!
end

- (Object) GET '/pnodes/:pnode/cpu/?'

Get the description of the CPU of a physical node



228
229
230
231
232
233
234
# File 'lib/distem/netapi/server.rb', line 228

get '/pnodes/:pnode/cpu/?' do
  check do
    @body = @daemon.pcpu_get(params['pnode'])
  end

  return result!
end

- (Object) GET '/pnodes/:pnode/memory/?'

Get the description of the memory of a physical node



237
238
239
240
241
242
243
# File 'lib/distem/netapi/server.rb', line 237

get '/pnodes/:pnode/memory/?' do
  check do
    @body = @daemon.pmemory_get(params['pnode'])
  end

  return result!
end

- (Object) GET '/pnodes/probes'

Get the data collected from the probes



141
142
143
144
145
146
# File 'lib/distem/netapi/server.rb', line 141

get '/pnodes/probes' do
  check do
    @body = @daemon.pnodes_get_probes_data().to_json
  end
  return result!
end

- (Object) GET '/vnetworks/?'

Get the list of the the currently created virtual networks



656
657
658
659
660
661
662
# File 'lib/distem/netapi/server.rb', line 656

get '/vnetworks/?' do
  check do
    @body = @daemon.vnetworks_get()
  end

  return result!
end

- (Object) GET '/vnetworks/:vnetname/?'

Get the description of a virtual network



638
639
640
641
642
643
644
# File 'lib/distem/netapi/server.rb', line 638

get '/vnetworks/:vnetname/?' do
  check do
    @body = @daemon.vnetwork_get(CGI.unescape(params['vnetname']))
  end

  return result!
end

- (Object) GET '/vnodes/?'

Get the list of the the currently created virtual nodes



293
294
295
296
297
298
299
# File 'lib/distem/netapi/server.rb', line 293

get '/vnodes/?' do
  check do
    @body = @daemon.vnodes_get_info()
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/?'

Get the description of a virtual node



284
285
286
287
288
289
290
# File 'lib/distem/netapi/server.rb', line 284

get '/vnodes/:vnodename/?' do
  check do
    @body = @daemon.vnode_get_info(CGI.unescape(params['vnodename']))
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/cpu/?'

Get the description of the virtual CPU associated with a virtual node



592
593
594
595
596
597
598
# File 'lib/distem/netapi/server.rb', line 592

get '/vnodes/:vnodename/cpu/?' do
  check do
    @body = @daemon.vcpu_get(CGI.unescape(params['vnodename']))
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/filesystem/?'

Retrieve informations about the virtual node filesystem



389
390
391
392
393
394
395
# File 'lib/distem/netapi/server.rb', line 389

get '/vnodes/:vnodename/filesystem/?' do
  check do
    @body = @daemon.vfilesystem_get(CGI.unescape(params['vnodename']))
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/filesystem/image/?'

Get a compressed archive of the current filesystem (tgz)

Important: You have to contact the physical node the vnode is hosted on directly



400
401
402
403
404
405
# File 'lib/distem/netapi/server.rb', line 400

get '/vnodes/:vnodename/filesystem/image/?' do
  check do
    @body = @daemon.vfilesystem_image(CGI.unescape(params['vnodename']))
    send_file(@body, :filename => "#{params['vnodename']}-fsimage.tar.gz")
  end
end

- (Object) GET '/vnodes/:vnodename/ifaces/:ifacename/?'

Get the description of a virtual network interface



462
463
464
465
466
467
468
469
# File 'lib/distem/netapi/server.rb', line 462

get '/vnodes/:vnodename/ifaces/:ifacename/?' do
  check do
    @body = @daemon.viface_get(CGI.unescape(params['vnodename']),
      CGI.unescape(params['ifacename']))
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/ifaces/:ifacename/input/?'

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



493
494
495
496
497
498
499
500
501
# File 'lib/distem/netapi/server.rb', line 493

get '/vnodes/:vnodename/ifaces/:ifacename/input/?' do
  check do
    vnodename = CGI.unescape(params['vnodename'])
    vifacename = CGI.unescape(params['ifacename'])
    @body = @daemon.vinput_get(vnodename,vifacename)
  end

  return result!
end

- (Object) GET '/vnodes/:vnodename/ifaces/:ifacename/output/?'

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



523
524
525
526
527
528
529
530
531
# File 'lib/distem/netapi/server.rb', line 523

get '/vnodes/:vnodename/ifaces/:ifacename/output/?' do
  check do
    vnodename = CGI.unescape(params['vnodename'])
    vifacename = CGI.unescape(params['ifacename'])
    @body = @daemon.voutput_get(vnodename,vifacename)
  end

  return result!
end

- (Object) GET '/vplatform'

Get the description file of the current platform in a specified format (JSON if not specified)



697
698
699
700
701
702
703
# File 'lib/distem/netapi/server.rb', line 697

get '/vplatform' do
  check do
    @body = @daemon.vplatform_get()
  end

  return result!
end

- (Object) NOT_FOUND

Return server resource error



72
73
74
75
# File 'lib/distem/netapi/server.rb', line 72

not_found do
  #response.headers[HTTP_HEADER_ERR] = \
    "ServerResourceError #{request.request_method} #{request.url}"
end

- (Object) POST '/commands/?'

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

Query parameters:

  • names – Array of virtual nodes

  • command – The command to be executed



427
428
429
430
431
432
433
# File 'lib/distem/netapi/server.rb', line 427

post '/commands/?' do
  check do
    @body = @daemon.vnodes_execute(JSON.parse(params['names']), params['command'])
  end

  return result!
end

- (Object) POST '/eventmanager/?'

Start the event manager



770
771
772
773
774
775
776
777
# File 'lib/distem/netapi/server.rb', line 770

post '/eventmanager/?' do
  check do
    @daemon.event_manager_start
    @body = ""
  end

  return result!
end

- (Object) POST '/events/random/?'

Add a random generated event to a resource



755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/distem/netapi/server.rb', line 755

post '/events/random/?' do
  check do
    generator_desc = {}
    generator_desc = JSON.parse(params['generator']) if params['generator']
    resource_desc = {}
    resource_desc = JSON.parse(params['resource']) if params['resource']
    event_type = CGI.unescape(params['event_type'])
    first_value = nil
    first_value = CGI.unescape(params['first_value']) if params['first_value']
    @daemon.event_random_add(resource_desc, event_type, generator_desc, first_value)
    @body = ""
  end
end

- (Object) POST '/events/trace/?'

Add a event trace to a resource



731
732
733
734
735
736
737
738
739
740
741
# File 'lib/distem/netapi/server.rb', line 731

post '/events/trace/?' do
  check do
    trace = {}
    trace = JSON.parse(params['trace']) if params['trace']
    resource_desc = {}
    resource_desc = JSON.parse(params['resource']) if params['resource']
    event_type = CGI.unescape(params['event_type'])
    @daemon.event_trace_add(resource_desc, event_type, trace)
    @body = ""
  end
end

- (Object) POST '/events/trace_string/?'

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



744
745
746
747
748
749
750
751
752
# File 'lib/distem/netapi/server.rb', line 744

post '/events/trace_string/?' do
  check do
    trace_string = CGI.unescape(params['trace_string'])
    resource_desc = JSON.parse(params['resource']) if params['resource']
    event_type = CGI.unescape(params['event_type'])
    @daemon.event_trace_string_add(resource_desc, event_type, trace_string)
    @body = ""
  end
end

- (Object) POST '/global_arptable/?'



812
813
814
815
816
817
818
819
# File 'lib/distem/netapi/server.rb', line 812

post '/global_arptable/?' do
  check do
    data = params.has_key?('data') ? params['data'] : nil
    arp_file = params.has_key?('arp_file') ? params['arp_file'] : nil
    @daemon.set_global_arptable(data, arp_file)
    @body = ""
  end
end

- (Object) POST '/global_etchosts/?'



794
795
796
797
798
799
800
# File 'lib/distem/netapi/server.rb', line 794

post '/global_etchosts/?' do
  check do
    data = params.has_key?('data') ? params['data'] : nil
    @daemon.set_global_etchosts(data)
    @body = ""
  end
end

- (Object) POST '/peers_matrix_latencies/?'



787
788
789
790
791
792
# File 'lib/distem/netapi/server.rb', line 787

post '/peers_matrix_latencies/?' do
  check do
    vnodes = (params['vnodes'] == "") ? nil : JSON.parse(params['vnodes'])
    @body = @daemon.set_peers_latencies(vnodes, JSON.parse(params['matrix']))
  end
end

- (Object) POST '/pnodes/?'

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

Query parameters:

  • targetmandatory – The name/address of the physical machine

  • desc – JSON Hash structured as described in Resource Description - PNode.

  • async – Asynchronious mode, check the physical node status to know when the configuration is done (see GET /pnodes/:pnode)



163
164
165
166
167
168
169
170
171
# File 'lib/distem/netapi/server.rb', line 163

post '/pnodes/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    target = (params['target'] == "") ? nil : JSON.parse(params['target'])
    @body = @daemon.pnode_create(target,desc,params['async'])
  end
  return result!
end

- (Object) POST '/pnodes/probes'

Launch a set of probes on the physical nodes. Physical nodes have to initialized before doing that

Query parameters:

  • desc – JSON Hash structured as follows: { 'probe1_type' => { 'name' => probe1_name, 'frequency' => freq, …}}}



119
120
121
122
123
124
125
126
# File 'lib/distem/netapi/server.rb', line 119

post '/pnodes/probes' do
  check do
    desc = JSON.parse(params['desc'])
    ref_time = params.has_key?('ref_time') ? params['ref_time'] : nil
    @daemon.pnodes_launch_probes(desc, ref_time)
    @body = ""
  end
end

- (Object) POST '/vnetworks/?'

Create a new virtual network specifying his range of IP address (IPv4 atm).

Query parameters:

  • name – the -unique- name of the virtual network (it will be used in a lot of methods)

  • address – the address in the CIDR (10.0.0.1/24) or IP/NetMask (10.0.0.1/255.255.255.0) format



606
607
608
609
610
611
612
613
# File 'lib/distem/netapi/server.rb', line 606

post '/vnetworks/?' do
  check do
    opts = params.has_key?('opts') ? JSON.parse(params['opts']) : nil
    @body = @daemon.vnetwork_create(params['name'],params['address'],opts)
  end

  return result!
end

- (Object) POST '/vnetworks/:vnetname/routes/?'

Create a virtual route (“go from <networkname> to <destnetwork> via <gatewaynode>”). The virtual route is applied to all the vnodes of <networkname>. This method automagically set <gatewaynode> in gateway mode (if it's not already the case) and find the right virtual interface to set the virtual route on

Query parameters:

  • destnetwork – the name of the destination network

  • gatewaynode – the name of the virtual node to use as a gateway



672
673
674
675
676
677
678
679
680
681
682
# File 'lib/distem/netapi/server.rb', line 672

post '/vnetworks/:vnetname/routes/?' do
  check do
    @body = @daemon.vroute_create(
      CGI.unescape(params['vnetname']),
      params['destnetwork'],
      params['gatewaynode']
    )
  end

  return result!
end

- (Object) POST '/vnetworks/routes/complete/?'

Try to create every possible virtual routes between the current set of virtual nodes automagically finding and setting up the gateways to use



688
689
690
691
692
693
694
# File 'lib/distem/netapi/server.rb', line 688

post '/vnetworks/routes/complete/?' do
  check do
    @body = @daemon.vroute_complete()
  end

  return result!
end

- (Object) POST '/vnodes/?'

Create several virtual node

Query parameters:

  • namesmandatory, unique – The names of the virtual nodes to create (it will be used in a lot of methods)

  • desc – JSON Hash structured as described in Resource Description - VNode.

  • ssh_key – JSON Hash structured as described in Resource Description - SSH Key.

  • async – Asynchronious mode, check virtual node status to know when node is configured (see GET /vnodes/:vnode)



271
272
273
274
275
276
277
278
279
280
281
# File 'lib/distem/netapi/server.rb', line 271

post '/vnodes/?' do
  check do
    desc = {}
    ssh_key = {}
    desc = JSON.parse(params['desc']) if params['desc']
    ssh_key = JSON.parse(params['ssh_key']) if params['ssh_key']
    @body = @daemon.vnode_create(JSON.parse(params['names']), desc, ssh_key, params['async'])
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/?'

Create a new virtual node

Query parameters:

  • namemandatory, unique – The unique name of the virtual node to create (it will be used in a lot of methods)

  • desc – JSON Hash structured as described in Resource Description - VNode.

  • ssh_key – JSON Hash structured as described in Resource Description - SSH Key.

  • async – Asynchronious mode, check virtual node status to know when node is configured (see GET /vnodes/:vnode)



252
253
254
255
256
257
258
259
260
261
262
# File 'lib/distem/netapi/server.rb', line 252

post '/vnodes/:vnodename/?' do
  check do
    desc = {}
    ssh_key = {}
    desc = JSON.parse(params['desc']) if params['desc']
    ssh_key = JSON.parse(params['ssh_key']) if params['ssh_key']
    @body = @daemon.vnode_create(CGI.unescape(params['vnodename']), desc, ssh_key, params['async']).first
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/commands/?'

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

Query parameters:

  • command – The command to be executed



412
413
414
415
416
417
418
419
420
# File 'lib/distem/netapi/server.rb', line 412

post '/vnodes/:vnodename/commands/?' do
  check do
    r = @daemon.vnode_execute(CGI.unescape(params['vnodename']),
                              params['command'])
    @body = (r ? r.split("\n") : [])
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/cpu/?'

Create a new virtual cpu on the targeted virtual node. By default all the virtual nodes on a same physical one are sharing available CPU resources, using this method you can allocate some cores to a virtual node and apply some limitations on them

Query parameters:



556
557
558
559
560
561
562
563
564
# File 'lib/distem/netapi/server.rb', line 556

post '/vnodes/:vnodename/cpu/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vcpu_create(CGI.unescape(params['vnodename']),desc)
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/filesystem/?'

Set up the virtual node filesystem

Query parameters:



363
364
365
366
367
368
369
370
371
# File 'lib/distem/netapi/server.rb', line 363

post '/vnodes/:vnodename/filesystem/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vfilesystem_create(CGI.unescape(params['vnodename']),desc)
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/ifaces/?'

Create a new virtual interface on the targeted virtual node The IP address is auto assigned to the virtual interface if not specified

Query parameters:

  • name – the name of the virtual interface (need to be unique on this virtual node)

  • desc – JSON Hash structured as described in Resource Description - VIface.



441
442
443
444
445
446
447
448
449
# File 'lib/distem/netapi/server.rb', line 441

post '/vnodes/:vnodename/ifaces/?' do
  check do
    desc = {}
      desc = JSON.parse(params['desc']) if params['desc']
      @body = @daemon.viface_create(CGI.unescape(params['vnodename']),params['name'],desc)
  end

  return result!
end

- (Object) POST '/vnodes/:vnodename/vmem/?'



802
803
804
805
806
807
808
809
810
# File 'lib/distem/netapi/server.rb', line 802

post '/vnodes/:vnodename/vmem/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vmem_create(params['vnodename'],desc)
  end

  return result!
end

- (Object) POST '/wait_vnodes/?'



821
822
823
824
825
826
827
# File 'lib/distem/netapi/server.rb', line 821

post '/wait_vnodes/?' do
  check do
    opts = params.has_key?('opts') ? JSON.parse(params['opts']) : {}
    @body = @daemon.wait_vnodes(opts)
  end
  return result!
end

- (Object) PUT '/pnodes/:pnode/?'

Update a physical machine configuration

Query parameters:



186
187
188
189
190
191
192
193
194
# File 'lib/distem/netapi/server.rb', line 186

put '/pnodes/:pnode/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.pnode_update(params['pnode'],desc)
  end

  return result!
end

- (Object) PUT '/pnodes/probes'

Stop or restart the probes



129
130
131
132
133
134
135
136
137
138
# File 'lib/distem/netapi/server.rb', line 129

put '/pnodes/probes' do
  check do
    if params['state'] == 'stop'
      @daemon.pnodes_stop_probes()
    else
      @daemon.pnodes_restart_probes()
    end
    @body = ""
  end
end

- (Object) PUT '/vnetworks/?'

Add a routing interface

Query parameters

  • address – the address of the interface to add in the bridge

  • netmask – the netmask of the interface to add in the bridge



620
621
622
623
624
625
626
# File 'lib/distem/netapi/server.rb', line 620

put '/vnetworks/?' do
  check do
    @body = @daemon.vnetwork_create_routing_interface(params['address'],params['netmask'])
  end

  return result!
end

- (Object) PUT '/vnodes/?'

Update or stop the virtual nodes following a new description

Query parameters:

  • desc – JSON Hash structured as described in Resource Description - VNode.

  • type – Type of operation: update or stop

  • async – Asynchronious mode, check the physical node status to know when the configuration is done (see GET /vnodes/:vnodename)



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/distem/netapi/server.rb', line 336

put '/vnodes/?' do
  check do
    desc = params['desc'] ? JSON.parse(params['desc']) : {}
    names = params['names'] ? JSON.parse(params['names']) : nil
    case params['type']
    when 'update'
      @body = @daemon.vnode_update(names,desc,params['async'])
    when 'stop'
      @body = @daemon.vnodes_stop(names,params['async'])
    when 'remove'
      @body = @daemon.vnodes_remove(names)
    when 'freeze'
      @body = @daemon.vnodes_freeze(names,params['async'])
    when 'unfreeze'
      @body = @daemon.vnodes_unfreeze(names,params['async'])
    else
      raise Lib::InvalidParameterError, params['type']
    end
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/?'

Update or stop the virtual node following a new description

Query parameters:

  • desc – JSON Hash structured as described in Resource Description - VNode.

  • type – Type of operation: update or stop

  • async – Asynchronious mode, check the physical node status to know when the configuration is done (see GET /vnodes/:vnodename)



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/distem/netapi/server.rb', line 307

put '/vnodes/:vnodename/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    case params['type']
    when 'update'
      @body = @daemon.vnode_update(CGI.unescape(params['vnodename']),desc,params['async']).first
    when 'stop'
      @body = @daemon.vnode_stop(CGI.unescape(params['vnodename']),params['async'])
    when 'remove'
      @body = @daemon.vnode_remove(CGI.unescape(params['vnodename']))
    when 'freeze'
      @body = @daemon.vnodes_freeze([CGI.unescape(params['vnodename'])],params['async'])
    when 'unfreeze'
      @body = @daemon.vnodes_unfreeze([CGI.unescape(params['vnodename'])],params['async'])
    else
      raise Lib::InvalidParameterError, params['type']
    end
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/cpu/?'

Update the virtual CPU associated with a virtual node (can be used when the node is started)

Important: The frequency description is updated on-the-fly

Query parameters:



581
582
583
584
585
586
587
588
589
# File 'lib/distem/netapi/server.rb', line 581

put '/vnodes/:vnodename/cpu/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vcpu_update(CGI.unescape(params['vnodename']),desc)
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/filesystem/?'

Update the virtual node filesystem

Query parameters:



377
378
379
380
381
382
383
384
385
# File 'lib/distem/netapi/server.rb', line 377

put '/vnodes/:vnodename/filesystem/?' do
  check do
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vfilesystem_update(CGI.unescape(params['vnodename']),desc)
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/ifaces/:ifacename/?'

Update a virtual network interface

Important: If specified in the description, the vtraffic description is updated on-the-fly

Query parameters:

Note: Dettach/Disconnect the virtual interface if properties is empty



479
480
481
482
483
484
485
486
487
488
489
# File 'lib/distem/netapi/server.rb', line 479

put '/vnodes/:vnodename/ifaces/:ifacename/?' do
  check do
    vnodename = CGI.unescape(params['vnodename'])
    vifacename = CGI.unescape(params['ifacename'])
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.viface_update(vnodename,vifacename,desc)
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/ifaces/:ifacename/input/?'

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

Important: The vtraffic description is updated on-the-fly

Query parameters:



509
510
511
512
513
514
515
516
517
518
519
# File 'lib/distem/netapi/server.rb', line 509

put '/vnodes/:vnodename/ifaces/:ifacename/input/?' do
  check do
    vnodename = CGI.unescape(params['vnodename'])
    vifacename = CGI.unescape(params['ifacename'])
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.vinput_update(vnodename,vifacename,desc)
  end

  return result!
end

- (Object) PUT '/vnodes/:vnodename/ifaces/:ifacename/output/?'

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

Important: The vtraffic description is updated on-the-fly

Query parameters:



539
540
541
542
543
544
545
546
547
548
549
# File 'lib/distem/netapi/server.rb', line 539

put '/vnodes/:vnodename/ifaces/:ifacename/output/?' do
  check do
    vnodename = CGI.unescape(params['vnodename'])
    vifacename = CGI.unescape(params['ifacename'])
    desc = {}
    desc = JSON.parse(params['desc']) if params['desc']
    @body = @daemon.voutput_update(vnodename,vifacename,desc)
  end

  return result!
end

- (Object) run

This method is abstract.


56
57
58
# File 'lib/distem/netapi/server.rb', line 56

def run
  raise "Server can not be run directly, use ServerDaemon or ServerNode"
end