Class: Fog::Compute::RackspaceV2::Real

Inherits:
Rackspace::Service show all
Defined in:
lib/fog/rackspace/compute_v2.rb,
lib/fog/rackspace/requests/compute_v2/get_image.rb,
lib/fog/rackspace/requests/compute_v2/get_flavor.rb,
lib/fog/rackspace/requests/compute_v2/get_server.rb,
lib/fog/rackspace/requests/compute_v2/get_keypair.rb,
lib/fog/rackspace/requests/compute_v2/get_network.rb,
lib/fog/rackspace/requests/compute_v2/list_images.rb,
lib/fog/rackspace/requests/compute_v2/create_image.rb,
lib/fog/rackspace/requests/compute_v2/delete_image.rb,
lib/fog/rackspace/requests/compute_v2/list_flavors.rb,
lib/fog/rackspace/requests/compute_v2/list_servers.rb,
lib/fog/rackspace/requests/compute_v2/set_metadata.rb,
lib/fog/rackspace/requests/compute_v2/attach_volume.rb,
lib/fog/rackspace/requests/compute_v2/create_server.rb,
lib/fog/rackspace/requests/compute_v2/delete_server.rb,
lib/fog/rackspace/requests/compute_v2/list_keypairs.rb,
lib/fog/rackspace/requests/compute_v2/list_metadata.rb,
lib/fog/rackspace/requests/compute_v2/list_networks.rb,
lib/fog/rackspace/requests/compute_v2/reboot_server.rb,
lib/fog/rackspace/requests/compute_v2/rescue_server.rb,
lib/fog/rackspace/requests/compute_v2/resize_server.rb,
lib/fog/rackspace/requests/compute_v2/update_server.rb,
lib/fog/rackspace/requests/compute_v2/create_keypair.rb,
lib/fog/rackspace/requests/compute_v2/create_network.rb,
lib/fog/rackspace/requests/compute_v2/delete_keypair.rb,
lib/fog/rackspace/requests/compute_v2/delete_network.rb,
lib/fog/rackspace/requests/compute_v2/get_attachment.rb,
lib/fog/rackspace/requests/compute_v2/list_addresses.rb,
lib/fog/rackspace/requests/compute_v2/rebuild_server.rb,
lib/fog/rackspace/requests/compute_v2/unrescue_server.rb,
lib/fog/rackspace/requests/compute_v2/update_metadata.rb,
lib/fog/rackspace/requests/compute_v2/list_attachments.rb,
lib/fog/rackspace/requests/compute_v2/delete_attachment.rb,
lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/list_images_detail.rb,
lib/fog/rackspace/requests/compute_v2/list_flavors_detail.rb,
lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/revert_resize_server.rb,
lib/fog/rackspace/requests/compute_v2/confirm_resize_server.rb,
lib/fog/rackspace/requests/compute_v2/change_server_password.rb,
lib/fog/rackspace/requests/compute_v2/list_virtual_interfaces.rb,
lib/fog/rackspace/requests/compute_v2/create_virtual_interface.rb,
lib/fog/rackspace/requests/compute_v2/delete_virtual_interface.rb,
lib/fog/rackspace/requests/compute_v2/list_addresses_by_network.rb

Instance Method Summary collapse

Methods inherited from Rackspace::Service

#request_without_retry, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fog/rackspace/compute_v2.rb', line 146

def initialize(options = {})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  setup_custom_endpoint(options)
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}

  authenticate

  deprecation_warnings(options)

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Instance Method Details

#attach_volume(server_id, volume_id, device) ⇒ Excon::Response

This operation attaches a volume to the specified server.

Parameters:

  • server_id (String)
  • volume_id (String)
  • device (String)

    name of the device /dev/xvd (optional)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • volumeAttachment [Hash]:

        • device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.

        • serverId [String] - The id of the server that attached the volume

        • id [String] - The id of the attachment

        • volumeId [String] - The id of the volume that was attached

Raises:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/rackspace/requests/compute_v2/attach_volume.rb', line 21

def attach_volume(server_id, volume_id, device)
  data = {
    'volumeAttachment' => {
      'volumeId' => volume_id
    }
  }

  data['volumeAttachment']['device'] = device if device

  request(
    :body => Fog::JSON.encode(data),
    :expects => [200],
    :method => 'POST',
    :path => "servers/#{server_id}/os-volume_attachments"
  )
end

#authenticate(options = {}) ⇒ Object



