Class: Fog::Compute::HP::Real

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/fog/hp/compute.rb,
lib/fog/hp/requests/compute/get_meta.rb,
lib/fog/hp/requests/compute/delete_meta.rb,
lib/fog/hp/requests/compute/get_address.rb,
lib/fog/hp/requests/compute/list_images.rb,
lib/fog/hp/requests/compute/update_meta.rb,
lib/fog/hp/requests/compute/create_image.rb,
lib/fog/hp/requests/compute/delete_image.rb,
lib/fog/hp/requests/compute/list_flavors.rb,
lib/fog/hp/requests/compute/list_servers.rb,
lib/fog/hp/requests/compute/set_metadata.rb,
lib/fog/hp/requests/compute/attach_volume.rb,
lib/fog/hp/requests/compute/create_server.rb,
lib/fog/hp/requests/compute/delete_server.rb,
lib/fog/hp/requests/compute/detach_volume.rb,
lib/fog/hp/requests/compute/list_metadata.rb,
lib/fog/hp/requests/compute/reboot_server.rb,
lib/fog/hp/requests/compute/resize_server.rb,
lib/fog/hp/requests/compute/server_action.rb,
lib/fog/hp/requests/compute/update_server.rb,
lib/fog/hp/requests/compute/list_addresses.rb,
lib/fog/hp/requests/compute/list_key_pairs.rb,
lib/fog/hp/requests/compute/rebuild_server.rb,
lib/fog/hp/requests/compute/create_key_pair.rb,
lib/fog/hp/requests/compute/delete_key_pair.rb,
lib/fog/hp/requests/compute/release_address.rb,
lib/fog/hp/requests/compute/update_metadata.rb,
lib/fog/hp/requests/compute/allocate_address.rb,
lib/fog/hp/requests/compute/associate_address.rb,
lib/fog/hp/requests/compute/get_image_details.rb,
lib/fog/hp/requests/compute/get_console_output.rb,
lib/fog/hp/requests/compute/get_flavor_details.rb,
lib/fog/hp/requests/compute/get_security_group.rb,
lib/fog/hp/requests/compute/get_server_details.rb,
lib/fog/hp/requests/compute/list_images_detail.rb,
lib/fog/hp/requests/compute/list_flavors_detail.rb,
lib/fog/hp/requests/compute/list_server_volumes.rb,
lib/fog/hp/requests/compute/list_servers_detail.rb,
lib/fog/hp/requests/compute/disassociate_address.rb,
lib/fog/hp/requests/compute/get_windows_password.rb,
lib/fog/hp/requests/compute/list_security_groups.rb,
lib/fog/hp/requests/compute/create_security_group.rb,
lib/fog/hp/requests/compute/delete_security_group.rb,
lib/fog/hp/requests/compute/list_server_addresses.rb,
lib/fog/hp/requests/compute/revert_resized_server.rb,
lib/fog/hp/requests/compute/change_password_server.rb,
lib/fog/hp/requests/compute/confirm_resized_server.rb,
lib/fog/hp/requests/compute/create_persistent_server.rb,
lib/fog/hp/requests/compute/create_security_group_rule.rb,
lib/fog/hp/requests/compute/delete_security_group_rule.rb,
lib/fog/hp/requests/compute/list_server_public_addresses.rb,
lib/fog/hp/requests/compute/list_server_private_addresses.rb

Instance Method Summary collapse

Methods included from Utils

#decrypt_using_private_key, #encrypt_using_public_key, #extract_password_from_log

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/fog/hp/compute.rb', line 178

def initialize(options={})
  # deprecate hp_account_id
  if options[:hp_account_id]
    Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.")
    options[:hp_access_key] = options.delete(:hp_account_id)
  end
  @hp_access_key = options[:hp_access_key]
  unless @hp_access_key
    raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.")
  end
  @hp_secret_key = options[:hp_secret_key]
  @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 name 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   = uri.host
  @path   = uri.path
  @persistent = options[:persistent] || false
  @port   = uri.port
  @scheme = uri.scheme

  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#allocate_addressObject

