Class: Distem::TopologyStore::HashWriter

Inherits:
TopologyWriter show all
Defined in:
lib/distem/topologystore/hashwriter.rb

Overview

Class that saves some virtual resource object as an Hash representing their properties. Based on the Visitor design pattern.

Instance Method Summary (collapse)

Methods inherited from TopologyWriter

#method_missing, #visit, #visit_array, #visit_hash, #visit_nilclass, #visit_string

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Distem::TopologyStore::TopologyWriter

Instance Method Details

- (Object) visit_bandwidth(limitbw)

See the visit_vplatform documentation



211
212
213
214
215
# File 'lib/distem/topologystore/hashwriter.rb', line 211

def visit_bandwidth(limitbw)
  return {
    'rate' => limitbw.rate,
  }
end

- (Object) visit_core(core)

See the visit_vplatform documentation



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/distem/topologystore/hashwriter.rb', line 101

def visit_core(core)
  ret = {
    'physicalid' => core.physicalid,
    'coreid' => core.coreid,
    'frequency' => (core.frequency / 1000).to_s + ' MHz',
    'frequencies' => [],
    'cache_links' => [],
  }
  core.frequencies.each do |corefreq|
    ret['frequencies'] << (corefreq / 1000).to_s + ' MHz'
  end

  core.cache_links.each do |linkedcore|
    ret['cache_links'] << linkedcore.physicalid
  end

  return ret
end

- (Object) visit_cpu(cpu)

See the visit_vplatform documentation



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/distem/topologystore/hashwriter.rb', line 80

def visit_cpu(cpu)
  ret = {
    'id' => cpu.object_id.to_s,
    'cores' => visit(cpu.cores),
    'cores_alloc' => [],
    'critical_cache_links' => [],
  }

  cpu.cores_alloc.each do |core,vnode|
    ret['cores_alloc'] << { 'core' => core.physicalid, 'vnode' => vnode.name }
  end

  cpu.critical_cache_links.each do |cachelink|
    ret['critical_cache_links'] <<
    cachelink.collect { |core| core.physicalid }
  end

  return ret
end

- (Object) visit_filesystem(filesystem)

See the visit_vplatform documentation



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/distem/topologystore/hashwriter.rb', line 162

def visit_filesystem(filesystem)
  return {
    'vnode' => filesystem.vnode,
    'image' => filesystem.image,
    'shared' => filesystem.shared,
    'path' => filesystem.path,
    'sharedpath' => filesystem.sharedpath,
    'cow' => filesystem.cow,
    'disk_throttling' => filesystem.disk_throttling,
  }
end

- (Object) visit_latency(limitlat)

See the visit_vplatform documentation



218
219
220
221
222
# File 'lib/distem/topologystore/hashwriter.rb', line 218

def visit_latency(limitlat)
  return {
    'delay' => limitlat.delay,
  }
end

- (Object) visit_memory(memory)

See the visit_vplatform documentation



147
148
149
150
151
152
# File 'lib/distem/topologystore/hashwriter.rb', line 147

def visit_memory(memory)
  return {
    'capacity' => memory.capacity.to_s,
    'swap' => memory.swap.to_s,
  }
end

- (Object) visit_pnode(pnode)

See the visit_vplatform documentation



22
23
24
25
26
27
28
29
30
31
# File 'lib/distem/topologystore/hashwriter.rb', line 22

def visit_pnode(pnode)
  return {
    'id' => pnode.id.to_s,
    'address' => pnode.address,
    'cpu' => visit(pnode.cpu),
    'memory' => visit(pnode.memory),
    'status' => pnode.status,
    'algorithms' => pnode.algorithms,
  }
end

- (Object) visit_vcore(vcore)

See the visit_vplatform documentation



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/distem/topologystore/hashwriter.rb', line 129

def visit_vcore(vcore)
  pcorenum = nil
  if vcore.pcore
    if vcore.pcore.is_a?(Resource::CPU::Core)
      pcorenum = vcore.pcore.physicalid.to_s
    else
      pcorenum = vcore.pcore.to_s
    end
  end

  return {
    'id' => vcore.id.to_s,
    'pcore' => pcorenum,
    'frequency' => vcore.frequency ? (vcore.frequency / 1000).to_s : '0',
  }
end

- (Object) visit_vcpu(vcpu)

See the visit_vplatform documentation



121
122
123
124
125
126
# File 'lib/distem/topologystore/hashwriter.rb', line 121

