1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[hp] Updates reference to service

This commit is contained in:
Paul Thornthwaite 2012-12-22 23:26:21 +00:00
parent 2135e583b5
commit b8a36cc688
16 changed files with 67 additions and 67 deletions

View file

@ -138,7 +138,7 @@ module Fog
request_body['auth']['tenantId'] = "#{@hp_tenant_id}" if @hp_tenant_id
### Make the call to CS to get auth token and service catalog
response = connection.request(
response = service.request(
{
:expects => 200,
:headers => {

View file

@ -21,7 +21,7 @@ module Fog
def destroy
requires :id
connection.release_address(id)
service.release_address(id)
true
end
@ -35,7 +35,7 @@ module Fog
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = connection.allocate_address.body['floating_ip']
data = service.allocate_address.body['floating_ip']
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
merge_attributes(new_attributes)
if @server
@ -52,14 +52,14 @@ module Fog
else
@server = nil
self.instance_id = new_server.id
connection.associate_address(instance_id, ip)
service.associate_address(instance_id, ip)
end
end
def disassociate
@server = nil
if persisted?
connection.disassociate_address(instance_id, ip)
service.disassociate_address(instance_id, ip)
end
self.instance_id = nil
end

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::HP::Address
def all
data = connection.list_addresses.body['floating_ips']
data = service.list_addresses.body['floating_ips']
load(data)
end
def get(address_id)
if address = connection.get_address(address_id).body['floating_ip']
if address = service.get_address(address_id).body['floating_ip']
new(address)
end
rescue Fog::Compute::HP::NotFound

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::HP::Flavor
def all
data = connection.list_flavors_detail.body['flavors']
data = service.list_flavors_detail.body['flavors']
load(data)
end
def get(flavor_id)
data = connection.get_flavor_details(flavor_id).body['flavor']
data = service.get_flavor_details(flavor_id).body['flavor']
new(data)
rescue Fog::Compute::HP::NotFound
nil

View file

@ -16,13 +16,13 @@ module Fog
attribute :minDisk, :aliases => 'min_disk'
attribute :minRam, :aliases => 'min_ram'
attribute :server, :aliases => 'server'
attribute :metadata
attribute :metadata
attribute :links
def destroy
requires :id
connection.delete_image(id)
service.delete_image(id)
true
end

View file

@ -12,7 +12,7 @@ module Fog
attribute :server
def all
data = connection.list_images_detail.body['images']
data = service.list_images_detail.body['images']
load(data)
if server
self.replace(self.select {|image| image.server.id == server.id})
@ -21,7 +21,7 @@ module Fog
end
def get(image_id)
data = connection.get_image_details(image_id).body['image']
data = service.get_image_details(image_id).body['image']
new(data)
rescue Fog::Compute::HP::NotFound
nil

View file

@ -18,7 +18,7 @@ module Fog
def destroy
requires :name
connection.delete_key_pair(name)
service.delete_key_pair(name)
true
end
@ -26,9 +26,9 @@ module Fog
requires :name
data = if public_key
connection.create_key_pair(name, public_key).body['keypair']
service.create_key_pair(name, public_key).body['keypair']
else
connection.create_key_pair(name).body['keypair']
service.create_key_pair(name).body['keypair']
end
new_attributes = data.reject {|key,value| !['fingerprint', 'public_key', 'name', 'private_key', 'user_id'].include?(key)}
merge_attributes(new_attributes)

View file

@ -11,7 +11,7 @@ module Fog
def all
items = []
connection.list_key_pairs.body['keypairs'].each do |kp|
service.list_key_pairs.body['keypairs'].each do |kp|
items = items + kp.map { |key, value| value }
end
load(items)
@ -28,4 +28,4 @@ module Fog
end
end
end
end
end

View file

@ -16,25 +16,25 @@ module Fog
def destroy
requires :id
connection.delete_security_group(id)
service.delete_security_group(id)
true
end
def save
requires :name, :description
data = connection.create_security_group(name, description)
data = service.create_security_group(name, description)
merge_attributes(data.body['security_group'])
true
end
def create_rule(range, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id=nil)
requires :id
connection.create_security_group_rule(id, ip_protocol, range.min, range.max, cidr, group_id)
service.create_security_group_rule(id, ip_protocol, range.min, range.max, cidr, group_id)
end
def delete_rule(rule_id)
connection.delete_security_group_rule(rule_id)
service.delete_security_group_rule(rule_id)
true
end

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Compute::HP::SecurityGroup
def all
items = connection.list_security_groups.body['security_groups']
items = service.list_security_groups.body['security_groups']
load(items)
end
def get(security_group_id)
if security_group_id
sec_group = connection.get_security_group(security_group_id).body['security_group']
sec_group = service.get_security_group(security_group_id).body['security_group']
new(sec_group)
end
rescue Fog::Compute::HP::NotFound
@ -26,4 +26,4 @@ module Fog
end
end
end
end
end

View file

@ -43,19 +43,19 @@ module Fog
def destroy
requires :id
connection.delete_server(id)
service.delete_server(id)
true
end
def images
requires :id
connection.images(:server => self)
service.images(:server => self)
end
def key_pair
requires :key_name
connection.key_pairs.get(key_name)
service.key_pairs.get(key_name)
end
def key_pair=(new_keypair)
@ -111,53 +111,53 @@ module Fog
@security_groups = new_security_groups
end
def security_groups
def security_groups
@security_groups
end
def ready?
self.state == 'ACTIVE'
end
def change_password(admin_password)
requires :id
connection.change_password_server(id, admin_password)
service.change_password_server(id, admin_password)
true
end
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(id, type)
service.reboot_server(id, type)
true
end
def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil)
requires :id
connection.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
service.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
true
end
def resize(flavor_id)
requires :id
connection.resize_server(id, flavor_id)
service.resize_server(id, flavor_id)
true
end
def revert_resize
requires :id
connection.revert_resized_server(id)
service.revert_resized_server(id)
true
end
def confirm_resize
requires :id
connection.confirm_resized_server(id)
service.confirm_resized_server(id)
true
end
def create_image(name, metadata={})
requires :id
connection.create_image(id, name, metadata)
service.create_image(id, name, metadata)
end
def save
@ -174,7 +174,7 @@ module Fog
'security_groups' => @security_groups
}
options = options.reject {|key, value| value.nil?}
data = connection.create_server(name, flavor_id, image_id, options)
data = service.create_server(name, flavor_id, image_id, options)
merge_attributes(data.body['server'])
true
end

View file

@ -10,7 +10,7 @@ module Fog
model Fog::Compute::HP::Server
def all
data = connection.list_servers_detail.body['servers']
data = service.list_servers_detail.body['servers']
load(data)
end
@ -22,7 +22,7 @@ module Fog
end
def get(server_id)
if server = connection.get_server_details(server_id).body['server']
if server = service.get_server_details(server_id).body['server']
new(server)
end
rescue Fog::Compute::HP::NotFound

View file

@ -10,14 +10,14 @@ module Fog
model Fog::Storage::HP::Directory
def all
data = connection.get_containers.body
data = service.get_containers.body
load(data)
end
def get(key, options = {})
read_header = nil
write_header = nil
data = connection.get_container(key, options)
data = service.get_container(key, options)
directory = new(:key => key)
for key, value in data.headers
if ['X-Container-Bytes-Used', 'X-Container-Object-Count'].include?(key)
@ -31,7 +31,7 @@ module Fog
end
# set the acl on the directory based on the headers
if !(read_header.nil? && write_header.nil?)
directory.acl = connection.header_to_acl(read_header, write_header)
directory.acl = service.header_to_acl(read_header, write_header)
end
directory.files.merge_attributes(options)
directory.files.instance_variable_set(:@loaded, true)

View file

@ -25,11 +25,11 @@ module Fog
def destroy
requires :key
connection.delete_container(key)
service.delete_container(key)
# If CDN service is available, try to delete the container if it was CDN-enabled
if cdn_enabled?
begin
connection.cdn.delete_container(key)
service.cdn.delete_container(key)
rescue Fog::CDN::HP::NotFound
# ignore if cdn container not found
end
@ -43,7 +43,7 @@ module Fog
@files ||= begin
Fog::Storage::HP::Files.new(
:directory => self,
:connection => connection
:service => service
)
end
end
@ -68,9 +68,9 @@ module Fog
def public_url
requires :key
@public_url ||= begin
begin response = connection.head_container(key)
begin response = service.head_container(key)
# escape the key to cover for special char. in container names
url = "#{connection.url}/#{Fog::HP.escape(key)}"
url = "#{service.url}/#{Fog::HP.escape(key)}"
rescue Fog::Storage::HP::NotFound => err
nil
end
@ -79,7 +79,7 @@ module Fog
def cdn_enable=(new_cdn_enable)
@cdn_enable ||= false
if (!connection.cdn.nil? && connection.cdn.enabled?)
if (!service.cdn.nil? && service.cdn.enabled?)
@cdn_enable = new_cdn_enable
else
# since cdn service is not activated, container cannot be cdn-enabled
@ -88,8 +88,8 @@ module Fog
end
def cdn_enabled?
if (!connection.cdn.nil? && connection.cdn.enabled?)
begin response = connection.cdn.head_container(key)
if (!service.cdn.nil? && service.cdn.enabled?)
begin response = service.cdn.head_container(key)
cdn_header = response.headers.fetch('X-Cdn-Enabled', nil)
if (!cdn_header.nil? && cdn_header == 'True')
@cdn_enable = true
@ -108,9 +108,9 @@ module Fog
requires :key
@cdn_public_url ||= begin
# return the CDN public url from the appropriate uri from the header
begin response = connection.cdn.head_container(key)
begin response = service.cdn.head_container(key)
if response.headers['X-Cdn-Enabled'] == 'True'
if connection.hp_cdn_ssl == true
if service.hp_cdn_ssl == true
response.headers.fetch('X-Cdn-Ssl-Uri', nil)
else
response.headers.fetch('X-Cdn-Uri', nil)
@ -126,25 +126,25 @@ module Fog
requires :key
options = {}
if @acl
options.merge!(connection.acl_to_header(@acl))
options.merge!(service.acl_to_header(@acl))
end
connection.put_container(key, options)
service.put_container(key, options)
# Added an extra check to see if CDN is enabled for the container
if (!connection.cdn.nil? && connection.cdn.enabled?)
if (!service.cdn.nil? && service.cdn.enabled?)
# If CDN available, set the container to be CDN-enabled or not based on if it is marked as cdn_enable.
if @cdn_enable
# check to make sure that the container exists. If yes, cdn enable it.
begin response = connection.cdn.head_container(key)
begin response = service.cdn.head_container(key)
### Deleting a container from CDN is much more expensive than flipping the bit to disable it
connection.cdn.post_container(key, {'X-CDN-Enabled' => 'True'})
service.cdn.post_container(key, {'X-CDN-Enabled' => 'True'})
rescue Fog::CDN::HP::NotFound => err
connection.cdn.put_container(key)
service.cdn.put_container(key)
end
else
# check to make sure that the container exists. If yes, cdn disable it.
begin response = connection.cdn.head_container(key)
begin response = service.cdn.head_container(key)
### Deleting a container from CDN is much more expensive than flipping the bit to disable it
connection.cdn.post_container(key, {'X-CDN-Enabled' => 'False'})
service.cdn.post_container(key, {'X-CDN-Enabled' => 'False'})
rescue Fog::CDN::HP::NotFound => err
# just continue, as container is not cdn-enabled.
end

View file

@ -31,14 +31,14 @@ module Fog
def copy(target_directory_key, target_file_key)
requires :directory, :key
target_directory = connection.directories.new(:key => target_directory_key)
connection.put_object(target_directory_key, target_file_key, nil, {'X-Copy-From' => "/#{directory.key}/#{key}" })
target_directory = service.directories.new(:key => target_directory_key)
service.put_object(target_directory_key, target_file_key, nil, {'X-Copy-From' => "/#{directory.key}/#{key}" })
target_directory.files.get(target_file_key)
end
def destroy
requires :directory, :key
connection.delete_object(directory.key, key)
service.delete_object(directory.key, key)
true
end
@ -68,7 +68,7 @@ module Fog
def save(options = {})
requires :body, :directory, :key
options['Content-Type'] = content_type if content_type
data = connection.put_object(directory.key, key, body, options)
data = service.put_object(directory.key, key, body, options)
merge_attributes(data.headers)
self.content_length = Fog::Storage.get_body_size(body)
true

View file

@ -54,7 +54,7 @@ module Fog
def get(key, &block)
requires :directory
data = connection.get_object(directory.key, key, &block)
data = service.get_object(directory.key, key, &block)
file_data = data.headers.merge({
:body => data.body,
:key => key
@ -82,7 +82,7 @@ module Fog
def head(key, options = {})
requires :directory
data = connection.head_object(directory.key, key)
data = service.head_object(directory.key, key)
file_data = data.headers.merge({
:key => key
})