Class: Zona::VDC
- Inherits:
-
OZonesElement
- Object
- JSONElement
- OZonesElement
- Zona::VDC
- 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
Class Method Summary (collapse)
-
+ (Hash, Zona::Error) build_json(pe_id = nil)
Builds minimal JSON description for a VDC.
Instance Method Summary (collapse)
-
- (Zona::Error) addhosts(hosts_array, options = {})
(also: #addhost)
Adds hosts to a VDC.
-
- (Zona::Error) allocate(template)
Allocates a new element from a JSON description.
-
- (Zona::Error) allocate_hash(template)
Allocates a new element from a hash description.
-
- (Zona::Error) delete
Deletes current element.
-
- (Zona::Error) delhosts(hosts_array)
(also: #delhost)
Delete hosts from a VDC.
-
- (Zona::Error) info
Retrieves details about this object and fills in the information hash.
-
- (String) initialize(hash, client)
constructor
Initializes a VDC object instance.
Methods inherited from OZonesElement
Methods inherited from JSONElement
Constructor Details
- (String) initialize(hash, client)
Initializes a VDC object instance
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
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
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,={}) 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 [: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
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
59 60 61 |
# File 'zona/VDCElement.rb', line 59 def allocate_hash(template) super(VDC_KIND,template) end |
- (Zona::Error) delete
Deletes current element
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.
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
52 53 54 |
# File 'zona/VDCElement.rb', line 52 def info super(VDC_KIND,:VDC) end |