174
175
176
177
178
179
180
181
# File 'lib/fog/rackspace/compute_v2.rb', line 174

def authenticate(options={})
  super({
    :rackspace_api_key => @rackspace_api_key,
    :rackspace_username => @rackspace_username,
    :rackspace_auth_url => @rackspace_auth_url,
    :connection_options => @connection_options
  })
end

#change_server_password(server_id, password) ⇒ Excon::Response

Note:

Though Rackspace does not enforce complexity requirements for the password, the operating system might. If the password is not complex enough, the server might enter an ERROR state.

Changes server admin password

Parameters:

  • server_id (String)
  • password (String)

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/rackspace/requests/compute_v2/change_server_password.rb', line 15

def change_server_password(server_id, password)
  data = {
    'changePassword' => {
      'adminPass' => password
    }
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#confirm_resize_server(server_id) ⇒ Excon::Response

Note:

All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.

Confirm server resize operation

  • Status Transition:

    • VERIFY_RESIZE -> ACTIVE

    • VERIFY_RESIZE -> ERROR (on error)

Parameters:

  • server_id (String)

    The id of the server to revert

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/rackspace/requests/compute_v2/confirm_resize_server.rb', line 18

def confirm_resize_server(server_id)
  data = {
    'confirmResize' => nil
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [204],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#create_image(server_id, name, options = {}) ⇒ Excon::Response

Create an image from a running server

  • State Transition:

    • SAVING -> ACTIVE

    • SAVING -> ERROR (on error)

Parameters:

  • server_id (String)

    Id of server to create image from

  • name (String)

    name for created image

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :metadata (Hash)
    • key value pairs of image metadata

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/rackspace/requests/compute_v2/create_image.rb', line 21

def create_image(server_id, name, options = {})
  data = {
    'createImage' => {
      'name' => name
    }
  }
  data['createImage'].merge!(options)
  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 202,
    :method   => 'POST',
    :path     => "servers/#{server_id}/action"
  )
end

#create_keypair(key_name, attributes = nil) ⇒ Excon::Response

Request a new keypair to be created

Parameters:

  • key_name: (String)

    unique name of the keypair to create

Returns:

  • (Excon::Response)

    response :

    • body [Hash]: -

      • ‘keypair’ [Hash]: -

        • ‘fingerprint’ [String]: unique fingerprint of the keypair

        • ‘name’ [String]: unique name of the keypair

        • ‘private_key’ [String]: the private key of the keypair (only available here, at creation time)

        • ‘public_key’ [String]: the public key of the keypair

        • ‘user_id’ [String]: the user id

Raises:

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/rackspace/requests/compute_v2/create_keypair.rb', line 20

def create_keypair(key_name, attributes = nil)
  key_data = { 'name' => key_name }

  if attributes.is_a?(String)
    Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes."
    key_data.merge!("public_key" => attributes)
  end

  key_data.merge!(attributes) if attributes.is_a?(Hash)

  data = {
    'keypair' => key_data
  }

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

#create_network(label, cidr) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/compute_v2/create_network.rb', line 5

def create_network(label, cidr)
  data = {
    'network' => {
      'label' => label,
      'cidr' => cidr
    }
  }

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

#create_server(name, image_id, flavor_id, min_count, max_count, options = {}) ⇒ Excon::Response

Create server

  • State Transitions

    • BUILD -> ACTIVE

    • BUILD -> ERROR (on error)

Parameters:

  • name (String)

    name of server

  • image_id (String)

    of the image used to create server

  • flavor_id (String)

    id of the flavor of the image

  • min_count (String)
  • max_count (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • metadata (Hash)

    key value pairs of server metadata

  • OS-DCF:diskConfig (String)

    The disk configuration value. (AUTO or MANUAL)

  • personality (Hash)

    Hash containing data to inject into the file system of the cloud server instance during server creation.

  • config_drive (Boolean)

    whether to attach a read-only configuration drive

  • keypair (String)

    Name of the kay-pair to associate with this server.

  • block_device_mapping (Array<Hash>)

    A manually specified block device mapping to fully control the creation and attachment of volumes to this server. Mutually exclusive with :volume_id or :volume_image_id. If provided, leave image_id as “”. See developer.openstack.org/api-ref-compute-v2-ext.html#ext-os-block-device-mapping-v2-boot for details.

  • boot_volume_id (String)

    Id of a pre-created bootable volume to use for this server. If provided, leave image_id as “”.

  • boot_image_id (String)

    Id of an image to create a bootable volume from and attach to this server. If provided, leave image_id as “”.

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • server [Hash]:

        • name [String] - name of server

        • imageRef [String] - id of image used to create server

        • flavorRef [String] - id of flavor used to create server

        • OS-DCF:diskConfig [String] - The disk configuration value.

        • name [String] - name of server

        • metadata [Hash] - Metadata key and value pairs.

        • personality [Array]:

          • [Hash]:

            • path - path of the file created

            • contents - Base 64 encoded file contents

        • networks [Array]:

          • [Hash]:

            • uuid [String] - uuid of attached network

        • config_drive [Boolean]: Wether to use a config drive or not

        • user_data [String]: User data for cloud init

Raises:

See Also:



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fog/rackspace/requests/compute_v2/create_server.rb', line 54

def create_server(name, image_id, flavor_id, min_count, max_count, options = {})
  data = {
    'server' => {
      'name'      => name,
      'imageRef'  => image_id,
      'flavorRef' => flavor_id,
      'minCount'  => min_count,
      'maxCount'  => max_count
    }
  }

  data['server']['adminPass'] = options[:password] unless options[:password].nil?
  data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
  data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
  data['server']['personality'] = options[:personality] unless options[:personality].nil?
  data['server']['config_drive'] = options[:config_drive] unless options[:config_drive].nil?
  data['server']['user_data'] = options[:user_data] unless options[:user_data].nil?
  data['server']['networks'] = options[:networks] || [
    { :uuid => '00000000-0000-0000-0000-000000000000' },
    { :uuid => '11111111-1111-1111-1111-111111111111' }
  ]

  if options[:keypair]
    Fog::Logger.deprecation(":keypair has been depreciated. Please use :key_name instead.")
    options[:key_name] = options[:keypair]
  end

  data['server']['key_name'] = options[:key_name] unless options[:key_name].nil?

  if options[:block_device_mapping]
    if options[:boot_volume_id]
      Fog::Logger.warning("Manual :block_device_mapping overrides :boot_volume_id in #create_server!")
    end

    if options[:boot_image_id]
      Fog::Logger.warning("Manual :block_device_mapping overrides :boot_image_id in #create_server!")
    end

    data['server']['block_device_mapping_v2'] = options[:block_device_mapping]
  else
    if options[:boot_volume_id]
      if options[:boot_image_id]
        Fog::Logger.warning(":boot_volume_id overrides :boot_image_id!")
      end

      data['server']['block_device_mapping_v2'] = [{
        'boot_index' => '0',
        'uuid' => options[:boot_volume_id],
        'source_type' => 'volume',
        'destination_type' => 'volume',
        'volume_size' => 100
      }]
    end

    if options[:boot_image_id]
      data['server']['block_device_mapping_v2'] = [{
        'boot_index' => '0',
        'uuid' => options[:boot_image_id],
        'source_type' => 'image',
        'destination_type' => 'volume',
        'volume_size' => 100
      }]
    end
end

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

#create_virtual_interface(server_id, network_id) ⇒ Object

Creates virtual interface for a server

Parameters:

  • server_id (String)

    The server id to create the virtual interface on

  • network_id (String)

    The network id to attach the virtual interface to

Raises:

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/compute_v2/create_virtual_interface.rb', line 13

def create_virtual_interface(server_id, network_id)
  data = {
    :virtual_interface => {
      :network_id => network_id
    }
  }

  request(
    :expects => [200],
    :method => 'POST',
    :path => "servers/#{server_id}/os-virtual-interfacesv2",
    :body => Fog::JSON.encode(data)
  )
end

#delete_attachment(server_id, volume_id) ⇒ Excon::Response

Deletes a specified volume attachment from a specified server instance.

Parameters:

  • server_id (String)

    id of server containing volume to delete

  • volume_id (String)

    id of volume on server to delete

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



14
15
16
17
18
19
20
# File 'lib/fog/rackspace/requests/compute_v2/delete_attachment.rb', line 14

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

#delete_image(image_id) ⇒ Excon::Response

Delete an image

Parameters:

  • image_id (String)

    Id of image to delete

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/compute_v2/delete_image.rb', line 13

def delete_image(image_id)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => "images/#{image_id}"
  )
end

#delete_keypair(key_name) ⇒ Excon::Response

Delete the key specified with key_name

Parameters:

  • key_name (String)

    name of the key to delete

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/compute_v2/delete_keypair.rb', line 13

def delete_keypair(key_name)
  request(
    :method   => 'DELETE',
    :expects  => 202,
    :path     => "/os-keypairs/#{URI.escape(key_name)}"
  )
end

#delete_metadata_item(collection, obj_id, key) ⇒ Excon::Response

Deletes a metadata item.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

  • key (String)

    the key of the metadata to delete

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



15
16
17
18
19
20
21
# File 'lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb', line 15

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

#delete_network(id) ⇒ Object



5
6
7
# File 'lib/fog/rackspace/requests/compute_v2/delete_network.rb', line 5

def delete_network(id)
  request(:method => 'DELETE', :path => "os-networksv2/#{id}", :expects => 202)
end

#delete_server(server_id) ⇒ Excon::Response

Deletes a specified server instance from the system.

Parameters:

  • server_id (String)

    the id of the server to delete

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/compute_v2/delete_server.rb', line 13

def delete_server(server_id)
  request({
    :expects => [204],
    :method => 'DELETE',
    :path => "servers/#{server_id}"
  }, false)
end

#delete_virtual_interface(server_id, interface_id) ⇒ Object

Deletes virtual interface from server

Parameters:

  • server_id (String)

    The server id that contains the virtual interface

  • interface_id (String)

    The id of the virtual interface

Raises:

See Also:



13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/compute_v2/delete_virtual_interface.rb', line 13

def delete_virtual_interface(server_id, interface_id)
  request(
    :expects => [200],
    :method => 'DELETE',
    :path => "servers/#{server_id}/os-virtual-interfacesv2/#{interface_id}"
  )
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



195
196
197
# File 'lib/fog/rackspace/compute_v2.rb', line 195

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_compute_url)
end