Acquires a floating IP address

Returns

  • 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



16
17
18
19
20
21
22
23
24
# 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_address(server_id, ip_address) ⇒ Object

Associate a floating IP address with existing server

Parameters

  • server_id<~Integer> - Id of server to associate IP with

  • ip_address<~String> - IP address to associate with the server



12
13
14
15
# 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

#attach_volume(server_id, volume_id, device) ⇒ Object

Attach a block storage volume to an existing server

Parameters

  • server_id<~Integer> - Id of server to attach the volume to

  • volume_id<~Integer> - Id of the volume to be attached to the server

  • device<~String> - Device name that is the mount point that the volume will be attached to. e.g. /dev/sdf

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘volumeAttachment’<~Hash>:

      • <~Hash>

        • ‘volumeId’:<~Integer> - The volume id

        • ‘device’:<~String> - The name of the device



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/hp/requests/compute/attach_volume.rb', line 20

def attach_volume(server_id, volume_id, device)
  data = { 'volumeAttachment' =>
           { 'volumeId' => volume_id,
             'device'   => device
           }
         }
  response = request(
    :body     => Fog::JSON.encode(data),
    :expects  => 200,
    :method   => 'POST',
    :path     => "servers/#{server_id}/os-volume_attachments"
  )
  response
end

#change_password_server(server_id, admin_password) ⇒ Object



6
7
8
9
# 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_resized_server(server_id) ⇒ Object

Confirm resizing

Parameters

  • server_id<~Integer> - Id of server to confirm



11
12
13
14
# 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_image(server_id, name, metadata = {}) ⇒ Object

Create an image from an existing server

Parameters

  • 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

Returns

Does not return a response body.



18
19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/compute/create_image.rb', line 18

def create_image(server_id, name,  = {})
  body = { 'createImage' =>
               { 'name' => name,
                 'metadata' => 
               }
         }
  server_action(server_id, body)
end

#create_key_pair(key_name, public_key = nil) ⇒ Object

Create a new keypair

Parameters

  • key_name<~String> - Name of the keypair

  • public_key<~String> - The public key for the keypair

Returns

  • 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

Openstack API Reference



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_persistent_server(name, flavor_id, block_device_mapping = [], options = {}) ⇒ Object

Create a new persistent server i.e. use a bootable volume instead of an image

Parameters

  • name<~String> - Name of server

  • flavor_id<~Integer> - Id of flavor for server

  • block_device_mapping<~Array>: Use bootable volumes to create persistent instances

    • <~Hash>:

      • ‘volume_size’<~String> - Size of the volume. Ignored, and automatically picked up from the volume

      • ‘volume_id’<~String> - Id of the bootable volume to use

      • ‘delete_on_termination’<~String> - Setting this to ‘1’ (True) means that the volume gets deleted when the instance is killed. Set it to ‘0’ to preserve the volume.

      • ‘device_name’<~String> - Block device name e.g. “vda”

  • 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

    • ‘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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘server’<~Hash>:

      • ‘addresses’<~Hash>:

        • ‘private’<~Array> - private and public fixed and floating ip addresses

      • ‘flavor’<~Hash>

        • ‘id’<~String> - id of the flavor

        • ‘links’<~Array> - array of flavor links

      • ‘id’<~Integer> - id of server

      • ‘links’<~Array> - array of server links

      • ‘hostId’<~String>

      • ‘metadata’<~Hash> - metadata

      • ‘name’<~String> - name of server

      • ‘accessIPv4’<~String> - IPv4 ip address

      • ‘accessIPv6’<~String> - IPv6 ip address

      • ‘progress’<~Integer> - progress through current status

      • ‘status’<~String> - current server status

      • ‘created’<~String> - created date time stamp

      • ‘updated’<~String> - updated date time stamp

      • ‘user_id’<~String> - user id

      • ‘tenant_id’<~String> - tenant id

      • ‘uuid’<~String> - uuid of the server

      • ‘config_drive’<~String> - config drive

      • ‘security_groups’<~Array of Hash>

        • ‘id’<~Integer> - id of the security group

        • ‘name’<~String> - name of the security group

        • ‘links’<~Array> - array of security group links

      • ‘key_name’<~String> - name of the keypair

      • ‘adminPass’<~String> - admin password for server



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fog/hp/requests/compute/create_persistent_server.rb', line 60

