Class: Fog::Rackspace::Databases::Real

Inherits:
Service
  • Object
show all
Defined in:
lib/fog/rackspace/databases.rb,
lib/fog/rackspace/requests/databases/get_flavor.rb,
lib/fog/rackspace/requests/databases/list_users.rb,
lib/fog/rackspace/requests/databases/create_user.rb,
lib/fog/rackspace/requests/databases/delete_user.rb,
lib/fog/rackspace/requests/databases/get_instance.rb,
lib/fog/rackspace/requests/databases/list_flavors.rb,
lib/fog/rackspace/requests/databases/list_databases.rb,
lib/fog/rackspace/requests/databases/list_instances.rb,
lib/fog/rackspace/requests/databases/check_root_user.rb,
lib/fog/rackspace/requests/databases/create_database.rb,
lib/fog/rackspace/requests/databases/create_instance.rb,
lib/fog/rackspace/requests/databases/delete_database.rb,
lib/fog/rackspace/requests/databases/delete_instance.rb,
lib/fog/rackspace/requests/databases/resize_instance.rb,
lib/fog/rackspace/requests/databases/enable_root_user.rb,
lib/fog/rackspace/requests/databases/restart_instance.rb,
lib/fog/rackspace/requests/databases/resize_instance_volume.rb

Instance Method Summary collapse

Methods inherited from Service

#request_without_retry, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/rackspace/databases.rb', line 72

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

  authenticate

  deprecation_warnings(options)

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

Instance Method Details

#authenticate(options = {}) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/fog/rackspace/databases.rb', line 104

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

#check_root_user(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/check_root_user.rb', line 5

def check_root_user(instance_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "instances/#{instance_id}/root"
  )
end

#create_database(instance_id, name, options = {}) ⇒ Object



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

def create_database(instance_id, name, options = {})
  data = {
    'databases' => [{
      'name' => name,
      'character_set' => options[:character_set] || 'utf8',
      'collate' => options[:collate] || 'utf8_general_ci'
    }]
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => 202,
    :method => 'POST',
    :path => "instances/#{instance_id}/databases"
  )
end

#create_instance(name, flavor_id, volume_size, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/databases/create_instance.rb', line 5

def create_instance(name, flavor_id, volume_size, options = {})
  data = {
    'instance' => {
      'name' => name,
      'flavorRef' => flavor_id,
      'volume' => {
        'size' => volume_size
      },
      'databases' => [
      ]
    }
  }

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

#create_user(instance_id, name, password, options = {}) ⇒ Object



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

def create_user(instance_id, name, password, options = {})
  data = {
    'users' => [{
      'name' => name,
      'password' => password,
      'databases' => options[:databases] || []
    }]
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => 202,
    :method => 'POST',
    :path => "instances/#{instance_id}/users"
  )
end

#delete_database(instance_id, name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/delete_database.rb', line 5

def delete_database(instance_id, name)
  request(
    :expects => 202,
    :method => 'DELETE',
    :path => "instances/#{instance_id}/databases/#{name}"
  )
end

#delete_instance(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/delete_instance.rb', line 5

def delete_instance(instance_id)
  request(
    :expects => 202,
    :method => 'DELETE',
    :path => "instances/#{instance_id}"
  )
end

#delete_user(instance_id, name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/delete_user.rb', line 5

def delete_user(instance_id, name)
  request(
    :expects => 202,
    :method => 'DELETE',
    :path => "instances/#{instance_id}/users/#{name}"
  )
end

#enable_root_user(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/enable_root_user.rb', line 5

def enable_root_user(instance_id)
  request(
    :expects => 200,
    :method => 'POST',
    :path => "instances/#{instance_id}/root"
  )
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



100
101
102
# File 'lib/fog/rackspace/databases.rb', line 100

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

#get_flavor(flavor_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/get_flavor.rb', line 5

def get_flavor(flavor_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "flavors/#{flavor_id}"
  )
end

#get_instance(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/get_instance.rb', line 5

def get_instance(instance_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "instances/#{instance_id}"
  )
end

#list_databases(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/list_databases.rb', line 5

def list_databases(instance_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "instances/#{instance_id}/databases"
  )
end

#list_flavorsObject



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/list_flavors.rb', line 5

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

#list_instancesObject



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/list_instances.rb', line 5

def list_instances()
  request(
    :expects => 200,
    :method => 'GET',
    :path => 'instances'
  )
end

#list_users(instance_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/databases/list_users.rb', line 5

def list_users(instance_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "instances/#{instance_id}/users"
  )
end

#regionObject



68
69
70
# File 'lib/fog/rackspace/databases.rb', line 68

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/rackspace/databases.rb', line 88

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

#resize_instance(instance_id, flavor_id) ⇒ Object



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

def resize_instance(instance_id, flavor_id)
  data = {
    'resize' => {
      'flavorRef' => flavor_id
    }
  }

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

#resize_instance_volume(instance_id, volume_size) ⇒ Object



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

def resize_instance_volume(instance_id, volume_size)
  data = {
    'resize' => {
      'volume' => {
        'size' => volume_size
      }
    }
  }

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

#restart_instance(instance_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/rackspace/requests/databases/restart_instance.rb', line 5

def restart_instance(instance_id)
  data = {
    'restart' => {}
  }

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

#service_nameObject



64
65
66
# File 'lib/fog/rackspace/databases.rb', line 64

def service_name
  :cloudDatabases
end