omf_sfa 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/brite2rspec.rb +60 -0
- data/examples/waxman_10.brite +37 -0
- data/lib/omf-sfa/resource.rb +3 -0
- data/lib/omf-sfa/resource/abstract_service.rb +14 -0
- data/lib/omf-sfa/resource/disk_image.rb +23 -0
- data/lib/omf-sfa/resource/execute_service.rb +20 -0
- data/lib/omf-sfa/resource/gurn.rb +4 -1
- data/lib/omf-sfa/resource/install_service.rb +20 -0
- data/lib/omf-sfa/resource/interface.rb +4 -2
- data/lib/omf-sfa/resource/link.rb +33 -10
- data/lib/omf-sfa/resource/node.rb +7 -2
- data/lib/omf-sfa/resource/ocomponent.rb +3 -3
- data/lib/omf-sfa/resource/oproperty.rb +18 -54
- data/lib/omf-sfa/resource/oresource.rb +23 -2
- data/lib/omf-sfa/resource/sfa_base.rb +52 -19
- data/lib/omf-sfa/resource/sliver_type.rb +25 -0
- data/lib/omf-sfa/version.rb +1 -1
- metadata +9 -2
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
require 'omf_base/lobject'
|
3
|
+
OMF::Base::Loggable.init_log 'brite2rspec'
|
4
|
+
|
5
|
+
require 'omf-sfa/util/brite_parser'
|
6
|
+
require 'omf-sfa/resource'
|
7
|
+
include OMF::SFA::Resource
|
8
|
+
|
9
|
+
GURN.default_domain = "urn:publicid:IDN+acme.org"
|
10
|
+
|
11
|
+
unless file_name = ARGV[0]
|
12
|
+
puts "Missing BRITE file name - #{ARGV}"
|
13
|
+
exit -1
|
14
|
+
end
|
15
|
+
|
16
|
+
OMF::SFA::Resource::OResource.init()
|
17
|
+
|
18
|
+
node_services = []
|
19
|
+
node_services << ExecuteService.create(command: "sudo sh /local/postboot_script.sh", shell: "sh")
|
20
|
+
node_services << InstallService.create(install_path: "/local", url: "http://emmy9.casa.umass.edu/InstaGENI_Images/install-script.tar.gz")
|
21
|
+
|
22
|
+
di = DiskImage.create(url: "urn:publicid:IDN+utah.geniracks.net+image+emulab-ops:OPENVZ-STD")
|
23
|
+
sliver_type = SliverType.create(name: 'emulab-openvz', disk_image: di)
|
24
|
+
|
25
|
+
parser = OMF::SFA::Util::BriteParser.new()
|
26
|
+
# opts; [:id, :i], [:x, :f], [:y, :f], [:type]
|
27
|
+
parser.on_new_node do |opts|
|
28
|
+
name = "n#{opts[:id]}"
|
29
|
+
node = Node.create(name: name, urn: 'foo_urn', sliver_type: sliver_type, exclusive: false)
|
30
|
+
node_services.each {|s| node.services << s }
|
31
|
+
node
|
32
|
+
end
|
33
|
+
|
34
|
+
network_cnt = 0
|
35
|
+
# opts: [:id, :i], [:from, :i], [:to, :i], [:length, :f], [:delay, :f], [:bw, :f], [:type], [:direction]
|
36
|
+
parser.on_new_edge do |opts, from, to|
|
37
|
+
name = "l#{opts[:id]}"
|
38
|
+
link = Link.create(name: name)
|
39
|
+
|
40
|
+
# Create a new subnet for each link
|
41
|
+
ip_nw = "10.#{network_cnt / 256}.#{network_cnt % 256}"
|
42
|
+
network_cnt += 1
|
43
|
+
|
44
|
+
f_ip = Ip.create(address: "#{ip_nw}.1", netmask: "255.255.255.0", ip_type: "ipv4")
|
45
|
+
f_name = "#{from.name}:if#{from.interfaces.length}"
|
46
|
+
from.interfaces << f_if = Interface.create(name: f_name, ip: f_ip)
|
47
|
+
|
48
|
+
t_ip = Ip.create(address: "#{ip_nw}.2", netmask: "255.255.255.0", ip_type: "ipv4")
|
49
|
+
t_name = "#{to.name}:if#{to.interfaces.length}"
|
50
|
+
to.interfaces << t_if = Interface.create(name: t_name, ip: t_ip)
|
51
|
+
|
52
|
+
link.interfaces << f_if << t_if
|
53
|
+
link.capacity = opts[:bw]
|
54
|
+
#link.latency = opts[:delay]
|
55
|
+
link
|
56
|
+
end
|
57
|
+
|
58
|
+
# Write RSPEC to stdout
|
59
|
+
parser.parse_file(file_name)
|
60
|
+
puts parser.to_rspec
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Topology: ( 10 Nodes, 20 Edges )
|
2
|
+
Model (1 - RTWaxman): 10 1000 100 2 2 0.15000000596046448 0.20000000298023224 1 1 10.0 1024.0
|
3
|
+
|
4
|
+
Nodes: ( 10 )
|
5
|
+
0 46 77 3 3 -1 RT_NODE
|
6
|
+
1 102 39 5 5 -1 RT_NODE
|
7
|
+
2 257 24 5 5 -1 RT_NODE
|
8
|
+
3 388 1 5 5 -1 RT_NODE
|
9
|
+
4 404 86 3 3 -1 RT_NODE
|
10
|
+
5 405 16 5 5 -1 RT_NODE
|
11
|
+
6 543 41 6 6 -1 RT_NODE
|
12
|
+
7 685 59 3 3 -1 RT_NODE
|
13
|
+
8 767 32 3 3 -1 RT_NODE
|
14
|
+
9 733 1 2 2 -1 RT_NODE
|
15
|
+
|
16
|
+
|
17
|
+
Edges: ( 20 )
|
18
|
+
0 2 0 217.55459085020476 0.7256840025315272 10.0 -1 -1 E_RT U
|
19
|
+
1 2 1 155.72411502397438 0.5194397352850497 10.0 -1 -1 E_RT U
|
20
|
+
2 3 2 133.00375934536586 0.44365278643989725 10.0 -1 -1 E_RT U
|
21
|
+
3 3 1 288.51343122981297 0.9623772164068684 10.0 -1 -1 E_RT U
|
22
|
+
4 4 2 159.5399636454766 0.5321680362134947 10.0 -1 -1 E_RT U
|
23
|
+
5 4 1 305.6354037084055 1.019489968985162 10.0 -1 -1 E_RT U
|
24
|
+
6 5 2 148.21605850919124 0.4943955545045474 10.0 -1 -1 E_RT U
|
25
|
+
7 5 4 70.00714249274856 0.23351869143001774 10.0 -1 -1 E_RT U
|
26
|
+
8 6 5 140.24621207005913 0.46781100834117423 10.0 -1 -1 E_RT U
|
27
|
+
9 6 3 160.0781059358212 0.5339630856751614 10.0 -1 -1 E_RT U
|
28
|
+
10 7 3 302.61031046545656 1.009399344080419 10.0 -1 -1 E_RT U
|
29
|
+
11 7 6 143.13629868066312 0.47745129959427834 10.0 -1 -1 E_RT U
|
30
|
+
12 8 7 86.33075929238663 0.28796841611134405 10.0 -1 -1 E_RT U
|
31
|
+
13 8 6 224.1807306616695 0.747786425840204 10.0 -1 -1 E_RT U
|
32
|
+
14 9 3 345.0 1.1507961284336246 10.0 -1 -1 E_RT U
|
33
|
+
15 9 8 46.010868281309364 0.1534757364753631 10.0 -1 -1 E_RT U
|
34
|
+
16 0 5 364.1455752854894 1.2146588934051483 10.0 -1 -1 E_RT U
|
35
|
+
17 0 6 498.30211719397704 1.6621569485713248 10.0 -1 -1 E_RT U
|
36
|
+
18 1 5 303.87168344549644 1.013606831448363 10.0 -1 -1 E_RT U
|
37
|
+
19 1 6 441.0045351240733 1.4710327873694318 10.0 -1 -1 E_RT U
|
data/lib/omf-sfa/resource.rb
CHANGED
@@ -18,3 +18,6 @@ require 'omf-sfa/resource/component_lease'
|
|
18
18
|
require 'omf-sfa/resource/link'
|
19
19
|
require 'omf-sfa/resource/interface'
|
20
20
|
require 'omf-sfa/resource/node'
|
21
|
+
require 'omf-sfa/resource/execute_service'
|
22
|
+
require 'omf-sfa/resource/install_service'
|
23
|
+
require 'omf-sfa/resource/disk_image'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource/oresource'
|
3
|
+
|
4
|
+
module OMF::SFA::Resource
|
5
|
+
|
6
|
+
# This class represents a service attached to a resource
|
7
|
+
#
|
8
|
+
class AbstractService < OMF::SFA::Resource::OResource
|
9
|
+
extend OMF::SFA::Resource::Base::ClassMethods
|
10
|
+
include OMF::SFA::Resource::Base::InstanceMethods
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource/oresource'
|
3
|
+
|
4
|
+
module OMF::SFA::Resource
|
5
|
+
|
6
|
+
# This class represents a disk image to be used for a particular node.
|
7
|
+
#
|
8
|
+
# <disk_image name="urn:publicid:IDN+instageni.gpolab.bbn.com+image+emulab-net//GIMIomf"/>
|
9
|
+
# <disk_image version="de35e71b31771870bcdfcccb4dee11657ba145b8" name="http://emmy9.casa.umass.edu/Disk_Images/ExoGENI/exogeni-umass-ovs-1.0.2.xml"/>
|
10
|
+
#
|
11
|
+
class DiskImage < OResource
|
12
|
+
oproperty :url, String, required: true
|
13
|
+
oproperty :version, String, required: false
|
14
|
+
|
15
|
+
extend OMF::SFA::Resource::Base::ClassMethods
|
16
|
+
include OMF::SFA::Resource::Base::InstanceMethods
|
17
|
+
|
18
|
+
sfa_class 'disk_image'
|
19
|
+
sfa :name, prop_name: :url, attribute: true
|
20
|
+
sfa :version, attribute: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource/oresource'
|
3
|
+
|
4
|
+
module OMF::SFA::Resource
|
5
|
+
|
6
|
+
# This class represents a service which executes a
|
7
|
+
# program as part of the boot process.
|
8
|
+
#
|
9
|
+
# <execute command="sudo sh /local/postboot_script.sh" shell="sh"/>
|
10
|
+
#
|
11
|
+
class ExecuteService < AbstractService
|
12
|
+
oproperty :command, String, required: true
|
13
|
+
oproperty :shell, String, default: 'sh'
|
14
|
+
|
15
|
+
sfa_class 'execute'
|
16
|
+
sfa :command, :attribute => true
|
17
|
+
sfa :shell, :attribute => true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -5,7 +5,7 @@ module OMF::SFA::Resource
|
|
5
5
|
#
|
6
6
|
class GURN #< OMF::Base::MObject
|
7
7
|
|
8
|
-
@@def_domain =
|
8
|
+
@@def_domain = "urn:publicid:IDN+acme.org"
|
9
9
|
@@name2obj = {}
|
10
10
|
|
11
11
|
# Create a GURN
|
@@ -18,6 +18,9 @@ module OMF::SFA::Resource
|
|
18
18
|
#
|
19
19
|
def self.create(name, opts = {})
|
20
20
|
return name if name.kind_of? self
|
21
|
+
unless name
|
22
|
+
raise "No name given"
|
23
|
+
end
|
21
24
|
#puts "GUID: #{name}###{opts}"
|
22
25
|
|
23
26
|
obj = @@name2obj[name]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource/oresource'
|
3
|
+
|
4
|
+
module OMF::SFA::Resource
|
5
|
+
|
6
|
+
# This class represents a service which installs a
|
7
|
+
# program as part of the boot process.
|
8
|
+
#
|
9
|
+
# <install install_path="/local" url="http://emmy9.casa.umass.edu/InstaGENI_Images/install-script.tar.gz"/>
|
10
|
+
#
|
11
|
+
class InstallService < AbstractService
|
12
|
+
oproperty :url, String, required: true # Location of file to install
|
13
|
+
oproperty :install_path, String, default: '/usr/local'
|
14
|
+
|
15
|
+
sfa_class 'install'
|
16
|
+
sfa :url, :attribute => true
|
17
|
+
sfa :install_path, :attribute => true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -33,10 +33,12 @@ module OMF::SFA::Resource
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_sfa_ref_xml(res_el, obj2id, opts)
|
36
|
+
#puts "IF_OPTS #{opts}"
|
36
37
|
if obj2id.key?(self)
|
37
38
|
el = res_el.add_child(Nokogiri::XML::Element.new('interface_ref', res_el.document))
|
38
|
-
el.set_attribute('component_id', self.component_id.to_s)
|
39
|
-
el.set_attribute('id_ref', self.uuid.to_s)
|
39
|
+
el.set_attribute('component_id', self.component_id.to_s) unless opts[:type] == :request
|
40
|
+
#el.set_attribute('id_ref', self.uuid.to_s)
|
41
|
+
el.set_attribute('client_id', self.component_name)
|
40
42
|
else
|
41
43
|
self.to_sfa_xml(res_el, obj2id, opts)
|
42
44
|
end
|
@@ -5,24 +5,47 @@ require 'omf-sfa/resource/channel'
|
|
5
5
|
|
6
6
|
module OMF::SFA::Resource
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
# <link component_id="urn:publicid:IDN+emulab.net+link+link-pc102%3Aeth2-internet%3Aborder" component_name="link-pc102:eth2-internet:border">
|
9
|
+
# <component_manager name="urn:publicid:IDN+emulab.net+authority+cm"/>
|
10
|
+
# <interface_ref component_id="urn:publicid:IDN+emulab.net+interface+pc102:eth2"/>
|
11
|
+
# <interface_ref component_id="urn:publicid:IDN+emulab.net+interface+internet:border"/>
|
12
|
+
# <property capacity="100000" dest_id="urn:publicid:IDN+emulab.net+interface+internet:border" latency="0" packet_loss="0" source_id="urn:publicid:IDN+emulab.net+interface+pc102:eth2"/>
|
13
|
+
# <property capacity="100000" dest_id="urn:publicid:IDN+emulab.net+interface+pc102:eth2" latency="0" packet_loss="0" source_id="urn:publicid:IDN+emulab.net+interface+internet:border"/>
|
14
|
+
# <link_type name="ipv4"/>
|
15
|
+
# </link>
|
17
16
|
class Link < Channel
|
18
17
|
|
19
18
|
oproperty :link_type, String
|
20
|
-
|
19
|
+
oproperty :capacity, Integer # kbps
|
20
|
+
oproperty :latency, Integer # ms
|
21
|
+
oproperty :packet_loss, Float # 0 .. 1
|
21
22
|
|
22
23
|
sfa_class 'link'
|
23
24
|
sfa :link_type, :content_attribute => :name
|
25
|
+
sfa :property # sets capacity, latency and packet_loss
|
24
26
|
#sfa :properties, LinkProperty, :inline => true, :has_many => true
|
25
27
|
|
28
|
+
#Override xml serialization of 'property'
|
29
|
+
def _to_sfa_xml_property(res_el, pdef, obj2id, opts)
|
30
|
+
capacity = self.capacity
|
31
|
+
latency = self.latency
|
32
|
+
packet_loss = self.packet_loss
|
33
|
+
if capacity || latency || packet_loss
|
34
|
+
source, dest = self.interfaces.to_a
|
35
|
+
_to_sfa_xml_one_way_property(res_el, source, dest, capacity, latency, packet_loss)
|
36
|
+
_to_sfa_xml_one_way_property(res_el, dest, source, capacity, latency, packet_loss)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def _to_sfa_xml_one_way_property(res_el, source, dest, capacity, latency, packet_loss)
|
41
|
+
# <property source_id="n7:if1" dest_id="n6:if2" capacity="10" latency="20" packet_loss="0.3"/>
|
42
|
+
el = res_el.add_child(Nokogiri::XML::Element.new('property', res_el.document))
|
43
|
+
el.set_attribute('source_id', source.client_id)
|
44
|
+
el.set_attribute('dest_id_id', dest.client_id)
|
45
|
+
el.set_attribute('capacity', capacity.to_i) if capacity
|
46
|
+
el.set_attribute('latency', latency.to_i) if latency
|
47
|
+
el.set_attribute('packet_loss', packet_loss) if packet_loss
|
48
|
+
end
|
26
49
|
end
|
27
50
|
|
28
51
|
end # OMF::SFA::Resource
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'omf-sfa/resource/ocomponent'
|
3
3
|
require 'omf-sfa/resource/interface'
|
4
|
+
require 'omf-sfa/resource/abstract_service'
|
5
|
+
require 'omf-sfa/resource/sliver_type'
|
4
6
|
|
5
7
|
module OMF::SFA::Resource
|
6
8
|
|
@@ -9,18 +11,21 @@ module OMF::SFA::Resource
|
|
9
11
|
|
10
12
|
oproperty :hardware_type, String, :required => false
|
11
13
|
oproperty :available, Boolean, :default => true
|
12
|
-
|
14
|
+
oproperty :sliver_type, SliverType, :required => false # Is this required?
|
13
15
|
oproperty :interfaces, :interface, :functional => false
|
14
16
|
oproperty :exclusive, Boolean, :default => true
|
17
|
+
oproperty :services, OMF::SFA::Resource::AbstractService, functional: false
|
15
18
|
|
16
19
|
#belongs_to :sliver
|
17
20
|
|
18
21
|
sfa_class 'node'
|
19
22
|
sfa :hardware_type, :inline => true, :has_many => true
|
20
|
-
sfa :available, :
|
23
|
+
sfa :available, attr_value: 'now', in_request: false # <available now="true">
|
21
24
|
#sfa :sliver_type, :attr_value => 'name'
|
25
|
+
sfa :sliver_type
|
22
26
|
sfa :interfaces, :inline => true, :has_many => true
|
23
27
|
sfa :exclusive, :attribute => true
|
28
|
+
sfa :services, :has_many => true
|
24
29
|
|
25
30
|
|
26
31
|
# Override xml serialization of 'interface'
|
@@ -41,13 +41,13 @@ module OMF::SFA::Resource
|
|
41
41
|
|
42
42
|
#sfa_add_namespace :ol, 'http://nitlab.inf.uth.gr/schema/sfa/rspec/1'
|
43
43
|
|
44
|
-
sfa :component_id, :
|
44
|
+
sfa :component_id, attribute: true, prop_name: :component_gurn, in_request: false
|
45
45
|
|
46
46
|
sfa :client_id, :attribute => true, :prop_name => :name
|
47
47
|
alias_method :client_id, :name
|
48
48
|
|
49
|
-
sfa :component_manager_id, :
|
50
|
-
sfa :component_name, :
|
49
|
+
sfa :component_manager_id, attribute: true, prop_name: :component_manager_gurn, in_request: false
|
50
|
+
sfa :component_name, attribute: true, in_request: false
|
51
51
|
sfa :leases, :inline => true, :has_many => true
|
52
52
|
|
53
53
|
sfa :exo_sliver__geni_sliver_info
|
@@ -47,57 +47,6 @@ module OMF::SFA::Resource
|
|
47
47
|
|
48
48
|
belongs_to :o_resource
|
49
49
|
|
50
|
-
# module ArrayProxy
|
51
|
-
# def << (val)
|
52
|
-
# if @on_set_block
|
53
|
-
# val = @on_set_block.call(val)
|
54
|
-
# return if val.nil?
|
55
|
-
# end
|
56
|
-
# @oproperty << val
|
57
|
-
# @on_modified_block.call(val, true) if @on_add_block
|
58
|
-
# super
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# def clear()
|
62
|
-
# _remove { super }
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# def delete(obj)
|
66
|
-
# _remove { super }
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# def delete_at(index)
|
70
|
-
# _remove { super }
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
# def delete_if(&block)
|
74
|
-
# _remove { super }
|
75
|
-
# end
|
76
|
-
#
|
77
|
-
# # Callback to support 'reverse' operation
|
78
|
-
# def on_modified(&block)
|
79
|
-
# @on_modified_block = block
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# def on_set(&block)
|
83
|
-
# @on_set_block = block
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# private
|
87
|
-
# def _remove(&block)
|
88
|
-
# old = self.dup
|
89
|
-
# r = block.call()
|
90
|
-
# removed = old - self
|
91
|
-
# unless removed.empty?
|
92
|
-
# if @on_remove_block
|
93
|
-
# removed.each {|it| @on_modified_block.call(it, false) }
|
94
|
-
# end
|
95
|
-
# @oproperty.value = self
|
96
|
-
# end
|
97
|
-
# r
|
98
|
-
# end
|
99
|
-
# end
|
100
|
-
|
101
50
|
def self.prop_all(query, opts = {}, resource_class = nil)
|
102
51
|
i = 0
|
103
52
|
where = query.map do |pn, v|
|
@@ -208,7 +157,10 @@ module OMF::SFA::Resource
|
|
208
157
|
when 's'
|
209
158
|
val = attribute_get(:s_value)
|
210
159
|
when 'r'
|
211
|
-
|
160
|
+
uuid_s = attribute_get(:s_value)
|
161
|
+
uuid = UUIDTools::UUID.parse(uuid_s)
|
162
|
+
#puts "RRRR >> #{uuid}"
|
163
|
+
#puts "OOOO >> #{OResource.all.to_a}"
|
212
164
|
val = OResource.first(uuid: uuid)
|
213
165
|
when 't'
|
214
166
|
val = Time.at(attribute_get(:n_value))
|
@@ -225,7 +177,7 @@ module OMF::SFA::Resource
|
|
225
177
|
val = JSON.load(js)[0]
|
226
178
|
#puts "VALUE: #{js.inspect}-#{val.inspect}-#{val.class}"
|
227
179
|
if val.kind_of? Array
|
228
|
-
val.tap {|v| v.extend(
|
180
|
+
#val.tap {|v| v.extend(OPropertyArray).instance_variable_set(:@oproperty, self) }
|
229
181
|
end
|
230
182
|
else
|
231
183
|
throw "Unknown property type '#{type}'"
|
@@ -307,8 +259,20 @@ module OMF::SFA::Resource
|
|
307
259
|
end
|
308
260
|
end
|
309
261
|
|
262
|
+
def [](index)
|
263
|
+
if p = OProperty.all(name: @name, o_resource: @resource).all[index]
|
264
|
+
p.value
|
265
|
+
else
|
266
|
+
nil
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def length
|
271
|
+
OProperty.count(name: @name, o_resource: @resource)
|
272
|
+
end
|
273
|
+
|
310
274
|
def empty?
|
311
|
-
|
275
|
+
self.length == 0
|
312
276
|
end
|
313
277
|
|
314
278
|
# Callback to support 'reverse' operation
|
@@ -2,6 +2,8 @@ require 'rubygems'
|
|
2
2
|
require 'dm-core'
|
3
3
|
require 'dm-types'
|
4
4
|
require 'dm-validations'
|
5
|
+
require 'dm-aggregates'
|
6
|
+
|
5
7
|
require 'omf_base/lobject'
|
6
8
|
require 'set'
|
7
9
|
require 'active_support/inflector'
|
@@ -66,6 +68,20 @@ module OMF::SFA::Resource
|
|
66
68
|
|
67
69
|
#belongs_to :account, :model => 'OAccount', :child_key => [ :account_id ], :required => false
|
68
70
|
|
71
|
+
def self.init(persistence_url = 'sqlite::memory:')
|
72
|
+
DataMapper::Logger.new($stdout, :info) # :note
|
73
|
+
|
74
|
+
DataMapper.setup(:default, persistence_url)
|
75
|
+
DataMapper::Model.raise_on_save_failure = true
|
76
|
+
|
77
|
+
DataMapper.finalize
|
78
|
+
#DataMapper.auto_upgrade!
|
79
|
+
require 'dm-migrations'
|
80
|
+
DataMapper.auto_migrate!
|
81
|
+
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
69
85
|
def self.href_resolver(&block)
|
70
86
|
@@href_resolvers[self] = block
|
71
87
|
end
|
@@ -73,6 +89,10 @@ module OMF::SFA::Resource
|
|
73
89
|
def self.oproperty(name, type, opts = {})
|
74
90
|
name = name.to_s
|
75
91
|
|
92
|
+
if self.properties.find {|p| p.name.to_s == name }
|
93
|
+
raise "Can't define an oproperty '#{name}' as it is already used as a base property."
|
94
|
+
end
|
95
|
+
|
76
96
|
# should check if +name+ is already used
|
77
97
|
op = @@oprops[self] ||= {}
|
78
98
|
opts[:__type__] = type
|
@@ -241,7 +261,7 @@ module OMF::SFA::Resource
|
|
241
261
|
|
242
262
|
|
243
263
|
def oproperty_get(pname)
|
244
|
-
#puts "OPROPERTY_GET: pname:'#{pname}'"
|
264
|
+
#puts "OPROPERTY_GET: pname:'#{pname}':#{pname.class}"
|
245
265
|
pname = pname.to_sym
|
246
266
|
return self.name if pname == :name
|
247
267
|
|
@@ -251,7 +271,7 @@ module OMF::SFA::Resource
|
|
251
271
|
alias_method :[], :oproperty_get
|
252
272
|
|
253
273
|
def oproperty_set(pname, value, type = nil)
|
254
|
-
#puts "OPROPERTY_SET pname:'#{pname}', value:'#{value.class}'
|
274
|
+
#puts "OPROPERTY_SET pname:'#{pname}', value:'#{value.class}'::#{type}, self:'#{self.inspect}'"
|
255
275
|
pname = pname.to_sym
|
256
276
|
if pname == :name
|
257
277
|
self.name = value
|
@@ -260,6 +280,7 @@ module OMF::SFA::Resource
|
|
260
280
|
#puts ">>>>>" + @@oprops[self.class][pname.to_s].to_s
|
261
281
|
prop = self.oproperties.first_or_create(:name => pname)
|
262
282
|
prop.value = value
|
283
|
+
#puts ">> #{prop.inspect}"
|
263
284
|
end
|
264
285
|
value
|
265
286
|
end
|
@@ -30,6 +30,7 @@ module OMF::SFA
|
|
30
30
|
@@sfa_namespace2prefix = {}
|
31
31
|
@@sfa_classes = {}
|
32
32
|
@@sfa_name2class = {}
|
33
|
+
@@sfa_suppress_id = {}
|
33
34
|
|
34
35
|
#
|
35
36
|
# @opts
|
@@ -65,6 +66,14 @@ module OMF::SFA
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
69
|
+
def sfa_suppress_id
|
70
|
+
@@sfa_suppress_id[self] = true
|
71
|
+
end
|
72
|
+
|
73
|
+
def sfa_suppress_id?
|
74
|
+
@@sfa_suppress_id[self] == true
|
75
|
+
end
|
76
|
+
|
68
77
|
# Define a SFA property
|
69
78
|
#
|
70
79
|
# @param [Symbol] name name of resource in RSpec
|
@@ -85,29 +94,34 @@ module OMF::SFA
|
|
85
94
|
# opts:
|
86
95
|
# :valid_for - valid [sec] from now
|
87
96
|
#
|
88
|
-
def
|
97
|
+
def to_rspec(resources, type, opts = {})
|
89
98
|
doc = Nokogiri::XML::Document.new
|
90
99
|
#<rspec expires="2011-09-13T09:07:09Z" generated="2011-09-13T09:07:09Z" type="advertisement" xmlns="http://www.geni.net/resources/rspec/3" xmlns:ol="http://nitlab.inf.uth.gr/schema/sfa/rspec/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/ad.xsd http://nitlab.inf.uth.gr/schema/sfa/rspec/1 http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd">
|
91
100
|
root = doc.add_child(Nokogiri::XML::Element.new('rspec', doc))
|
92
|
-
root.add_namespace(nil, SFA_NAMESPACE_URI)
|
93
|
-
root.add_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
|
94
101
|
|
95
|
-
|
96
|
-
|
102
|
+
root.set_attribute('type', type)
|
103
|
+
now = Time.now
|
104
|
+
root.set_attribute('generated', now.iso8601)
|
105
|
+
|
106
|
+
case opts[:type] = type = type.to_sym
|
107
|
+
when :manifest
|
97
108
|
schema = 'manifest.xsd'
|
98
|
-
|
109
|
+
when :advertisement
|
99
110
|
schema = 'ad.xsd'
|
111
|
+
root.set_attribute('expires', (now + (opts[:valid_for] || 600)).iso8601)
|
112
|
+
when :request
|
113
|
+
schema = 'request.xsd'
|
114
|
+
else
|
115
|
+
raise "Unnown Rspec type '#{type}'"
|
100
116
|
end
|
101
|
-
|
117
|
+
|
118
|
+
root.add_namespace(nil, SFA_NAMESPACE_URI)
|
119
|
+
root.add_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
|
120
|
+
#root['xsi:schemaLocation'] = "#{SFA_NAMESPACE_URI} #{SFA_NAMESPACE_URI}/#{schema} #{@@sfa_namespaces[:ol]} #{@@sfa_namespaces[:ol]}/ad-reservation.xsd"
|
102
121
|
@@sfa_namespaces.each do |prefix, opts|
|
103
122
|
root.add_namespace(prefix.to_s, opts[:urn])
|
104
123
|
end
|
105
124
|
|
106
|
-
root.set_attribute('type', opts[:type])
|
107
|
-
now = Time.now
|
108
|
-
root.set_attribute('generated', now.iso8601)
|
109
|
-
root.set_attribute('expires', (now + (opts[:valid_for] || 600)).iso8601)
|
110
|
-
|
111
125
|
#root = doc.create_element('rspec', doc)
|
112
126
|
#doc.add_child root
|
113
127
|
obj2id = {}
|
@@ -443,28 +457,41 @@ module OMF::SFA
|
|
443
457
|
self.class.sfa_add_namespaces_to_document(parent)
|
444
458
|
end
|
445
459
|
defs = self.class.sfa_defs()
|
446
|
-
if (id = obj2id[self])
|
460
|
+
if (!(opts[:suppress_id] || self.class.sfa_suppress_id?) && id = obj2id[self])
|
447
461
|
new_element.set_attribute('idref', id)
|
448
462
|
return parent
|
449
463
|
end
|
450
464
|
|
451
465
|
id = sfa_id()
|
452
466
|
obj2id[self] = id
|
453
|
-
|
467
|
+
unless opts[:suppress_id] || self.class.sfa_suppress_id?
|
468
|
+
new_element.set_attribute('id', id) #if detail_level > 0
|
469
|
+
end
|
454
470
|
#if href = self.href(opts)
|
455
471
|
# new_element.set_attribute('omf:href', href)
|
456
472
|
#end
|
457
473
|
level = opts[:level] ? opts[:level] : 0
|
458
474
|
opts[:level] = level + 1
|
475
|
+
sfa_type = opts[:type]
|
476
|
+
is_request = sfa_type == :request
|
459
477
|
defs.keys.sort.each do |key|
|
460
478
|
next if key.start_with?('_')
|
461
479
|
pdef = defs[key]
|
480
|
+
#puts ">>>> PDEF(#{key}): #{pdef}"
|
462
481
|
if (ilevel = pdef[:include_level])
|
463
482
|
#next if level > ilevel
|
464
483
|
end
|
465
|
-
|
466
|
-
|
467
|
-
|
484
|
+
next if is_request && pdef[:in_request] == false
|
485
|
+
|
486
|
+
if respond_to?(m = "_to_sfa_xml_#{key}".to_sym)
|
487
|
+
send(m, new_element, pdef, obj2id, opts)
|
488
|
+
next
|
489
|
+
end
|
490
|
+
pname = (pdef[:prop_name] || key).to_sym
|
491
|
+
#puts ">>>> #{pname} <#{self}> #{pdef.inspect}"
|
492
|
+
next unless respond_to? pname
|
493
|
+
value = send(pname)
|
494
|
+
#puts "#{key} <#{value} - #{value.class}> #{pdef.inspect}"
|
468
495
|
if value.nil?
|
469
496
|
value = pdef[:default]
|
470
497
|
end
|
@@ -473,7 +500,7 @@ module OMF::SFA
|
|
473
500
|
if value.is_a?(Time)
|
474
501
|
value = value.xmlschema # xs:dateTime
|
475
502
|
end
|
476
|
-
|
503
|
+
_to_sfa_property_xml(key, value, new_element, pdef, obj2id, opts)
|
477
504
|
#end
|
478
505
|
end
|
479
506
|
end
|
@@ -483,6 +510,11 @@ module OMF::SFA
|
|
483
510
|
|
484
511
|
def _to_sfa_property_xml(pname, value, res_el, pdef, obj2id, opts)
|
485
512
|
pname = self.class._sfa_add_ns(pname, pdef)
|
513
|
+
if value.respond_to?(:to_sfa_xml)
|
514
|
+
value.to_sfa_xml(res_el, obj2id, opts)
|
515
|
+
return
|
516
|
+
end
|
517
|
+
|
486
518
|
if pdef[:attribute]
|
487
519
|
res_el.set_attribute(pname, value.to_s)
|
488
520
|
elsif aname = pdef[:attr_value]
|
@@ -494,7 +526,8 @@ module OMF::SFA
|
|
494
526
|
else
|
495
527
|
cel = res_el.add_child(Nokogiri::XML::Element.new(pname, res_el.document))
|
496
528
|
end
|
497
|
-
|
529
|
+
#puts ">>> _to_sfa_property_xml(#{pname}): class: #{value.class} string? #{value.kind_of?(String)} enumerable: #{value.kind_of?(Enumerable)} "
|
530
|
+
if !value.kind_of?(String) && (value.kind_of?(Enumerable) || value.is_a?(OMF::SFA::Resource::OPropertyArray))
|
498
531
|
value.each do |v|
|
499
532
|
if v.respond_to?(:to_sfa_xml)
|
500
533
|
v.to_sfa_xml(cel, obj2id, opts)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
require 'omf-sfa/resource/oresource'
|
3
|
+
require 'omf-sfa/resource/disk_image'
|
4
|
+
|
5
|
+
module OMF::SFA::Resource
|
6
|
+
|
7
|
+
# This class represents a disk image to be used for a particular node.
|
8
|
+
#
|
9
|
+
# <sliver_type name="emulab-openvz">
|
10
|
+
# <disk_image name="urn:publicid:IDN+instageni.gpolab.bbn.com+image+emulab-net//GIMIomf"/>
|
11
|
+
# </sliver_type>
|
12
|
+
#
|
13
|
+
class SliverType < OResource
|
14
|
+
oproperty :disk_image, DiskImage, required: false
|
15
|
+
|
16
|
+
extend OMF::SFA::Resource::Base::ClassMethods
|
17
|
+
include OMF::SFA::Resource::Base::InstanceMethods
|
18
|
+
|
19
|
+
sfa_class 'sliver_type'
|
20
|
+
sfa_suppress_id
|
21
|
+
sfa :name, :attribute => true
|
22
|
+
sfa :disk_image
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/omf-sfa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_sfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -393,8 +393,10 @@ files:
|
|
393
393
|
- Rakefile
|
394
394
|
- bin/parse_rspec.rb
|
395
395
|
- etc/omf-sfa/omf-sfa-am.yaml
|
396
|
+
- examples/brite2rspec.rb
|
396
397
|
- examples/exogeni5nodemanifest.rspec
|
397
398
|
- examples/instageni5nodemanifest.rspec
|
399
|
+
- examples/waxman_10.brite
|
398
400
|
- lib/omf-sfa/am.rb
|
399
401
|
- lib/omf-sfa/am/am-rest/REST_API.md
|
400
402
|
- lib/omf-sfa/am/am-rest/account_handler.rb
|
@@ -426,13 +428,17 @@ files:
|
|
426
428
|
- lib/omf-sfa/model/ontology.rb
|
427
429
|
- lib/omf-sfa/resource.rb
|
428
430
|
- lib/omf-sfa/resource/README.md
|
431
|
+
- lib/omf-sfa/resource/abstract_service.rb
|
429
432
|
- lib/omf-sfa/resource/channel.rb
|
430
433
|
- lib/omf-sfa/resource/comp_group.rb
|
431
434
|
- lib/omf-sfa/resource/component_lease.rb
|
432
435
|
- lib/omf-sfa/resource/constants.rb
|
436
|
+
- lib/omf-sfa/resource/disk_image.rb
|
437
|
+
- lib/omf-sfa/resource/execute_service.rb
|
433
438
|
- lib/omf-sfa/resource/group_component.rb
|
434
439
|
- lib/omf-sfa/resource/group_membership.rb
|
435
440
|
- lib/omf-sfa/resource/gurn.rb
|
441
|
+
- lib/omf-sfa/resource/install_service.rb
|
436
442
|
- lib/omf-sfa/resource/interface.rb
|
437
443
|
- lib/omf-sfa/resource/ip.rb
|
438
444
|
- lib/omf-sfa/resource/link.rb
|
@@ -447,6 +453,7 @@ files:
|
|
447
453
|
- lib/omf-sfa/resource/project.rb
|
448
454
|
- lib/omf-sfa/resource/project_membership.rb
|
449
455
|
- lib/omf-sfa/resource/sfa_base.rb
|
456
|
+
- lib/omf-sfa/resource/sliver_type.rb
|
450
457
|
- lib/omf-sfa/resource/user.rb
|
451
458
|
- lib/omf-sfa/util/create_sample_testbed.rb
|
452
459
|
- lib/omf-sfa/util/load_from_sfa_xml.rb
|