Class: Zona::VDC

Inherits:
OZonesElement show all
Defined in:
zona/VDCElement.rb

Overview

This class describes a single VDC element. It can be used to allocate, delete, add hosts, remove hosts and retrieve full information for a VDC.

Constant Summary

VDC_KIND =

String describing the kind of this resource Should become part of the requests to server: get /vdc/…

"vdc"

Instance Attribute Summary

Attributes inherited from OZonesElement

name, pe_id

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from OZonesElement

new_with_id

Methods inherited from JSONElement

#[], #initialize_json

Constructor Details

- (String) initialize(hash, client)

Initializes a VDC object instance

Parameters:

  • hash (Hash)

    VDC description

  • client (Zona::Client)

    OZones Client



45
46
47
# File 'zona/VDCElement.rb', line 45

def initialize(hash, client)
    super(hash, client)
end

Class Method Details

+ (Hash, Zona::Error) build_json(pe_id = nil)

Builds minimal JSON description for a VDC

Parameters:

  • pe_id (Integer) (defaults to: nil)

    VDC’s ID

Returns:

  • (Hash, Zona::Error)

    Hash description of the object, or Error



32
33
34
35
36
37
38
39
# File 'zona/VDCElement.rb', line 32

def self.build_json(pe_id=nil)
    if pe_id
        json = "{\"VDC\":{\"ID\":#{pe_id}}}"
    else
        json = '{"VDC":{}}'
    end
    OZonesJSON.build_json(json,:VDC)
end

Instance Method Details

- (Zona::Error) addhosts(hosts_array, options = {}) Also known as: addhost

Adds hosts to a VDC. The specified hosts are added to the VDC’s current ones. in the zone to be added which already belong to other VDCs

Parameters:

  • hosts_array (Array<#to_i>)

    array of hosts IDs

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

    a hash of options

Options Hash (options):

  • :force (Boolean)

    allows hosts to add hosts

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'zona/VDCElement.rb', line 85

def addhosts(hosts_array,options={})
    return Error.new('VDC not info-ed') if !@json_hash

    # array of hosts, integers
    hosts = self[:HOSTS].split(',').collect!{|x| x.to_i}
    hosts.concat(hosts_array).uniq!

    new_hosts = hosts.join(',')
    template = {:ID => @pe_id, :HOSTS => new_hosts}
    template[:FORCE] = "YES" if options[:FORCE]

    template = {:VDC => template}

    rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
    return rc if Zona.is_error?(rc)
    nil
end

- (Zona::Error) allocate(template)

Allocates a new element from a JSON description

Parameters:

  • template (String)

    element description

Returns:



66
67
68
# File 'zona/VDCElement.rb', line 66

def allocate(template)
    super(VDC_KIND,template)
end

- (Zona::Error) allocate_hash(template)

Allocates a new element from a hash description

Parameters:

  • template (Hash)

    element description

Returns:



59
60
61
# File 'zona/VDCElement.rb', line 59

def allocate_hash(template)
    super(VDC_KIND,template)
end

- (Zona::Error) delete

Deletes current element

Returns:



72
73
74
# File 'zona/VDCElement.rb', line 72

def delete
    super(VDC_KIND)
end

- (Zona::Error) delhosts(hosts_array) Also known as: delhost

Delete hosts from a VDC. The specified hosts are removed from the VDC. to be removed. If a host is not in the VDC, then it is ignored.

Parameters:

  • hosts_array (Array<#to_i>)

    array of the VDC’s hosts IDs

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
# File 'zona/VDCElement.rb', line 107

def delhosts(hosts_array)
    return Error.new('VDC not info-ed') if !@json_hash

    hosts = self[:HOSTS].split(',').collect!{|x| x.to_i}

    new_hosts = (hosts - hosts_array).join(',')
    template = {:VDC => {:ID => @pe_id, :HOSTS => new_hosts}}

    rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
    return rc if Zona.is_error?(rc)
    nil
end

- (Zona::Error) info

Retrieves details about this object and fills in the information hash

Returns:



52
53
54
# File 'zona/VDCElement.rb', line 52

def info
    super(VDC_KIND,:VDC)
end