def visit_vcpu(vcpu)
  return {
    'pcpu' => vcpu.pcpu.object_id.to_s,
    'vcores' => visit(vcpu.vcores),
  }
end

- (Object) visit_viface(viface)

See the visit_vplatform documentation



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/distem/topologystore/hashwriter.rb', line 64

def visit_viface(viface)
    # Direction input/output is switched because of the lxc-veth structure that cause the input and the output of the network interface to be switched inside of the container
  return {
    'id' => viface.id.to_s,
    'name' => viface.name,
    'vnode' => viface.vnode.name,
    'address' => viface.address.to_string,
    'macaddress' => viface.macaddress,
    'vnetwork' => (viface.vnetwork ? viface.vnetwork.name : nil),
    'input' => (viface.vinput ? visit(viface.vinput) : nil),
    'output' => (viface.voutput ? visit(viface.voutput) : nil),
    'bridge' => viface.bridge,
  }
end

- (Object) visit_vmem(vmem)



154
155
156
157
158
159
# File 'lib/distem/topologystore/hashwriter.rb', line 154

def visit_vmem(vmem)
  return {
    'mem' => vmem.mem.to_s,
    'swap' => vmem.swap.to_s,
  }
end

- (Object) visit_vnetwork(vnetwork)

See the visit_vplatform documentation



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/distem/topologystore/hashwriter.rb', line 175

def visit_vnetwork(vnetwork)
  ret = {
    'name' => vnetwork.name,
    'address' => vnetwork.address.to_string,
    'vnodes' => [],
    'vroutes' => visit(vnetwork.vroutes),
    'opts' => vnetwork.opts,
  }
  vnetwork.vnodes.each_pair do |vnode,viface|
    ret['vnodes'] << vnode.name if viface
  end
  return ret
end

- (Object) visit_vnode(vnode)

See the visit_vplatform documentation



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/distem/topologystore/hashwriter.rb', line 34

def visit_vnode(vnode)
  ret = {
    'id' => vnode.id.to_s,
    'name' => vnode.name,
    'status' => vnode.status,
    'vfilesystem' => visit(vnode.filesystem),
    'vifaces' => visit(vnode.vifaces),
    'vcpu' => visit(vnode.vcpu),
    'vmem' => visit(vnode.vmem),
    'mode' => (vnode.gateway ? Resource::VNode::MODE_GATEWAY : Resource::VNode::MODE_NORMAL),
  }

  if vnode.host
    ret['host'] = vnode.host.address.to_s
  else
    ret['host'] = nil
  end

  if vnode.sshkey
    ret['ssh_key'] = {}
    ret['ssh_key']['public'] = vnode.sshkey['public'] if vnode.sshkey['public']
    ret['ssh_key']['private'] = vnode.sshkey['private'] if vnode.sshkey['private']
  else
    ret['ssh_key'] = nil
  end

  return ret
end

- (Object) visit_vplatform(vplatform)

Visit a virtual platform object. /All the other “visit_” methods are working the same way./

Attributes

*vplatform The VPlatform object

Returns

Hash object representing the VPlatform properties



13
14
15
16
17
18
19
# File 'lib/distem/topologystore/hashwriter.rb', line 13

def visit_vplatform(vplatform)
  return { 'vplatform' => {
    'pnodes' => visit(vplatform.pnodes),
    'vnodes' => visit(vplatform.vnodes),
    'vnetworks' => visit(vplatform.vnetworks),
  } }
end

- (Object) visit_vroute(vroute)

See the visit_vplatform documentation



190
191
192
193
194
195
196
197
# File 'lib/distem/topologystore/hashwriter.rb', line 190

def visit_vroute(vroute)
  return {
    'id' => vroute.id.to_s,
    'networksrc' => vroute.srcnet.name,
    'networkdst' => vroute.dstnet.name,
    'gateway' => vroute.gw.to_s,
  }
end

- (Object) visit_vtraffic(vtraffic)

See the visit_vplatform documentation



200
201
202
203
204
205
206
207
208
# File 'lib/distem/topologystore/hashwriter.rb', line 200

def visit_vtraffic(vtraffic)
  ret = {}
  vtraffic.properties.each_value do |prop|
    name = prop.class.name.split('::').last.downcase
    ret[name] = {} unless ret[name]
    ret[name].merge!(visit(prop))
  end
  return ret
end