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

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/hp/compute.rb,
lib/rackspace-fog/hp/requests/compute/get_address.rb,
lib/rackspace-fog/hp/requests/compute/list_images.rb,
lib/rackspace-fog/hp/requests/compute/create_image.rb,
lib/rackspace-fog/hp/requests/compute/delete_image.rb,
lib/rackspace-fog/hp/requests/compute/list_flavors.rb,
lib/rackspace-fog/hp/requests/compute/list_servers.rb,
lib/rackspace-fog/hp/requests/compute/create_server.rb,
lib/rackspace-fog/hp/requests/compute/delete_server.rb,
lib/rackspace-fog/hp/requests/compute/reboot_server.rb,
lib/rackspace-fog/hp/requests/compute/resize_server.rb,
lib/rackspace-fog/hp/requests/compute/server_action.rb,
lib/rackspace-fog/hp/requests/compute/update_server.rb,
lib/rackspace-fog/hp/requests/compute/list_addresses.rb,
lib/rackspace-fog/hp/requests/compute/list_key_pairs.rb,
lib/rackspace-fog/hp/requests/compute/rebuild_server.rb,
lib/rackspace-fog/hp/requests/compute/create_key_pair.rb,
lib/rackspace-fog/hp/requests/compute/delete_key_pair.rb,
lib/rackspace-fog/hp/requests/compute/release_address.rb,
lib/rackspace-fog/hp/requests/compute/allocate_address.rb,
lib/rackspace-fog/hp/requests/compute/associate_address.rb,
lib/rackspace-fog/hp/requests/compute/get_image_details.rb,
lib/rackspace-fog/hp/requests/compute/get_flavor_details.rb,
lib/rackspace-fog/hp/requests/compute/get_security_group.rb,
lib/rackspace-fog/hp/requests/compute/get_server_details.rb,
lib/rackspace-fog/hp/requests/compute/list_images_detail.rb,
lib/rackspace-fog/hp/requests/compute/list_flavors_detail.rb,
lib/rackspace-fog/hp/requests/compute/list_servers_detail.rb,
lib/rackspace-fog/hp/requests/compute/disassociate_address.rb,
lib/rackspace-fog/hp/requests/compute/list_security_groups.rb,
lib/rackspace-fog/hp/requests/compute/create_security_group.rb,
lib/rackspace-fog/hp/requests/compute/delete_security_group.rb,
lib/rackspace-fog/hp/requests/compute/list_server_addresses.rb,
lib/rackspace-fog/hp/requests/compute/revert_resized_server.rb,
lib/rackspace-fog/hp/requests/compute/change_password_server.rb,
lib/rackspace-fog/hp/requests/compute/confirm_resized_server.rb,
lib/rackspace-fog/hp/requests/compute/create_security_group_rule.rb,
lib/rackspace-fog/hp/requests/compute/delete_security_group_rule.rb,
lib/rackspace-fog/hp/requests/compute/list_server_public_addresses.rb,
lib/rackspace-fog/hp/requests/compute/list_server_private_addresses.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rackspace-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

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/rackspace-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/rackspace-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

#change_password_server(server_id, admin_password) ⇒ Object



6
7
8
9
# File 'lib/rackspace-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/rackspace-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
26
27
28
# File 'lib/rackspace-fog/hp/requests/compute/create_image.rb', line 18

def create_image(server_id, name,  = {})
  body = { 'createImage' =>
               { 'name' => name,
                 'metadata' =>
                     { 'ImageType' => [:image_type],
                       'ImageVersion' => [:image_version]
                     }
               }
         }
  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/rackspace-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_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/rackspace-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/rackspace-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

  • 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

Returns

  • 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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
# File 'lib/rackspace-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_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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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/rackspace-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/rackspace-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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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/rackspace-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/rackspace-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_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/rackspace-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/rackspace-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/rackspace-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/rackspace-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/rackspace-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



146
147
148
# File 'lib/rackspace-fog/hp/compute.rb', line 146

def reload
  @connection.reset
end

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



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/rackspace-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

#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/rackspace-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/rackspace-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/rackspace-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_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/rackspace-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