#get_attachment(server_id, volume_id) ⇒ Excon::Response

Retrieves attachment

Parameters:

  • server_id (String)
  • volume_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • volumeAttachment [Hash]:

        • device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.

        • serverId [String] - The id of the server that attached the volume

        • id [String] - The id of the attachment

        • volumeId [String] - The id of the volume that was attached

Raises:

See Also:



20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/compute_v2/get_attachment.rb', line 20

def get_attachment(server_id, volume_id)
  request(
    :expects => [200, 203, 300],
    :method => 'GET',
    :path => "servers/#{server_id}/os-volume_attachments/#{volume_id}"
  )
end

#get_flavor(flavor_id) ⇒ Excon::Response

Retrieves flavor detail

Parameters:

  • flavor_id (Sring)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • flavor [Hash]:

        • disk [Fixnum] - disk size in GB

        • id [String] - id of flavor

        • name [String] - name of flavor

        • ram [Fixnum] - amount of ram in MB

        • swap [Fixnum] - amount of swap in GB

        • vcpus [Fixnum] - number of virtual CPUs

        • links [Array] - links to flavor

Raises:

See Also:



22
23
24
25
26
27
28
# File 'lib/fog/rackspace/requests/compute_v2/get_flavor.rb', line 22

def get_flavor(flavor_id)
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => "flavors/#{Fog::Rackspace.escape(flavor_id)}"
  )