def create_persistent_server(name, flavor_id, block_device_mapping = [], options = {})
  data = {
    'server' => {
      'flavorRef'  => flavor_id,
      'imageRef'   => nil,
      '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['config_drive']
    data['server']['config_drive'] = options['config_drive']
  end
  if block_device_mapping
    data['server']['block_device_mapping'] = block_device_mapping
  end

  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 200,
    :method   => 'POST',
    :path     => 'os-volumes_boot'
  )
end

#create_security_group(name, description) ⇒ Object

Create a new security group

Parameters

  • ‘name’<~String> - name of the security group

  • ‘description’<~String> - description of the security group

Returns

  • 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

Openstack API Reference



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id = nil) ⇒ Object

Create a new security group rule and attach it to a security group

Parameters

* '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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

Openstack API Reference



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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_server(name, flavor_id, image_id, options = {}) ⇒ Object

Create a new server

Parameters

  • name<~String> - Name of server

  • flavor_id<~Integer> - Id of flavor for server

  • image_id<~Integer> - Id of image for server. If block_device_mapping is passed, this is ignored.

  • 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

    • ‘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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘server’<~Hash>:

      • ‘addresses’<~Hash>:

        • ‘private’<~Array> - private and public fixed and floating ip addresses

      • ‘flavor’<~Hash>

        • ‘id’<~String> - id of the flavor

        • ‘links’<~Array> - array of flavor links

      • ‘id’<~Integer> - id of server

      • ‘image’<~Hash> - id of image used to boot server

        • ‘id’<~String> - id of the image

        • ‘links’<~Array> - array of image links

      • ‘links’<~Array> - array of server links

      • ‘hostId’<~String>

      • ‘metadata’<~Hash> - metadata

      • ‘name’<~String> - name of server

      • ‘accessIPv4’<~String> - IPv4 ip address

      • ‘accessIPv6’<~String> - IPv6 ip address

      • ‘progress’<~Integer> - progress through current status

      • ‘status’<~String> - current server status

      • ‘created’<~String> - created date time stamp

      • ‘updated’<~String> - updated date time stamp

      • ‘user_id’<~String> - user id

      • ‘tenant_id’<~String> - tenant id

      • ‘uuid’<~String> - uuid of the server

      • ‘config_drive’<~String> - config drive

      • ‘security_groups’<~Array of Hash>

        • ‘id’<~Integer> - id of the security group

        • ‘name’<~String> - name of the security group

        • ‘links’<~Array> - array of security group links

      • ‘key_name’<~String> - name of the keypair

      • ‘adminPass’<~String> - admin password for server



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
# File 'lib/fog/hp/requests/compute/create_server.rb', line 58

def create_server(name, flavor_id, image_id, options = {})
  data = {
    'server' => {
      'flavorRef'  => flavor_id,
      'imageRef'   => image_id,
      'name'       => name
    }
  }
  l_options = ['metadata', 'accessIPv4', 'accessIPv6', 'key_name', 'config_drive', 'user_data']
  l_options.select{|o| options[o]}.each do |key|
    data['server'][key] = options[key]
  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['security_groups']
    data['server']['security_groups'] = []
    for sg in options['security_groups']
      data['server']['security_groups'] << {
        'name' => sg
      }
    end
  end

  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 202,
    :method   => 'POST',
    :path     => 'servers.json'
  )
end

#delete_image(image_id) ⇒ Object

Delete an image

Parameters

  • image_id<~Integer> - Id of image to delete



11
12
13
14
15
16
17
# 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_key_pair(key_name) ⇒ Object

