Class: OpenNebula::VRRole

Inherits:
Role
  • Object
show all
Defined in:
lib/models/vrrole.rb

Overview

Virtual Route Role class

Constant Summary

Constants inherited from Role

Role::FAILURE_STATES, Role::IMMUTABLE_ATTRS, Role::LOG_COMP, Role::RECOVER_DEPLOY_STATES, Role::RECOVER_SCALE_STATES, Role::RECOVER_UNDEPLOY_STATES, Role::SCALE_WAYS, Role::SCHEDULE_ACTIONS, Role::STATE, Role::STATE_STR, Role::VM_INFO

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Role

#any_parent_on_hold?, #can_recover_deploy?, #can_recover_scale?, #can_recover_undeploy?, #can_release?, #cardinality, #cardinality=, #check_new_template, for, #info_nodes, init_default_cooldown, init_default_shutdown, init_default_vm_name_template, init_default_vr_name_template, init_force_deletion, #initialize, #name, #nodes, #nodes_ids, #on_hold=, #on_hold?, #parents, #recover_deploy, #recover_undeploy, #release, #scheduled_policies, #service_on_hold?, #shutdown, #state, #state=, #state_str, #update_scheduled_policies, vm_failure?

Constructor Details

This class inherits a constructor from OpenNebula::Role

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/models/vrrole.rb', line 22

def service
  @service
end

Instance Method Details

#batch_action(_, _, _, _) ⇒ Object

Scheduler



64
65
66
67
68
# File 'lib/models/vrrole.rb', line 64

def batch_action(_, _, _, _)
    return OpenNebula::Error.new(
        "Virtual Router role #{name} does not support schedule actions"
    )
end

#chown(uid, gid) ⇒ Object

Operations



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/models/vrrole.rb', line 28

def chown(uid, gid)
    vrouter_id = @body['vrouter_id']

    vrouter = OpenNebula::VirtualRouter.new_with_id(
        vrouter_id, @service.client
    )

    rc = vrouter.chown(uid, gid)

    if OpenNebula.is_error?(rc)
        msg = "Role #{name} : Chown failed for VR #{vrouter_id}; " \
              "#{rc.message}"

        Log.error(LOG_COMP, msg, @service.id)
        @service.log_error(msg)

        return [false, rc.message]
    else
        msg = "Role #{name} : Chown success for VR #{vrouter_id}"
        Log.debug(LOG_COMP, msg, @service.id)

    end

    [true, nil]
end

#clean_scale_wayObject



110
111
112
# File 'lib/models/vrrole.rb', line 110

def clean_scale_way
    []
end

#cooldownObject



98
99
100
# File 'lib/models/vrrole.rb', line 98

def cooldown
    []
end

#deployArray<true, nil>, Array<false, String>

Deploys all the nodes in this role

Returns:

  • (Array<true, nil>, Array<false, String>)

    true if all the VMs were created, false and the error reason if there was a problem creating the VMs



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/models/vrrole.rb', line 123

def deploy
    deployed_nodes = []
    n_nodes        = cardinality - nodes.size

    return [deployed_nodes, nil] if n_nodes == 0

    vr_name = @@vr_name_template
              .gsub('$SERVICE_ID', @service.id.to_s)
              .gsub('$SERVICE_NAME', @service.name.to_s)
              .gsub('$ROLE_NAME', name.to_s)

    @body['template_contents']['NAME'] = vr_name
    template_id, _, extra_template = init_template_attributes

    # Create vrouter Object and description
    vrouter = VirtualRouter.new(
        VirtualRouter.build_xml(@service.uid),
        @service.client
    )

    Log.debug(
        LOG_COMP,
        "Role #{name} : Creating service VRouter",
        @service.id
    )

    # Allocating VR with role description provided
    rc = vrouter.allocate(extra_template)

    if OpenNebula.is_error?(rc)
        msg = "Role #{name} : Allocate failed for Vrouter " \
              "#{template_id}; #{rc.message}"

        Log.error(LOG_COMP, msg, @service.id)
        @service.log_error(msg)

        return [false, "Error allocating Vrouter #{template_id} in Role " \
                       "#{name}: #{rc.message}"]
    end

    Log.debug(
        LOG_COMP,
        "Role #{name} : Instantiating VRouter #{vrouter.id}",
        @service.id
    )

    # Instantiating Vrouters
    vm_name = @@vm_name_template
              .gsub('$SERVICE_ID', @service.id.to_s)
              .gsub('$SERVICE_NAME', @service.name.to_s)
              .gsub('$ROLE_NAME', name.to_s)
              .gsub('$VM_NUMBER', '%i')

    rc = vrouter.instantiate(
        n_nodes,
        template_id,
        vm_name,
        on_hold?,
        extra_template
    )

    if OpenNebula.is_error?(rc)
        msg = "Role #{name} : Instantiate failed for Vrouter " \
              "#{vrouter.id}; #{rc.message}"

        Log.error(LOG_COMP, msg, @service.id)
        @service.log_error(msg)

        return [false, "Error instantiating Vrouter #{vrouter.id} in Role " \
                       "#{name}: #{rc.message}"]
    end

    vrouter.info

    # Once deployed, save VM info in role node body
    deployed_nodes.concat(vrouter.vm_ids)

    deployed_nodes.each do |vm_id|
        fill_node_info(vm_id)
    end

    @body['vrouter_id'] = vrouter.id

    # Fill vrouter IP in vrouter role body
    vrouter_nics = vrouter.to_hash['VROUTER']['TEMPLATE']['NIC'] || []
    vrouter_nics = [vrouter_nics] if vrouter_nics.is_a?(Hash)

    @body['vrouter_ips'] = vrouter_nics.map do |nic|
        next unless nic.is_a?(Hash) && nic.key?('VROUTER_IP')

        {
            'NETWORK_ID' => nic['NETWORK_ID'].to_i,
            'VROUTER_IP' => nic['VROUTER_IP']
        }
    end.compact

    [deployed_nodes, nil]