end

#get_image(image_id) ⇒ Excon::Response

Retrieves image detail

Parameters:

  • image_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • image [Hash]:

        • OS-DCF:diskConfig [String] - The disk configuration value.

        • created [String] - created timestamp

        • id [String] - id of image

        • metadata [Hash] - image metadata

        • minDisk [Fixnum]

        • minRam [Fixnum]

        • name [String] - name of image

        • progress [Fixnum] - progress complete. Value is from 0 to 100.

        • status [String] - status of current image

        • updated [String] - updated timestamp

        • links [Array] - links to flavor

Raises:

See Also:



26
27
28
29
30
31
32
# File 'lib/fog/rackspace/requests/compute_v2/get_image.rb', line 26

def get_image(image_id)
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => "images/#{Fog::Rackspace.escape(image_id)}"
  )
end

#get_keypair(key_name) ⇒ Excon::Response

Retreive single keypair details

Parameters:

  • key_name (String)

    name of the key for which to request the details

Returns:

  • (Excon::Response)

    response :

    • body [Hash]: -

      • ‘keypair’ [Hash]: -

        • ‘fingerprint’ [String]: unique fingerprint of the keypair

        • ‘name’ [String]: unique name of the keypair

        • ‘public_key’ [String]: the public key assigne to the keypair

