# File lib/fog/hp/compute.rb, line 109 def initialize(options={}) @hp_secret_key = options[:hp_secret_key] @hp_account_id = options[:hp_account_id] @hp_servicenet = options[:hp_servicenet] @connection_options = options[:connection_options] || {} ### Set an option to use the style of authentication desired; :v1 or :v2 (default) auth_version = options[:hp_auth_version] || :v2 ### Pass the service type for compute via the options hash options[:hp_service_type] = "compute" @hp_tenant_id = options[:hp_tenant_id] ### Make the authentication call if (auth_version == :v2) # Call the control services authentication credentials = Fog::HP.authenticate_v2(options, @connection_options) # the CS service catalog returns the cdn endpoint @hp_compute_uri = credentials[:endpoint_url] else # Call the legacy v1.0/v1.1 authentication credentials = Fog::HP.authenticate_v1(options, @connection_options) # the user sends in the cdn endpoint @hp_compute_uri = options[:hp_auth_uri] end @auth_token = credentials[:auth_token] uri = URI.parse(@hp_compute_uri) @host = @hp_servicenet == true ? "snet-#{uri.host}" : uri.host @path = uri.path @persistent = options[:persistent] || false @port = uri.port @scheme = uri.scheme Excon.ssl_verify_peer = false if options[:hp_servicenet] == true @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Acquires a floating IP address
response<~Excon::Response>:
body<~Hash>:
'floating_ip'<~Hash> -
'id'<~Integer> - Id of the address
'ip'<~String> - Floating IP of the address
'instance_id'<~String> - Id of the associated server instance
'fixed_ip'<~String> - Fixed IP of the address
# File lib/fog/hp/requests/compute/allocate_address.rb, line 16 def allocate_address request( :body => nil, :expects => 200, :method => 'POST', :path => 'os-floating-ips.json' ) end
Associate a floating IP address with existing server
server_id<~Integer> - Id of server to associate IP with
ip_address<~String> - IP address to associate with the server
# File lib/fog/hp/requests/compute/associate_address.rb, line 12 def associate_address(server_id, ip_address) body = { 'addFloatingIp' => { 'server' => server_id, 'address' => ip_address }} server_action(server_id, body) end
# File lib/fog/hp/requests/compute/change_password_server.rb, line 6 def change_password_server(server_id, admin_password) body = { 'changePassword' => { 'adminPass' => admin_password }} server_action(server_id, body) end
Confirm resizing
server_id<~Integer> - Id of server to confirm
# File lib/fog/hp/requests/compute/confirm_resized_server.rb, line 11 def confirm_resized_server(server_id) body = { 'confirmResize' => nil } server_action(server_id, body, 204) end
Create an image from an existing server
server_id<~Integer> - Id of server to create image from
name<~String> - Name of the image
metadata<~Hash> - A hash of metadata options
'ImageType'<~String> - type of the image i.e. Gold
'ImageVersion'<~String> - version of the image i.e. 2.0
Does not return a response body.
# File lib/fog/hp/requests/compute/create_image.rb, line 18 def create_image(server_id, name, metadata = {}) body = { 'createImage' => { 'name' => name, 'metadata' => { 'ImageType' => metadata[:image_type], 'ImageVersion' => metadata[:image_version] } } } server_action(server_id, body) end
Create a new keypair
key_name<~String> - Name of the keypair
public_key<~String> - The public key for the keypair
response<~Excon::Response>:
body<~Hash>:
'keypair'<~Hash> - The keypair data
'public_key'<~String> - The public key for the keypair
'private_key'<~String> - The private key for the keypair
'user_id'<~String> - The user id
'fingerprint'<~String> - SHA-1 digest of DER encoded private key
'name'<~String> - Name of key
# File lib/fog/hp/requests/compute/create_key_pair.rb, line 23 def create_key_pair(key_name, public_key = nil) if public_key.nil? data = { 'keypair' => { 'name' => key_name } } else data = { 'keypair' => { 'name' => key_name, 'public_key' => public_key } } end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'os-keypairs.json' ) end
Create a new security group
'name'<~String> - name of the security group
'description'<~String> - description of the security group
response<~Excon::Response>:
body<~Hash>:
'security_group'<~Array>:
'rules'<~Array>: - array of security group rules
'id'<~Integer> - id of the security group rule
'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard)
'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard)
'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp']
'group'<~Hash>:
* Undefined
'parent_group_id'<~Integer> - parent group id
'ip_range'<~Hash>:
'cidr'<~String> - ip range address i.e. '0.0.0.0/0'
'id'<~Integer> - id of the security group
'name'<~String> - name of the security group
'description'<~String> - description of the security group
'tenant_id'<~String> - tenant id of the user
# File lib/fog/hp/requests/compute/create_security_group.rb, line 32 def create_security_group(name, description) data = { 'security_group' => { 'name' => name, 'description' => description } } request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'os-security-groups.json' ) end
Create a new security group rule and attach it to a security group
* 'parent_group_id'<~Integer> - id of the parent security group * 'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp'] * 'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard) * 'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard) * 'cidr'<~String> - ip range address i.e. '0.0.0.0/0' * 'group_id'<~Integer> - id of the security group to which this rule applies
response<~Excon::Response>:
body<~Hash>:
# File lib/fog/hp/requests/compute/create_security_group_rule.rb, line 21 def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil) data = { 'security_group_rule' => { 'parent_group_id' => parent_group_id, 'ip_protocol' => ip_protocol, 'from_port' => from_port, 'to_port' => to_port, 'cidr' => cidr, 'group_id' => group_id } } request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'os-security-group-rules.json' ) end
Create a new server
name<~String> - Name of server
flavor_id<~Integer> - Id of flavor for server
image_id<~Integer> - Id of image for server
options<~Hash>:
'metadata'<~Hash> - Up to 5 key value pairs containing 255 bytes of info
'min_count'<~Integer> - Number of servers to create. Defaults to 1.
'max_count'<~Integer> - Max. number of servers to create. Defaults to being equal to min_count.
'key_name'<~String> - Name of keypair to be used
'security_groups'<~Array> - one or more security groups to be used
'availability_zone'<~String> - the availability zone to be used
'personality'<~Array>: Up to 5 files to customize server
file<~Hash>:
'contents'<~String> - Contents of file (10kb total of contents)
'path'<~String> - Path to file (255 bytes total of path strings)
'accessIPv4'<~String> - IPv4 IP address
'accessIPv6'<~String> - IPv6 IP address
response<~Excon::Response>:
body<~Hash>:
'server'<~Hash>:
'addresses'<~Hash>:
'public'<~Array> - public address strings
'private'<~Array> - private address strings
'adminPass'<~String> - Admin password for server
'flavorId'<~Integer> - Id of servers current flavor
'hostId'<~String>
'id'<~Integer> - Id of server
'imageId'<~Integer> - Id of image used to boot server
'metadata'<~Hash> - metadata
'name'<~String> - Name of server
'progress'<~Integer> - Progress through current status
'status'<~String> - Current server status
# File lib/fog/hp/requests/compute/create_server.rb, line 42 def create_server(name, flavor_id, image_id, options = {}) data = { 'server' => { 'flavorRef' => flavor_id, 'imageRef' => image_id, 'name' => name } } if options['metadata'] data['server']['metadata'] = options['metadata'] end if options['accessIPv4'] data['server']['accessIPv4'] = options['accessIPv4'] end if options['accessIPv6'] data['server']['accessIPv6'] = options['accessIPv6'] end if options['personality'] data['server']['personality'] = [] for file in options['personality'] data['server']['personality'] << { 'contents' => Base64.encode64(file['contents']), 'path' => file['path'] } end end min_count = options['min_count'] || 1 max_count = options['max_count'] || min_count data['server']['min_count'] = min_count data['server']['max_count'] = max_count if options['key_name'] data['server']['key_name'] = options['key_name'] end if options['security_groups'] data['server']['security_groups'] = [] for sg in options['security_groups'] data['server']['security_groups'] << { 'name' => sg } end end if options['availability_zone'] data['server']['availability_zone'] = options['availability_zone'] end request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'POST', :path => 'servers.json' ) end
Delete an image
image_id<~Integer> - Id of image to delete
# File lib/fog/hp/requests/compute/delete_image.rb, line 11 def delete_image(image_id) request( :expects => 204, :method => 'DELETE', :path => "images/#{image_id}" ) end
Delete a keypair
key_name<~String> - Name of the keypair to delete
# File lib/fog/hp/requests/compute/delete_key_pair.rb, line 11 def delete_key_pair(key_name) request( :expects => 202, :method => 'DELETE', :path => "os-keypairs/#{key_name}" ) end
Delete a security group
id<~Integer> - Id of the security group to delete
# File lib/fog/hp/requests/compute/delete_security_group.rb, line 13 def delete_security_group(security_group_id) request( :expects => 202, :method => 'DELETE', :path => "os-security-groups/#{security_group_id}" ) end
Delete a security group rule
id<~Integer> - id of the security group rule to delete
# File lib/fog/hp/requests/compute/delete_security_group_rule.rb, line 12 def delete_security_group_rule(security_group_rule_id) request( :expects => 202, :method => 'DELETE', :path => "os-security-group-rules/#{security_group_rule_id}" ) end
Delete an existing server
id<~Integer> - Id of server to delete
# File lib/fog/hp/requests/compute/delete_server.rb, line 11 def delete_server(server_id) request( :expects => 204, :method => 'DELETE', :path => "servers/#{server_id}" ) end
Disassociate a floating IP address with existing server
server_id<~Integer> - Id of server to associate IP with
ip_address<~String> - IP address to associate with the server
# File lib/fog/hp/requests/compute/disassociate_address.rb, line 12 def disassociate_address(server_id, ip_address) body = { 'removeFloatingIp' => { 'server' => server_id, 'address' => ip_address }} server_action(server_id, body) end
Get details about an existing floating IP address
'address_id'<~Integer> - Id of floating IP address get details for
response<~Excon::Response>:
body<~Hash>:
'floating_ip'<~Hash> -
'id'<~Integer> - Id of the address
'ip'<~String> - Floating IP of the address
'instance_id'<~String> - Id of the associated server instance
'fixed_ip'<~String> - Fixed IP of the address
# File lib/fog/hp/requests/compute/get_address.rb, line 19 def get_address(address_id) request( :expects => [200], :method => 'GET', :path => "os-floating-ips/#{address_id}" ) end
Get details for flavor by id
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the flavor
'name'<~String> - Name of the flavor
'ram'<~Integer> - Amount of ram for the flavor
'disk'<~Integer> - Amount of diskspace for the flavor
# File lib/fog/hp/requests/compute/get_flavor_details.rb, line 15 def get_flavor_details(flavor_id) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_id}.json" ) end
Get details for image by id
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the image
'name'<~String> - Name of the image
'serverId'<~Integer> - Id of server image was created from
'status'<~Integer> - Status of image
'updated'<~String> - Timestamp of last update
# File lib/fog/hp/requests/compute/get_image_details.rb, line 16 def get_image_details(image_id) request( :expects => [200, 203], :method => 'GET', :path => "images/#{image_id}.json" ) end
Get details about a security group
'security_group_id'<~Integer> - Id of security group to get details for
response<~Excon::Response>:
body<~Hash>:
'security_group'<~Array>:
'rules'<~Array>: - array of security group rules
'id'<~Integer> - id of the security group rule
'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard)
'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard)
'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp']
'group'<~Hash>:
* Undefined
'parent_group_id'<~Integer> - parent group id
'ip_range'<~Hash>:
'cidr'<~String> - ip range address i.e. '0.0.0.0/0'
'id'<~Integer> - id of the security group
'name'<~String> - name of the security group
'description'<~String> - description of the security group
'tenant_id'<~String> - tenant id of the user
# File lib/fog/hp/requests/compute/get_security_group.rb, line 31 def get_security_group(security_group_id) request( :expects => [200], :method => 'GET', :path => "os-security-groups/#{security_group_id}" ) end
Get details about a server
server_id<~Integer> - Id of server to get details for
response<~Excon::Response>:
body<~Hash>:
'server'<~Hash>:
'addresses'<~Hash>:
'public'<~Array> - public address strings
'private'<~Array> - private address strings
'flavorId'<~Integer> - Id of servers current flavor
'hostId'<~String>
'id'<~Integer> - Id of server
'imageId'<~Integer> - Id of image used to boot server
'metadata'<~Hash> - metadata
'name<~String> - Name of server
'progress'<~Integer> - Progress through current status
'status'<~String> - Current server status
# File lib/fog/hp/requests/compute/get_server_details.rb, line 26 def get_server_details(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}.json" ) end
List all floating IP addresses
response<~Excon::Response>:
body<~Hash>:
'floating_ips'<~Array> -
'id'<~Integer> - Id of the address
'ip'<~String> - Floating IP of the address
'instance_id'<~String> - Id of the associated server instance
'fixed_ip'<~String> - Fixed IP of the address
# File lib/fog/hp/requests/compute/list_addresses.rb, line 16 def list_addresses request( :expects => 200, :method => 'GET', :path => "os-floating-ips.json" ) end
List all flavors (IDs and names only)
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the flavor
'name'<~String> - Name of the flavor
# File lib/fog/hp/requests/compute/list_flavors.rb, line 13 def list_flavors request( :expects => [200, 203], :method => 'GET', :path => 'flavors.json' ) end
List all flavors
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the flavor
'name'<~String> - Name of the flavor
'ram'<~Integer> - Amount of ram for the flavor
'disk'<~Integer> - Amount of diskspace for the flavor
# File lib/fog/hp/requests/compute/list_flavors_detail.rb, line 15 def list_flavors_detail request( :expects => [200, 203], :method => 'GET', :path => 'flavors/detail.json' ) end
List all images (IDs and names only)
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the image
'name'<~String> - Name of the image
# File lib/fog/hp/requests/compute/list_images.rb, line 13 def list_images request( :expects => [200, 203], :method => 'GET', :path => 'images.json' ) end
List all images
response<~Excon::Response>:
body<~Hash>:
'id'<~Integer> - Id of the image
'name'<~String> - Name of the image
'updated'<~String> - Last update timestamp for image
'created'<~String> - Creation timestamp for image
'status'<~String> - Status of image
# File lib/fog/hp/requests/compute/list_images_detail.rb, line 16 def list_images_detail request( :expects => [200, 203], :method => 'GET', :path => 'images/detail.json' ) end
List all key pairs
response<~Excon::Response>:
body<~Hash>:
'keypairs'<~Array>:
'keypair'<~Hash>:
'public_key'<~String> - Public portion of the key
'name'<~String> - Name of the key
'fingerprint'<~String> - Fingerprint of the key
# File lib/fog/hp/requests/compute/list_key_pairs.rb, line 18 def list_key_pairs request( :expects => [200, 203], :method => 'GET', :path => 'os-keypairs.json' ) end
List all security groups
response<~Excon::Response>:
body<~Hash>:
'security_groups'<~Array>:
'rules'<~Array>: - array of security group rules
'id'<~Integer> - id of the security group rule
'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard)
'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard)
'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp']
'group'<~Hash>:
* Undefined
'parent_group_id'<~Integer> - parent group id
'ip_range'<~Hash>:
'cidr'<~String> - ip range address i.e. '0.0.0.0/0'
'id'<~Integer> - id of the security group
'name'<~String> - name of the security group
'description'<~String> - description of the security group
'tenant_id'<~String> - tenant id of the user
# File lib/fog/hp/requests/compute/list_security_groups.rb, line 28 def list_security_groups request( :expects => [200], :method => 'GET', :path => 'os-security-groups.json' ) end
List all server addresses
server_id<~Integer> - Id of server to list addresses for
response<~Excon::Response>:
body<~Hash>:
'addresses'<~Hash>:
'novanet_7':<~Array> - The network name can change based on setup
# File lib/fog/hp/requests/compute/list_server_addresses.rb, line 16 def list_server_addresses(server_id) request( :expects => 200, :method => 'GET', :path => "servers/#{server_id}/ips.json" ) end
List private server addresses
server_id<~Integer> - Id of server to list addresses for
network_name<~String> - The name of the network name i.e. public, private or custom name
response<~Excon::Response>:
body<~Hash>:
'private'<~Array> - Private ip addresses
# File lib/fog/hp/requests/compute/list_server_private_addresses.rb, line 16 def list_server_private_addresses(server_id, network_name) response = request( :expects => 200, :method => 'GET', :path => "servers/#{server_id}/ips/#{network_name}.json" ) # return the first address private_address = [] data = response.body["#{network_name}"][0] if data private_address << data end response.body = { 'private' => private_address } response end
List public server addresses
server_id<~Integer> - Id of server to list addresses for
network_name<~String> - The name of the network name i.e. public, private or custom name
response<~Excon::Response>:
body<~Hash>:
'public'<~Array> - Public ip addresses
# File lib/fog/hp/requests/compute/list_server_public_addresses.rb, line 16 def list_server_public_addresses(server_id, network_name) response = request( :expects => 200, :method => 'GET', :path => "servers/#{server_id}/ips/#{network_name}.json" ) # return everything except the first address data = response.body["#{network_name}"] if data data.delete_at(0) public_address = data end response.body = { 'public' => public_address } response end
List all servers (IDs and names only)
response<~Excon::Response>:
body<~Hash>:
'servers'<~Array>:
'id'<~Integer> - Id of server
'name<~String> - Name of server
# File lib/fog/hp/requests/compute/list_servers.rb, line 14 def list_servers request( :expects => [200, 203], :method => 'GET', :path => 'servers.json' ) end
List all servers details
response<~Excon::Response>:
body<~Hash>:
'servers'<~Array>:
'id'<~Integer> - Id of server
'name<~String> - Name of server
'imageId'<~Integer> - Id of image used to boot server
'flavorId'<~Integer> - Id of servers current flavor
'hostId'<~String>
'status'<~String> - Current server status
'progress'<~Integer> - Progress through current status
'addresses'<~Hash>:
'public'<~Array> - public address strings
'private'<~Array> - private address strings
'metadata'<~Hash> - metadata
# File lib/fog/hp/requests/compute/list_servers_detail.rb, line 23 def list_servers_detail request( :expects => [200, 203], :method => 'GET', :path => 'servers/detail.json' ) end
Reboot an existing server
server_id<~Integer> - Id of server to reboot
type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
# File lib/fog/hp/requests/compute/reboot_server.rb, line 12 def reboot_server(server_id, type = 'SOFT') body = { 'reboot' => { 'type' => type }} server_action(server_id, body) end
# File lib/fog/hp/requests/compute/rebuild_server.rb, line 6 def rebuild_server(server_id, image_ref, name, admin_pass=nil, metadata=nil, personality=nil) body = { 'rebuild' => { 'imageRef' => image_ref, 'name' => name }} body['rebuild']['adminPass'] = admin_pass if admin_pass body['rebuild']['metadata'] = metadata if metadata body['rebuild']['personality'] = personality if personality server_action(server_id, body, 202) end
Release an existing floating IP address
id<~Integer> - Id of floating IP address to delete
# File lib/fog/hp/requests/compute/release_address.rb, line 11 def release_address(address_id) request( :expects => 202, :method => 'DELETE', :path => "os-floating-ips/#{address_id}" ) end
# File lib/fog/hp/compute.rb, line 146 def reload @connection.reset end
# File lib/fog/hp/compute.rb, line 150 def request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}", :query => ('ignore_awful_caching' << Time.now.to_i.to_s) }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::HP::NotFound.slurp(error) else error end end unless response.body.empty? begin response.body = Fog::JSON.decode(response.body) rescue MultiJson::DecodeError => error response.body #### the body is not in JSON format so just return it as it is end end response end
Reboot an existing server
server_id<~Integer> - Id of server to resize
size<~String> - new size. call #list_flavors to get available flavors
# File lib/fog/hp/requests/compute/resize_server.rb, line 12 def resize_server(server_id, flavor_id) body = { 'resize' => { 'flavorRef' => flavor_id }} server_action(server_id, body) end
Revert resizing
server_id<~Integer> - Id of server to revert
# File lib/fog/hp/requests/compute/revert_resized_server.rb, line 11 def revert_resized_server(server_id) body = { 'revertResize' => nil } server_action(server_id, body) end
Server actions for an existing server
server_id<~Integer> - Id of server to reboot
body<~.to_json object> - Body of the request, describes the action (see #reboot_server as an example)
expect<~Integer> - expected return, 202 except for confirm resize (204)
# File lib/fog/hp/requests/compute/server_action.rb, line 13 def server_action(server_id, body, expects=202) request( :body => Fog::JSON.encode(body), :expects => expects, :method => 'POST', :path => "servers/#{server_id}/action.json" ) end
Update an existing server
# server_id<~Integer> - Id of server to update
options<~Hash>:
adminPass<~String> - New admin password for server
name<~String> - New name for server
# File lib/fog/hp/requests/compute/update_server.rb, line 13 def update_server(server_id, options = {}) request( :body => Fog::JSON.encode({ 'server' => options }), :expects => 200, :method => 'PUT', :path => "servers/#{server_id}.json" ) end