Delete a keypair

Parameters

  • key_name<~String> - Name of the keypair to delete



11
12
13
14
15
16
17
# 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_meta(collection_name, parent_id, key) ⇒ Object

Delete metadata item for specific collections

Parameters

  • ‘collection_name’<~String> - name of the collection i.e. images, servers for which the metadata is intented.

  • ‘parent_id’<~Integer> - id of the collection i.e. image_id or the server_id

  • ‘key’<~String> - key for the metadata item

Returns

  • response<~Excon::Response>:

    • body: Empty response body



17
18
19
20
21
22
23
# File 'lib/fog/hp/requests/compute/delete_meta.rb', line 17

def delete_meta(collection_name, parent_id, key)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => "#{collection_name}/#{parent_id}/metadata/#{key}"
  )
end

#delete_security_group(security_group_id) ⇒ Object

Delete a security group

Parameters

  • id<~Integer> - Id of the security group to delete

Openstack API Reference



13
14
15
16
17
18
19
# 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_security_group_rule(security_group_rule_id) ⇒ Object

Delete a security group rule

Parameters

  • id<~Integer> - id of the security group rule to delete

Openstack API Reference



12
13
14
15
16
17
18
# 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_server(server_id) ⇒ Object

Delete an existing server

Parameters

  • id<~Integer> - Id of server to delete



11
12
13
14
15
16
17
# 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

#detach_volume(server_id, volume_id) ⇒ Object

Detach a block storage volume from an existing server

Parameters

  • server_id<~Integer> - Id of server to attach the volume to

  • volume_id<~Integer> - Id of the volume to be attached to the server

Returns

  • response<~Excon::Response>:

    • body: Empty



15
16
17
18
19
20
21
22
# File 'lib/fog/hp/requests/compute/detach_volume.rb', line 15

def detach_volume(server_id, volume_id)
  response = request(
    :expects  => 202,
    :method   => 'DELETE',
    :path     => "servers/#{server_id}/os-volume_attachments/#{volume_id}"
  )
  response
end

#disassociate_address(server_id, ip_address) ⇒ Object

Disassociate a floating IP address with existing server

Parameters

  • server_id<~Integer> - Id of server to associate IP with

  • ip_address<~String> - IP address to associate with the server



12
13
14
15
# 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_address(address_id) ⇒ Object

Get details about an existing floating IP address

Parameters

  • ‘address_id’<~Integer> - Id of floating IP address get details for

Returns

  • 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



19
20
21
22
23
24
25
# 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_console_output(server_id, num_lines) ⇒ Object

Retrieve console output for specified instance

Parameters

  • server_id<~Integer> - Id of instance to get console output from

  • num_lines<~Integer> - Number of lines of console output from the end

Returns

# * response<~Excon::Response>:

* body<~Hash>:
  * 'output'<~String> - Console output


18
19
20
21
# File 'lib/fog/hp/requests/compute/get_console_output.rb', line 18

def get_console_output(server_id, num_lines)
  body = { 'os-getConsoleOutput' => { 'length' => num_lines }}
  server_action(server_id, body, 200)
end

#get_flavor_details(flavor_id) ⇒ Object

Get details for flavor by id

Returns

  • 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



15
16
17
18
19
20
21
# 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_image_details(image_id) ⇒ Object

Get details for image by id

Returns

  • 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



16
17
18
19
20
21
22
# 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_meta(collection_name, parent_id, key) ⇒ Object

Get metadata item for specific collections

Parameters

  • ‘collection_name’<~String> - name of the collection i.e. images, servers for which the metadata is intended.

  • ‘parent_id’<~Integer> - id of the collection i.e. image_id or the server_id

  • ‘key’<~String> - key for the metadata item

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • meta<~Hash>: hash of key/value pair for the metadata item found



18
19
20
21
22
23
24
# File 'lib/fog/hp/requests/compute/get_meta.rb', line 18

def get_meta(collection_name, parent_id, key)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "#{collection_name}/#{parent_id}/metadata/#{key}"
  )