Raises:

See Also:



18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/compute_v2/get_keypair.rb', line 18

def get_keypair(key_name)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/os-keypairs/#{key_name}"
  )
end

#get_metadata_item(collection, obj_id, key) ⇒ Excon::Response

Retrieves single metadatum item by key.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

  • key (String)

    the key of the metadata to retrieve

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • meta [Hash]:

Raises:

See Also:



17
18
19
20
21
22
23
# File 'lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb', line 17

def (collection, obj_id, key)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "#{collection}/#{obj_id}/metadata/#{key}"
  )
end

#get_network(id) ⇒ Object



5
6
7
# File 'lib/fog/rackspace/requests/compute_v2/get_network.rb', line 5

def get_network(id)
  request(:method => 'GET', :path => "os-networksv2/#{id}", :expects => 200)
end

#get_server(server_id) ⇒ Excon::Response

Retrieves server detail

Parameters:

  • server_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • server [Hash]:

        • OS-DCF:diskConfig [String] - The disk configuration value.

        • OS-EXT-STS:power_state [Fixnum] - The power state.

        • OS-EXT-STS:task_state [String] - The task state.

        • OS-EXT-STS:vm_state [String] - The VM state.

        • accessIPv4 [String] - The public IP version 4 access address.

        • accessIPv6 [String] - The public IP version 6 access address.

        • addresses [Hash] - Public and private IP addresses, The version field indicates whether the IP address is version 4 or 6.

        • created [String] - created timestamp

        • hostId [String] - The host id.

        • id [String] - id of image

        • image [Hash]:

          • id [String] - id of the image

          • links [Hash] - links to image

        • flavor [Hash]:

          • id [String] - id of the flavor

          • links [Hash] - links to flavor

        • links [Hash] - links to server

        • metadata [Hash] - server metadata

        • name [String] - name of server

        • progress [Fixnum] - progress complete. Value is from 0 to 100.

        • rax-bandwidth:bandwidth [Array] - The amount of bandwidth used for the specified audit period.

        • status [String] - The server status.

        • tenant_id [String] - The tenant ID.

        • updated [String] - updated timestamp

        • user_id [Array] - The user ID.

Raises:

See Also:



40
41
42
43
44
45
46
# File 'lib/fog/rackspace/requests/compute_v2/get_server.rb', line 40

def get_server(server_id)
  request(
    :expects => [200, 203, 300],
    :method => 'GET',
    :path => "servers/#{server_id}"
  )
end

#list_addresses(server_id) ⇒ Excon::Response

Lists all networks and addresses associated with a specified server.

Parameters:

  • server_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • addresses [Hash] - key is the network name and the value are an array of addresses allocated for that network

Raises:



14
15
16
17
18
19
20
# File 'lib/fog/rackspace/requests/compute_v2/list_addresses.rb', line 14

def list_addresses(server_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/servers/#{server_id}/ips"
  )
end

#list_addresses_by_network(server_id, network_id) ⇒ Excon::Response

Lists all addresses associated with a specified server and network

Parameters:

  • server_id (String)
  • network_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • network [Hash]:

        • id [String] - id of network

        • ip [Array]:

          • [Hash]:

            • version [Fixnum] - version of the address

            • addr [String] - ip address

Raises:

See Also:



21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/compute_v2/list_addresses_by_network.rb', line 21

def list_addresses_by_network(server_id, network_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "servers/#{server_id}/ips/#{network_id}"
  )
end

#list_attachments(server_id) ⇒ Excon::Response

Retrieves list of attached volumes

Parameters:

  • server_id (String)

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • volumeAttachment [Array]:

        • [Hash]:

          • device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.

          • serverId [String] - The id of the server that attached the volume

          • id [String] - The id of the attachment

          • volumeId [String] - The id of the volume that was attached

Raises:

See Also:



20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/compute_v2/list_attachments.rb', line 20

def list_attachments(server_id)
  request(
    :expects => [200, 203, 300],
    :method => 'GET',
    :path => "servers/#{server_id}/os-volume_attachments"
  )
end

#list_flavorsExcon::Response

Retrieves a list of flavors

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • flavors [Array]:

        • [Hash]:

          • id [String] - flavor id

          • links [Array] - flavor links

          • name [String] - flavor name

Raises:

See Also:



18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/compute_v2/list_flavors.rb', line 18

