Class: IbmCloudRest::Server
Instance Attribute Summary collapse
-
#available_instances ⇒ Object
Lists all “available” instances.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
Instance Method Summary collapse
-
#addresses ⇒ Object
Lists all addresses on the server.
-
#available_instance?(ref_or_name) ⇒ Boolean
Checks that a instance is set as available.
-
#create_db(name) ⇒ Object
Create a instance.
- #default_instance ⇒ Object
- #default_instance=(name, create_unless_exists = true) ⇒ Object
-
#define_available_instance(reference, db_name, create_unless_exists = true) ⇒ Object
Adds a new available instance and create it unless it already exists.
-
#images ⇒ Object
Lists all images on the server.
-
#info ⇒ Object
GET the welcome message.
-
#initialize(server = 'https://www.ibm.com', base_path = '/cloud/developer/api/rest/20090403', uuid_batch_count = 1000) ⇒ Server
constructor
A new instance of Server.
-
#instance(name) ⇒ Object
Returns a IbmCloudRest::instance for the given name.
-
#instance!(name) ⇒ Object
Creates the instance if it doesn’t exist.
-
#instances ⇒ Object
Lists all instances on the server.
-
#keys ⇒ Object
Lists all keys on the server.
-
#next_uuid(count = @uuid_batch_count) ⇒ Object
Retrive an unused UUID from CouchDB.
-
#restart! ⇒ Object
Restart the CouchDB instance.
-
#storages ⇒ Object
Lists all storages on the server.
Constructor Details
#initialize(server = 'https://www.ibm.com', base_path = '/cloud/developer/api/rest/20090403', uuid_batch_count = 1000) ⇒ Server
Returns a new instance of Server.
4 5 6 7 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 4 def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403', uuid_batch_count = 1000) @uri = server+base_path @uuid_batch_count = uuid_batch_count end |
Instance Attribute Details
#available_instances ⇒ Object
Lists all “available” instances. An available instance, is a instance that was specified as avaiable by your code. It allows to define common instances to use and reuse in your code
13 14 15 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 13 def available_instances @available_instances end |
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 3 def uri @uri end |
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
3 4 5 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 3 def uuid_batch_count @uuid_batch_count end |
Instance Method Details
#addresses ⇒ Object
Lists all addresses on the server
53 54 55 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 53 def addresses IbmCloudRest.get "#{@uri}/addresses" end |
#available_instance?(ref_or_name) ⇒ Boolean
Checks that a instance is set as available
Example:
@couch.available_instance?(:default)
34 35 36 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 34 def available_instance?(ref_or_name) ref_or_name.is_a?(Symbol) ? available_instances.keys.include?(ref_or_name) : available_instances.values.map{|db| db.name}.include?(ref_or_name) end |
#create_db(name) ⇒ Object
Create a instance
89 90 91 92 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 89 def create_db(name) IbmCloudRest.put "#{@uri}/#{name}" instance(name) end |
#default_instance ⇒ Object
42 43 44 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 42 def default_instance available_instances[:default] end |
#default_instance=(name, create_unless_exists = true) ⇒ Object
38 39 40 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 38 def default_instance=(name, create_unless_exists = true) define_available_instance(:default, name, create_unless_exists = true) end |
#define_available_instance(reference, db_name, create_unless_exists = true) ⇒ Object
Adds a new available instance and create it unless it already exists
Example:
@couch.define_available_instance(:default, “tech-blog”)
24 25 26 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 24 def define_available_instance(reference, db_name, create_unless_exists = true) available_instances[reference.to_sym] = create_unless_exists ? instance!(db_name) : instance(db_name) end |
#images ⇒ Object
Lists all images on the server
68 69 70 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 68 def images IbmCloudRest.get "#{@uri}/images" end |
#info ⇒ Object
GET the welcome message
84 85 86 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 84 def info IbmCloudRest.get "#{@uri}/" end |
#instance(name) ⇒ Object
Returns a IbmCloudRest::instance for the given name
73 74 75 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 73 def instance(name) IbmCloudRest::instance.new(self, name) end |
#instance!(name) ⇒ Object
Creates the instance if it doesn’t exist
78 79 80 81 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 78 def instance!(name) create_db(name) rescue nil instance(name) end |
#instances ⇒ Object
Lists all instances on the server
63 64 65 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 63 def instances IbmCloudRest.get "#{@uri}/instances" end |
#keys ⇒ Object
Lists all keys on the server
58 59 60 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 58 def keys IbmCloudRest.get "#{@uri}/keys" end |
#next_uuid(count = @uuid_batch_count) ⇒ Object
Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
100 101 102 103 104 105 106 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 100 def next_uuid(count = @uuid_batch_count) @uuids ||= [] if @uuids.empty? @uuids = IbmCloudRest.get("#{@uri}/_uuids?count=#{count}")["uuids"] end @uuids.pop end |
#restart! ⇒ Object
Restart the CouchDB instance
95 96 97 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 95 def restart! IbmCloudRest.post "#{@uri}/_restart" end |
#storages ⇒ Object
Lists all storages on the server
47 48 49 |
# File 'lib/ibm_cloud_rest/core/server.rb', line 47 def storages IbmCloudRest.get "#{@uri}/storage" end |