Class: WeBee::Datacenter
- Inherits:
-
Object
- Object
- WeBee::Datacenter
- Includes:
- SAXMachine, RestResource
- Defined in:
- lib/webee.rb
Class Method Summary collapse
- .create(attributes) ⇒ Object
-
.find_by_name(name, options = {}) ⇒ Object
Return all the Datacenters matching name.
Instance Method Summary collapse
Methods included from RestResource
Methods included from SAXMachine
Class Method Details
.create(attributes) ⇒ Object
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 |
# File 'lib/webee.rb', line 167 def self.create(attributes) if attributes[:remote_services].nil? attributes[:remote_services] = WeBee::RemoteService.create_for_host(Api.host) end xm = Builder::XmlMarkup.new xm.datacenter { xm.name attributes[:name] xm.location(attributes[:location] || 'California, USA') xm.cpuSoft(attributes[:cpu_soft] || "0") xm.cpuHard(attributes[:cpu_hard] || "0") xm.vlanSoft(attributes[:vlan_soft] || "0") xm.vlanHard(attributes[:vlan_hard] || "0") xm.ramSoft(attributes[:ram_soft] || "0") xm.ramHard(attributes[:ram_hard] || "0") xm.repositorySoft(attributes[:repository_soft] || "0") xm.repositoryHard(attributes[:repository_hard] || "0") xm.publicIpsSoft(attributes[:public_ip_soft] || "0" ) xm.publicIpsHard(attributes[:public_ip_hard] || "0" ) xm.hdSoft(attributes[:hd_soft] || "0") xm.hdHard(attributes[:hd_hard] || "0") xm.storageSoft(attributes[:storage_soft] || "0") xm.storageHard(attributes[:storage_hard] || "0") xm.remoteServices { attributes[:remote_services].each do |rs| xm.remoteService { xm.uri rs.uri xm.type rs.rs_type } end } } res = RestClient.post(Api.url + '/admin/datacenters', xm.target!, :content_type => :xml) Datacenter.parse(res) end |
.find_by_name(name, options = {}) ⇒ Object
Return all the Datacenters matching name
205 206 207 |
# File 'lib/webee.rb', line 205 def self.find_by_name(name, = {}) Datacenter.all.find_all { |dc| dc.name =~ /#{name}/ } end |
Instance Method Details
#add_rack(params) ⇒ Object
221 222 223 |
# File 'lib/webee.rb', line 221 def add_rack(params) Rack.create datacenter_id, params end |
#discover_machine(params) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/webee.rb', line 225 def discover_machine(params) p = {} p[:ip] = params[:ip] p[:hypervisortype] = params[:hypervisortype] || 'kvm' p[:user] = params[:user] || 'user' p[:password] = params[:secret] || 'secret' p[:port] = params[:port] || '8889' p[:virtual_switch] = params[:virtual_switch] res = RestClient.get Api.url + "/admin/datacenters/#{datacenter_id}/action/discover", :params => p, :content_type => :xml machine = Machine.parse res end |
#racks ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/webee.rb', line 209 def racks items = [] doc = Nokogiri.parse(RestClient.get(Api.url + "/admin/datacenters/#{@datacenter_id}/racks", :accept => :xml)) doc.search doc.search('//rack').each do |node| rack = Rack.parse(node.to_s) rack.datacenter_id = @datacenter_id items << rack end items end |