def list_flavors
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => 'flavors'
  )
end

#list_flavors_detailExcon::Response

Retrieves a list of flavors

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • flavors [Array]:

        • [Hash]:

          • id [String] - flavor id

          • links [Array] - flavor links

          • name [String] - flavor name

          • ram [Fixnum] - flavor ram

          • disk [Fixnum] - flavor disk

          • vcpus [Fixnum] - flavor vcpus

Raises:

See Also:



21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/compute_v2/list_flavors_detail.rb', line 21

def list_flavors_detail
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => 'flavors/detail'
  )
end

#list_images(options = {}) ⇒ Excon::Response

Retrieves a list of images

Parameters

  • options<~String>:

    • ‘name’<~String> - Filters the list of images by image name

    • ‘limit’<~String> - Maximum number of objects to return

    • ‘marker’<~String> - Only return objects whose name is greater than marker

    • ‘status’<~String> - Filters the list of images by status

    • ‘type’<~String> - Filters base Rackspace images or anyn custom server images that have been created

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • images [Array]:

        • [Hash]:

          • id [String] - image id

          • links [Array] - image links

          • name [String] - image name

Raises:

See Also:



26
27
28
29
30
31
32
33
34
# File 'lib/fog/rackspace/requests/compute_v2/list_images.rb', line 26

def list_images(options = {})
  options = options.reject {|key, value| value.nil?}
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => 'images',
    :query => {'format' => 'json'}.merge!(options)
  )
end

#list_images_detail(options = {}) ⇒ Excon::Response

Retrieves a list of images

Parameters

  • options<~String>:

    • ‘name’<~String> - Filters the list of images by image name

    • ‘limit’<~String> - Maximum number of objects to return

    • ‘marker’<~String> - Only return objects whose name is greater than marker

    • ‘status’<~String> - Filters the list of images by status

    • ‘type’<~String> - Filters base Rackspace images or anyn custom server images that have been created

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • images [Array]:

        • [Hash]:

          • id [String] - image id

          • links [Array] - image links

          • name [String] - image name

          • minDisk [Fixnum] - image minimum disk required

          • minRam [Fixnum] - image minimum ram required

          • created [String] - image creation date (ISO 8601 format)

          • updated [String] - date of most recent image update

          • state [String] - image status (e.g. ACTIVE, SAVING, ERROR)

          • progress [Fixnum] - image saving progress

Raises:

See Also:



33
34
35
36
37
38
39
40
41
# File 'lib/fog/rackspace/requests/compute_v2/list_images_detail.rb', line 33

def list_images_detail(options = {})
  options = options.reject {|key, value| value.nil?}
  request(
    :expects => [200, 203],
    :method => 'GET',
    :path => 'images/detail',
    :query => {'format' => 'json'}.merge!(options)
  )
end

#list_keypairsExcon::Response

Returns a list of all key pairs associated with an account.

Returns:

  • (Excon::Response)

    response :

    • body [Hash]: -

      • ‘keypairs’ [Array]: list of keypairs

        • ‘keypair’ [Hash]: -

          * 'fingerprint' [String]: unique fingerprint of the keypair
          * 'name' [String]: unique name of the keypair
          * 'public_key' [String]: the public key assigned to the keypair
          

Raises:

See Also:



18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/compute_v2/list_keypairs.rb', line 18

def list_keypairs
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => 'os-keypairs'
  )
end

#list_metadata(collection, obj_id) ⇒ Excon::Response

Retrieves all metadata associated with a server or an image.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • meta [Hash]:

Raises:

See Also:



16
17
18
19
20
21
22
# File 'lib/fog/rackspace/requests/compute_v2/list_metadata.rb', line 16

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

#list_networksObject



5
6
7
# File 'lib/fog/rackspace/requests/compute_v2/list_networks.rb', line 5

def list_networks
  request(:method => 'GET', :path => 'os-networksv2', :expects => 200)
end

#list_serversExcon::Response

