Class: Dcmgr::Cli::Spec
Constant Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #adddrive(uuid, type, name) ⇒ Object
- #addvif(uuid, name) ⇒ Object
- #del(uuid) ⇒ Object
- #deldrive(uuid, name) ⇒ Object
- #delvif(uuid, name) ⇒ Object
- #modify(uuid) ⇒ Object
- #modifydrive(uuid, name) ⇒ Object
- #modifyvif(uuid, name) ⇒ Object
- #show(uuid = nil) ⇒ Object
Instance Method Details
#add ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dcmgr/cli/spec.rb', line 17 def add UnknownUUIDError.raise([:account_id]) if M::Account[[:account_id]].nil? UnsupportedArchError.raise([:arch]) unless M::HostNode::SUPPORTED_ARCH.member?([:arch]) UnsupportedHypervisorError.raise([:hypervisor]) unless M::HostNode::SUPPORTED_HYPERVISOR.member?([:hypervisor]) uuid = super(M::InstanceSpec,) # add one interface as default invoke("addvif", [uuid, 'eth0']) invoke("adddrive", [uuid, 'local', 'ephemeral1']) puts uuid end |
#adddrive(uuid, type, name) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dcmgr/cli/spec.rb', line 138 def adddrive(uuid, type, name) spec = M::InstanceSpec[uuid] index = if [:index].nil? # find max index value. index = spec.drives.values.map { |i| i[:index] }.max index.nil? ? 0 : (index + 1) else [:index].to_i end case type when 'local' spec.add_local_drive(name, index, [:size].to_i) when 'volume' spec.add_volume_drive(name, index, [:size].to_i) else raise "Unknown drive type: #{type}" end spec.save end |
#addvif(uuid, name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dcmgr/cli/spec.rb', line 99 def addvif(uuid, name) spec = M::InstanceSpec[uuid] index = if [:index].nil? # find max index value. index = spec.vifs.values.map { |i| i[:index] }.max index.nil? ? 0 : (index + 1) else [:index].to_i end spec.add_vif(name, index.to_i, [:bandwidth].to_i) spec.save end |
#del(uuid) ⇒ Object
44 45 46 47 |
# File 'lib/dcmgr/cli/spec.rb', line 44 def del(uuid) UnknownUUIDError.raise(uuid) if M::InstanceSpec[uuid].nil? super(M::InstanceSpec, uuid) end |
#deldrive(uuid, name) ⇒ Object
162 163 164 165 166 |
# File 'lib/dcmgr/cli/spec.rb', line 162 def deldrive(uuid, name) spec = M::InstanceSpec[uuid] spec.remove_drive(name) spec.save end |
#delvif(uuid, name) ⇒ Object
115 116 117 118 119 |
# File 'lib/dcmgr/cli/spec.rb', line 115 def delvif(uuid, name) spec = M::InstanceSpec[uuid] spec.remove_vif(name) spec.save end |
#modify(uuid) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/dcmgr/cli/spec.rb', line 36 def modify(uuid) UnknownUUIDError.raise([:account_id]) if [:account_id] && M::Account[[:account_id]].nil? UnsupportedArchError.raise([:arch]) unless [:arch].nil? || M::HostNode::SUPPORTED_ARCH.member?([:arch]) UnsupportedHypervisorError.raise([:hypervisor]) unless [:hypervisor].nil? || M::HostNode::SUPPORTED_HYPERVISOR.member?([:hypervisor]) super(M::InstanceSpec,uuid,) end |
#modifydrive(uuid, name) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/dcmgr/cli/spec.rb', line 172 def modifydrive(uuid, name) spec = M::InstanceSpec[uuid] if [:index] spec.update_drive_index(name, [:index].to_i) end if [:size] spec.update_drive_size(name, [:size].to_i) end if [:snapshot_id] spec.update_drive_snapshot_id(name, [:snapshot_id]) end spec.save end |
#modifyvif(uuid, name) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/dcmgr/cli/spec.rb', line 124 def modifyvif(uuid, name) spec = M::InstanceSpec[uuid] if [:index] spec.update_vif_index(name, [:index].to_i) end if [:bandwidth] spec.update_vif_bandwidth(name, [:bandwidth].to_i) end spec.save end |
#show(uuid = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dcmgr/cli/spec.rb', line 50 def show(uuid=nil) if uuid spec = M::InstanceSpec[uuid] || UnknownUUIDError.raise(uuid) print ERB.new(<<__END, nil, '-').result(binding) UUID: <%= spec.canonical_uuid %> Account ID: <%= spec.account_id %> Hypervisor: <%= spec.hypervisor %> Arch: <%= spec.arch %> CPU Cores: <%= spec.cpu_cores %> Memory Size: <%= spec.memory_size %> Quota Weight: <%= spec.quota_weight %> <%- unless spec.vifs.empty? -%> Interfaces: <%- spec.vifs.each { |name, i| -%> [<%= i[:index] %>] <%= name %>: Bandwidth: <%= i[:bandwidth] %> kbps <%- } -%> <%- end -%> <%- unless spec.drives.empty? -%> Drives: <%- spec.drives.each { |name, i| -%> [<%= i[:index] %>] <%= name %>: Type: <%= i[:type] %> <%- if i[:size] -%> Size: <%= i[:size] %> MB <%- else -%> Snapshot ID: <%= i[:snapshot_id] %> <%- end -%> <%- } -%> <%- end -%> <%- unless spec.config.empty? -%> Hypervisor Configuration: <%= spec.config.inspect %> <%- end -%> __END else cond = {} specs = M::InstanceSpec.filter(cond).all print ERB.new(<<__END, nil, '-').result(binding) <%- specs.each { |row| -%> <%= "%-20s %-15s %-15s" % [row.canonical_uuid, row.account_id, row.arch] %> <%- } -%> __END end end |