lib/providers/hpcloud/compute.rb in lorj-0.2.0 vs lib/providers/hpcloud/compute.rb in lorj-1.0.0
- old
+ new
@@ -12,102 +12,90 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+# Defined HPCloud controller.
module HPCompute
- def HPCompute.get_server(oComputeConnect, sId)
- oComputeConnect.servers.get(sId)
- end
+ def self.get_server(oComputeConnect, sId)
+ oComputeConnect.servers.get(sId)
+ end
- def HPCompute.query_addresses(oComputeConnect, sQuery)
- oComputeConnect.addresses.all(sQuery)
- end
+ def self.query_addresses(oComputeConnect, sQuery)
+ oComputeConnect.addresses.all(sQuery)
+ end
- def HPCompute.query_server(oComputeConnect, sQuery)
- oComputeConnect.servers.all(sQuery)
- end
+ def self.query_server(oComputeConnect, sQuery)
+ oComputeConnect.servers.all(sQuery)
+ end
- def HPCompute.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
+ 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
- def HPCompute.query_flavor(oComputeConnect, sQuery)
- oComputeConnect.flavors.all(sQuery)
- end
+ def self.query_flavor(oComputeConnect, sQuery)
+ oComputeConnect.flavors.all(sQuery)
+ end
- def HPCompute.create_server(oComputeConnect,
- sServerName, oSecurity_groups,
- oImage, oNetwork,
- oFlavor, oKeypairs,
- oUser_data, oMeta_data)
+ def self.create_server(oComputeConnect, options, oUser_data, oMeta_data)
+ if oUser_data
+ options[:user_data_encoded] = Base64.strict_encode64(oUser_data)
+ end
+ options[:metadata] = oMeta_data if oMeta_data
+ server = oComputeConnect.servers.create(options)
+ HPCompute.get_server(oComputeConnect, server.id) if server
+ end
- options = {
- :name => sServerName,
- :flavor_id => oFlavor.id,
- :image_id => oImage.id,
- :key_name => oKeypairs.name,
- :security_groups => [oSecurity_groups.name],
- :networks => [oNetwork.id]
- }
- options[:user_data_encoded] = Base64.strict_encode64(oUser_data) if oUser_data
- options[:metadata] = oMeta_data if oMeta_data
- server = oComputeConnect.servers.create(options)
- HPCompute.get_server(oComputeConnect, server.id ) if server
- end
+ 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
- def HPCompute.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 = []
- oAddresses = oComputeConnect.addresses.all()
- oAddresses.each { | oElem |
- bFound = true
- sQuery.each { | key, value |
- if not oElem.attributes.key?(key) or oElem.attributes[key] != value
- bFound = false
- break
- end
- }
- result << oElem if bFound
- }
- result
- end
-
- def HPCompute.server_assign_address(oComputeConnect, oServer)
-
- while oServer.state != 'ACTIVE'
- sleep(5)
- oServer = oComputeConnect.servers.get(oServer.id)
+ 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
- oAddresses = oComputeConnect.addresses.all()
- oAddress = nil
- # Search for an available IP
- oAddresses.each { | oElem |
- if oElem.fixed_ip.nil?
- oAddress = oElem
- break
- end
- }
+ def self.server_assign_address(oComputeConnect, server)
+ while server.state != 'ACTIVE'
+ sleep(5)
+ server = oComputeConnect.servers.get(server.id)
+ end
- if oAddress.nil?
- # Create a new public IP to add in the pool.
- oAddress = oComputeConnect.addresses.create
+ addresses = oComputeConnect.addresses.all
+ address = nil
+ # Search for an available IP
+ addresses.each do | oElem |
+ if oElem.fixed_ip.nil?
+ address = oElem
+ break
end
- raise "No Public IP to assign to server '%s'" % oServer.name if oAddress.nil?
- oAddress.server = oServer # associate the server
- oAddress.reload
- # This function needs to returns a list of object.
- # This list must support the each function.
- oAddress
- end
+ end
- def HPCompute.delete_server(oComputeConnect, oServer)
- oComputeConnect.servers.get(oServer.id).destroy
- 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
+ def self.delete_server(oComputeConnect, server)
+ oComputeConnect.servers.get(server.id).destroy
+ end
end