Retrieves list of servers

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • server [Hash]:

        • OS-DCF:diskConfig [String] - The disk configuration value.

        • OS-EXT-STS:power_state [Fixnum] - The power state.

        • OS-EXT-STS:task_state [String] - The task state.

        • OS-EXT-STS:vm_state [String] - The VM state.

        • accessIPv4 [String] - The public IP version 4 access address.

        • accessIPv6 [String] - The public IP version 6 access address.

        • addresses [Hash] - Public and private IP addresses, The version field indicates whether the IP address is version 4 or 6.

        • created [String] - created timestamp

        • hostId [String] - The host id.

        • id [String] - id of image

        • image [Hash]:

          • id [String] - id of the image

          • links [Hash] - links to image

        • flavor [Hash]:

          • id [String] - id of the flavor

          • links [Hash] - links to flavor

        • links [Hash] - links to server

        • metadata [Hash] - server metadata

        • name [String] - name of server

        • progress [Fixnum] - progress complete. Value is from 0 to 100.

        • rax-bandwidth:bandwidth [Array] - The amount of bandwidth used for the specified audit period.

        • status [String] - The server status.

        • tenant_id [String] - The tenant ID.

        • updated [String] - updated timestamp

        • user_id [Array] - The user ID.

Raises:

See Also:



39
40
41
42
43
44
45
# File 'lib/fog/rackspace/requests/compute_v2/list_servers.rb', line 39

def list_servers
  request(
    :expects => [200, 203, 300],
    :method => 'GET',
    :path => 'servers/detail'
  )
end

#list_virtual_interfaces(server_id) ⇒ Object

Lists virtual interfaces for a server



12
13
14
15
16
17
18
# File 'lib/fog/rackspace/requests/compute_v2/list_virtual_interfaces.rb', line 12

def list_virtual_interfaces(server_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "servers/#{server_id}/os-virtual-interfacesv2"
  )
end

#reboot_server(server_id, type) ⇒ Object

Reboots server

Parameters:

  • server_id (String)
  • type (String<SOFT,HARD>)

    type of reboot

Raises:

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/compute_v2/reboot_server.rb', line 13