end

#elasticity_policiesObject



90
91
92
# File 'lib/models/vrrole.rb', line 90

def elasticity_policies
    []
end

#max_cardinalityInteger?

Returns the role max cardinality

Returns:

  • (Integer, nil)

    the role cardinality



76
77
78
# File 'lib/models/vrrole.rb', line 76

def max_cardinality
    return cardinality
end

#min_cardinalityInteger?

Returns the role min cardinality

Returns:

  • (Integer, nil)

    the role cardinality



82
83
84
# File 'lib/models/vrrole.rb', line 82

def min_cardinality
    return cardinality
end

#recover_scale(_) ⇒ Object

VRs do not support scale operations, returing empty array with zero nodes deployed / shutdown



228
229
230
# File 'lib/models/vrrole.rb', line 228

def recover_scale(_)
    []
end

#scale?(_) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/models/vrrole.rb', line 86

def scale?(_)
    return [0, 0]
end

#scale_way(_) ⇒ Object



106
107
108
# File 'lib/models/vrrole.rb', line 106

def scale_way(_)
    []
end

#shutdown_nodes(_nodes, n_nodes, _) ⇒ Array<(Boolean, Array<Integer>)>

Shutdown all nodes associated with a Virtual Router.

If the router could not be deleted, returns ‘false` and an empty list.

Parameters:

  • nodes (Array<Hash>)

    list of node definitions for the role

  • n_nodes (Integer)

    number of nodes to shutdown

  • _ (Object)

    unused parameter (placeholder for recover att)

Returns:

  • (Array<(Boolean, Array<Integer>)>)

    a tuple:

    • Boolean indicating overall success (‘true` if VR was deleted successfully)

    • Array of VM IDs that were associated with the Virtual Router



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/models/vrrole.rb', line 247

def shutdown_nodes(_nodes, n_nodes, _)
    vrouter_id = @body['vrouter_id']
    return [true, []] if vrouter_id.nil?

    msg = "Role #{name} : Terminating VR #{vrouter_id} (#{n_nodes} VMs associated)"
    Log.debug(LOG_COMP, msg, @service.id)

    vrouter = OpenNebula::VirtualRouter.new_with_id(vrouter_id, @service.client)
    rc      = vrouter.info

    if OpenNebula.is_error?(rc)
        msg = "Role #{name} : Error getting VR #{vrouter_id}: #{rc.message}"
        Log.error(LOG_COMP, msg, @service.id)
        @service.log_error(msg)

        return [false, []]
    end

    vm_ids = vrouter.vm_ids
    rc     = vrouter.delete

    if OpenNebula.is_error?(rc) && rc.errno != OpenNebula::Error::ENO_EXISTS
        msg = "Role #{name} : Delete failed for VR #{vrouter_id}: #{rc.message}"
        Log.error(LOG_COMP, msg, @service.id)
        @service.log_error(msg)

        return [false, []]
    end

    msg = "Role #{name} : Delete success for VR #{vrouter_id}"
    Log.debug(LOG_COMP, msg, @service.id)

    [true, vm_ids]
end

#update(_) ⇒ Object



54
55
56
57
58
# File 'lib/models/vrrole.rb', line 54

def update(_)
    return OpenNebula::Error.new(
        "Virtual Router role #{name} does not support cardinality update"
    )
end

#update_cooldown(_) ⇒ Object



102
103
104
# File 'lib/models/vrrole.rb', line 102

def update_cooldown(_)
    []
end

#update_elasticity_policies(_) ⇒ Object



94
95
96
# File 'lib/models/vrrole.rb', line 94

def update_elasticity_policies(_)
    []
end