Module: HPCompute
- Defined in:
- lib/process/cloud/providers/hpcloud/compute.rb
Overview
Defined HPCloud controller.
Class Method Summary collapse
- .create_server(oComputeConnect, options, oUser_data, oMeta_data) ⇒ Object
- .delete_server(oComputeConnect, server) ⇒ Object
- .get_image(oComputeConnect, oImageID) ⇒ Object
- .get_server(oComputeConnect, sId) ⇒ Object
- .get_server_assigned_address(oComputeConnect, id) ⇒ Object
- .query_addresses(oComputeConnect, sQuery) ⇒ Object
- .query_flavor(oComputeConnect, sQuery) ⇒ Object
- .query_image(oComputeConnect, sQuery) ⇒ Object
- .query_server(oComputeConnect, sQuery) ⇒ Object
- .query_server_assigned_addresses(oComputeConnect, _oServer, sQuery) ⇒ Object
- .server_assign_address(oComputeConnect, server) ⇒ Object
Class Method Details
.create_server(oComputeConnect, options, oUser_data, oMeta_data) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 42 def self.create_server(oComputeConnect, , oUser_data, oMeta_data) if oUser_data [:user_data_encoded] = Base64.strict_encode64(oUser_data) end [:metadata] = oMeta_data if oMeta_data server = oComputeConnect.servers.create() HPCompute.get_server(oComputeConnect, server.id) if server end |
.delete_server(oComputeConnect, server) ⇒ Object
103 104 105 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 103 def self.delete_server(oComputeConnect, server) oComputeConnect.servers.get(server.id).destroy end |
.get_image(oComputeConnect, oImageID) ⇒ Object
107 108 109 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 107 def self.get_image(oComputeConnect, oImageID) oComputeConnect.images.get(oImageID) end |
.get_server(oComputeConnect, sId) ⇒ Object
19 20 21 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 19 def self.get_server(oComputeConnect, sId) oComputeConnect.servers.get(sId) end |
.get_server_assigned_address(oComputeConnect, id) ⇒ Object
70 71 72 73 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 70 def self.get_server_assigned_address(oComputeConnect, id) addresses = oComputeConnect.addresses.all addresses.each { |oElem| return oElem if oElem.attributes['id'] == id } end |
.query_addresses(oComputeConnect, sQuery) ⇒ Object
23 24 25 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 23 def self.query_addresses(oComputeConnect, sQuery) oComputeConnect.addresses.all(sQuery) end |
.query_flavor(oComputeConnect, sQuery) ⇒ Object
38 39 40 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 38 def self.query_flavor(oComputeConnect, sQuery) oComputeConnect.flavors.all(sQuery) end |
.query_image(oComputeConnect, sQuery) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 31 def self.query_image(oComputeConnect, sQuery) # HP Fog query is exact matching. No way to filter with a Regexp # Testing it and filtering it. # TODO: Be able to support Regexp in queries then extract all and filter. oComputeConnect.images.all(sQuery) end |
.query_server(oComputeConnect, sQuery) ⇒ Object
27 28 29 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 27 def self.query_server(oComputeConnect, sQuery) oComputeConnect.servers.all(sQuery) end |
.query_server_assigned_addresses(oComputeConnect, _oServer, sQuery) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 51 def self.query_server_assigned_addresses(oComputeConnect, _oServer, sQuery) # CloudProcess used a simplified way to manage IPs. # Following is the translation to get the public IPs for the server result = [] addresses = oComputeConnect.addresses.all addresses.each do |oElem| is_found = true sQuery.each do |key, value| if !oElem.attributes.key?(key) || oElem.attributes[key] != value is_found = false break end end result << oElem if is_found end result end |
.server_assign_address(oComputeConnect, server) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/process/cloud/providers/hpcloud/compute.rb', line 75 def self.server_assign_address(oComputeConnect, server) while server.state != 'ACTIVE' sleep(5) server = oComputeConnect.servers.get(server.id) end addresses = oComputeConnect.addresses.all address = nil # Search for an available IP addresses.each do |oElem| if oElem.fixed_ip.nil? address = oElem break end end if address.nil? # Create a new public IP to add in the pool. address = oComputeConnect.addresses.create end fail "No Public IP to assign to server '%s'", server.name if address.nil? address.server = server # associate the server address.reload # This function needs to returns a list of object. # This list must support the each function. address end |