def reboot_server(server_id, type)
  data = {
    'reboot' => {
      'type' => type
    }
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#rebuild_server(server_id, image_id, options = {}) ⇒ Excon::Response

The rebuild operation removes all data on the server and replaces it with the specified image. The serverRef and all IP addresses remain the same. If you specify name, metadata, accessIPv4, or accessIPv6 in the rebuild request, new values replace existing values. Otherwise, these values do not change.

  • Status Transition:

    • ACTIVE -> REBUILD -> ACTIVE

    • ACTIVE -> REBUILD -> ERROR (on error)

Parameters:

  • server_id (String)

    id of the server to rebuild

  • image_id (String)

    id of image used to rebuild the server

  • options (Hash) (defaults to: {})

Options Hash (options):

  • accessIPv4 (String)

    The IP version 4 address.

  • accessIPv6 (String)

    The IP version 6 address.

  • adminPass (String)

    The administrator password.

  • metadata (Hash)

    key value pairs of server metadata

  • OS-DCF:diskConfig (String)

    The disk configuration value. (AUTO or MANUAL)

  • personality (Hash)

    Hash containing data to inject into the file system of the cloud server instance during server creation.

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • server [Hash]:

        • name [String] - name of server

        • imageRef [String] - id of image used to create server

        • flavorRef [String] - id of flavor used to create server

        • OS-DCF:diskConfig [String] - The disk configuration value.

        • name [String] - name of server

        • metadata [Hash] - Metadata key and value pairs.

        • personality [Array]:

          * [Hash]:
            * path - path of the file created
            * contents - Base 64 encoded file contents
          
        • networks [Array]:

          • [Hash]:

            • uuid [String] - uuid of attached network

Raises:

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/rackspace/requests/compute_v2/rebuild_server.rb', line 45

def rebuild_server(server_id, image_id, options={})
  data = {
    'rebuild' => options || {}
  }
  data['rebuild']['imageRef'] = image_id

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#regionObject



191
192
193
# File 'lib/fog/rackspace/compute_v2.rb', line 191

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/fog/rackspace/compute_v2.rb', line 162

def request(params, parse_json = true)
  super
rescue Excon::Errors::NotFound => error
  raise NotFound.slurp(error, self)
rescue Excon::Errors::BadRequest => error
  raise BadRequest.slurp(error, self)
rescue Excon::Errors::InternalServerError => error
  raise InternalServerError.slurp(error, self)
rescue Excon::Errors::HTTPStatusError => error
  raise ServiceError.slurp(error, self)
end

#request_id_headerObject



187
188
189
# File 'lib/fog/rackspace/compute_v2.rb', line 187

def request_id_header
  "x-compute-request-id"
end

#rescue_server(server_id) ⇒ Excon::Response

Note:

Rescue mode is only guaranteed to be active for 90 minutes

Puts server into rescue mode

  • Status Transition:

    • PREP_RESCUE -> RESCUE

    • PREP_RESCUE -> ACTIVE (on error)

Parameters:

  • server_id (String)

    id of server to rescue

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/rackspace/requests/compute_v2/rescue_server.rb', line 18

def rescue_server(server_id)
  data = {
    'rescue' => nil
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [200],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#resize_server(server_id, flavor_id) ⇒ Excon::Response

Note:

All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.

Reverts server resize operation

  • Status Transition:

    • VERIFY_RESIZE -> ACTIVE

    • VERIFY_RESIZE -> ERROR (on error)

Parameters:

  • server_id (String)

    id of server to resize

  • flavor_id (String)

    id of the desired flavor

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/rackspace/requests/compute_v2/resize_server.rb', line 19

def resize_server(server_id, flavor_id)
  data = {
    'resize' => {
      'flavorRef' => flavor_id
    }
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#revert_resize_server(server_id) ⇒ Excon::Response

Note:

All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.

Reverts server resize operation

  • Status Transition:

    • VERIFY_RESIZE -> ACTIVE

    • VERIFY_RESIZE -> ERROR (on error)

Parameters:

  • server_id (String)

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/rackspace/requests/compute_v2/revert_resize_server.rb', line 19

def revert_resize_server(server_id)
  data = {
    'revertResize' => nil
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#service_nameObject



183
184
185
# File 'lib/fog/rackspace/compute_v2.rb', line 183

def service_name
  :cloudServersOpenStack
end

#set_metadata(collection, obj_id, metadata = {}) ⇒ Excon::Response

Sets metadata associated with a server or an image.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

  • metadata (Hash) (defaults to: {})

    key value pairs of metadata

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • metadata [Hash]:

Raises:

See Also:



17
18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/compute_v2/set_metadata.rb', line 17

def (collection, obj_id,  = {})
  request(
    :expects => [200, 203],
    :method => 'PUT',
    :path => "#{collection}/#{obj_id}/metadata",
    :body => Fog::JSON.encode('metadata' => )
  )
end

#set_metadata_item(collection, obj_id, key, value) ⇒ Excon::Response

Sets a single metadatum item by key.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

  • key (String)

    the key of the metadata to set

  • value (String)

    the value of the metadata to set

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • meta [Hash]:

Raises:

See Also:



18
19
20
21
22
23
24
25
# File 'lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb', line 18

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

#unrescue_server(server_id) ⇒ Excon::Response

Take server out of rescue mode

  • Status Transition:

    • RESCUE -> PREP_UNRESCUE -> ACTIVE

    • RESCUE -> ERROR (on error)

Parameters:

  • server_id (String)

    id of server

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/rackspace/requests/compute_v2/unrescue_server.rb', line 17

def unrescue_server(server_id)
  data = {
    'unrescue' => nil
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [202],
    :method => 'POST',
    :path => "servers/#{server_id}/action"
  )
end

#update_metadata(collection, obj_id, metadata = {}) ⇒ Excon::Response

Updates metadata items for a specified server or image.

Parameters:

  • collection (String<images, servers>)

    type of metadata

  • obj_id (String)

    id of the object where the metadata is attached

  • metadata (Hash) (defaults to: {})

    key value pairs of metadata

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • metadata [Hash]:

Raises:

See Also:



17
18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/compute_v2/update_metadata.rb', line 17

def (collection, obj_id,  = {})
  request(
    :expects => [200, 203],
    :method => 'POST',
    :path => "#{collection}/#{obj_id}/metadata",
    :body => Fog::JSON.encode('metadata' => )
  )
end

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

Note:

If you edit the server name, the server host name does not change. Also, server names are not guaranteed to be unique.

Update the editable attributes of a specified server.

Parameters:

  • server_id (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • name (Hash)

    name for server

  • accessIPv4 (String)

    The IP version 4 address.

  • accessIPv6 (Hash)

    The IP version 6 address.

Raises:

See Also:



17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/compute_v2/update_server.rb', line 17

def update_server(server_id, options={})
  data = options.is_a?(Hash) ? options : { 'name' => options } #LEGACY - second parameter was previously server name

  request(
    :body => Fog::JSON.encode('server' => data),
    :expects => [200],
    :method => 'PUT',
    :path => "servers/#{server_id}"
  )
end