end

#get_security_group(security_group_id) ⇒ Object

Get details about a security group

Parameters

  • ‘security_group_id’<~Integer> - Id of security group to get details for

Returns

  • 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

Openstack API Reference



31
32
33
34
35
36
37
# 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_server_details(server_id) ⇒ Object

Get details about a server

Parameters

  • server_id<~Integer> - Id of server to get details for

Returns

  • 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



26
27
28
29
30
31
32
# 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

#get_windows_password(server_id) ⇒ Object

Retrieves the encrypted administrator password for a server running Windows.

Parameters

  • server_id<~Integer> - Id of server

Returns

  • password_data<~string>: Encrypted password for a server running Windows



14
15
16
17
18
19
# File 'lib/fog/hp/requests/compute/get_windows_password.rb', line 14

def get_windows_password(server_id)
  # get console output assuming that the server is already in active state
  log_output = get_console_output(server_id, 400).body['output']
  # decrypt the log output to extract the encrypted, base64-encoded password
  encrypted_password = extract_password_from_log(log_output)
end

#list_addressesObject

List all floating IP addresses

Returns

  • 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



16
17
18
19
20
21
22
# 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_flavorsObject

List all flavors (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~Integer> - Id of the flavor

      • ‘name’<~String> - Name of the flavor



13
14
15
16
17
18
19
# 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_flavors_detailObject

List all flavors

Returns

  • 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



15
16
17
18
19
20
21
# 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_imagesObject

List all images (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~Integer> - Id of the image

      • ‘name’<~String> - Name of the image



13
14
15
16
17
18
19
# 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_images_detailObject

List all images

Returns

  • 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



16
17
18
19
20
21
22
# 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_key_pairsObject

List all key pairs

Returns

  • 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

Openstack API Reference



18
19
20
21
22
23
24
# 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_metadata(collection_name, parent_id) ⇒ Object

List metadata for specific collections

Parameters

  • ‘collection_name’<~String> - name of the collection i.e. images, servers for which the metadata is intended.

  • ‘parent_id’<~Integer> - id of the collection i.e. image_id or the server_id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • metadata<~Hash>: hash of key/value pair for the metadata items found



17
18
19
20
21
22
23
# File 'lib/fog/hp/requests/compute/list_metadata.rb', line 17

def (collection_name, parent_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "/#{collection_name}/#{parent_id}/metadata.json"
  )
end

#list_security_groupsObject

List all security groups

Returns

  • 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

Openstack API Reference



28
29
30
31
32
33
34
# 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_server_addresses(server_id) ⇒ Object

List all server addresses

Parameters

  • server_id<~Integer> - Id of server to list addresses for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘addresses’<~Hash>:

      • ‘novanet_7’:<~Array> - The network name can change based on setup



16
17
18
19
20
21
22
# 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_server_private_addresses(server_id, network_name) ⇒ Object

List private server addresses

Parameters

  • 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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘private’<~Array> - Private ip addresses



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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_server_public_addresses(server_id, network_name) ⇒ Object

List public server addresses

Parameters

  • 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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘public’<~Array> - Public ip addresses



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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_server_volumes(server_id) ⇒ Object

List all volumes attached to a server

Parameters

  • server_id<~Integer> - Id of server to list attached volumes for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘volumeAttachments’<~Array>:

      • <~Hash>

        • ‘device’:<~String> - The name of the device

        • ‘serverId’:<~Integer> - The server id to which thsi volume is attached

        • ‘id’:<~Integer> - The volume id

        • ‘volumeId’:<~Integer> - The volume id



20
21
22
23
24
25
26
27
# File 'lib/fog/hp/requests/compute/list_server_volumes.rb', line 20

def list_server_volumes(server_id)
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "servers/#{server_id}/os-volume_attachments"
  )
  response
end

#list_serversObject

List all servers (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • ‘servers’<~Array>:

      • ‘id’<~Integer> - Id of server

      • ‘name<~String> - Name of server



14
15
16
17
18
19
20
# 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_servers_detailObject

List all servers details

Returns

  • 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



23
24
25
26
27
28
29
# 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_server(server_id, type = 'SOFT') ⇒ Object

Reboot an existing server

Parameters

  • server_id<~Integer> - Id of server to reboot

  • type<~String> - Type of reboot, must be in [‘HARD’, ‘SOFT’]



12
13
14
15
# 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

#rebuild_server(server_id, image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/hp/requests/compute/rebuild_server.rb', line 6

def rebuild_server(server_id, image_ref, name, admin_pass=nil, =nil, personality=nil)

  body = { 'rebuild' => {
    'imageRef' => image_ref,
    'name' => name
  }}
  body['rebuild']['adminPass'] = admin_pass if admin_pass
  body['rebuild']['metadata'] =  if 
  body['rebuild']['personality'] = personality if personality
  server_action(server_id, body, 202)
end

#release_address(address_id) ⇒ Object

Release an existing floating IP address

Parameters

  • id<~Integer> - Id of floating IP address to delete



11
12
13
14
15
16
17
# 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

#reloadObject



221
222
223
# File 'lib/fog/hp/compute.rb', line 221

def reload
  @connection.reset
end

#request(params, parse_json = true, &block) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/fog/hp/compute.rb', line 225

def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge!({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept'       => '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
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#resize_server(server_id, flavor_id) ⇒ Object

Reboot an existing server

Parameters

  • server_id<~Integer> - Id of server to resize

  • size<~String> - new size. call list_flavors to get available flavors



12
13
14
15
# 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_resized_server(server_id) ⇒ Object

Revert resizing

Parameters

  • server_id<~Integer> - Id of server to revert



11
12
13
14
# 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_action(server_id, body, expects = 202) ⇒ Object

Server actions for an existing server

Parameters

  • 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)



13
14
15
16
17
18
19
20
# 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

#set_metadata(collection_name, parent_id, metadata = {}) ⇒ Object

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • metadata<~Hash> - key/value pairs of metadata items



18
19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/compute/set_metadata.rb', line 18

def (collection_name, parent_id,  = {})
  request(
    :body     => Fog::JSON.encode({ 'metadata' =>  }),
    :expects  => 200,
    :method   => 'PUT',
    :path     => "#{collection_name}/#{parent_id}/metadata"
  )
end

#update_meta(collection_name, parent_id, key, value) ⇒ Object

Set or update metadata item for specific collections

Parameters

  • ‘collection_name’<~String> - name of the collection i.e. images, servers for which the metadata is intented.

  • ‘parent_id’<~Integer> - id of the collection i.e. image_id or the server_id

  • ‘key’<~String> - key for the metadata item

  • ‘value’<~String> - value for the metadata item

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • meta<~Hash>: hash of key/value pair for the metadata item updated



19
20
21
22
23
24
25
26
# File 'lib/fog/hp/requests/compute/update_meta.rb', line 19

def update_meta(collection_name, parent_id, key, value)
  request(
    :body     => Fog::JSON.encode({ 'meta' => { key => value }}),
    :expects  => 200,
    :method   => 'PUT',
    :path     => "#{collection_name}/#{parent_id}/metadata/#{key}"
  )
end

#update_metadata(collection_name, parent_id, metadata = {}) ⇒ Object

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • metadata<~Hash> - all key/value pairs of metadata items merged with existing metadata



18
19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/compute/update_metadata.rb', line 18

def (collection_name, parent_id,  = {})
  request(
    :body     => Fog::JSON.encode({ 'metadata' =>  }),
    :expects  => 200,
    :method   => 'POST',
    :path     => "#{collection_name}/#{parent_id}/metadata.json"
  )
end

#update_server(server_id, options = {}) ⇒ Object

Update an existing server

Parameters

# server_id<~Integer> - Id of server to update

  • options<~Hash>:

    • adminPass<~String> - New admin password for server

    • name<~String> - New name for server



13
14
15
16
17
18
19
20
# 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