Class: Brightbox::DatabaseServer
- Inherits:
-
Api
- Object
- Api
- Brightbox::DatabaseServer
show all
- Defined in:
- lib/brightbox-cli/database_server.rb
Instance Attribute Summary
Attributes inherited from Api
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Api
cache_all!, cached_get, conn, #created_on, #exists?, find, find_all_or_warn, find_by_handle, find_or_call, #fog_model, #initialize, klass_name, #method_missing, #respond_to_missing?, #to_s
Constructor Details
This class inherits a constructor from Brightbox::Api
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Brightbox::Api
Class Method Details
.all ⇒ Object
13
14
15
|
# File 'lib/brightbox-cli/database_server.rb', line 13
def self.all
conn.database_servers.all
end
|
.clean_arguments(args) ⇒ Object
Converts GLI’s arguments to fog based parameters
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/brightbox-cli/database_server.rb', line 122
def self.clean_arguments(args)
params = NilableHash.new
params[:name] = args[:n] if args[:n]
params[:description] = args[:d] if args[:d]
if args["allow-access"]
params[:allow_access] = args["allow-access"].split(",")
end
if args["maintenance-weekday"]
params[:maintenance_weekday] = weekday_index(args["maintenance-weekday"])
end
params[:maintenance_hour] = args["maintenance-hour"] if args["maintenance-hour"]
params[:snapshots_schedule] = args["snapshots-schedule"] if args["snapshots-schedule"]
if args["remove-snapshots-schedule"]
params[:snapshots_schedule] = nil
end
params[:database_engine] = args[:engine] if args[:engine]
params[:database_version] = args["engine-version"] if args["engine-version"]
params[:snapshot_id] = args[:snapshot] if args[:snapshot]
params[:flavor_id] = args[:type] if args[:type]
params[:zone_id] = args[:zone] if args[:zone]
params.nilify_blanks
params
end
|
.create(options) ⇒ Object
9
10
11
|
# File 'lib/brightbox-cli/database_server.rb', line 9
def self.create(options)
new(conn.database_servers.create(options))
end
|
.default_field_order ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/brightbox-cli/database_server.rb', line 35
def self.default_field_order
i[
id
status
type
db_engine
zone
created_on
cloud_ip_ids
name
]
end
|
.detailed_fields ⇒ Object
These are all the fields show in the longer table form
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/brightbox-cli/database_server.rb', line 49
def self.detailed_fields
i[
id name description status locked
type engine version
zone
created_on
admin_username admin_password
maintenance_window
snapshots_schedule
snapshots_schedule_next_at
allow_access
cloud_ip_ids cloud_ips
]
end
|
.get(id) ⇒ Object
17
18
19
|
# File 'lib/brightbox-cli/database_server.rb', line 17
def self.get(id)
conn.database_servers.get(id)
end
|
.require_account? ⇒ Boolean
5
6
7
|
# File 'lib/brightbox-cli/database_server.rb', line 5
def self.require_account?
true
end
|
.weekday_index(user_input) ⇒ Object
155
156
157
158
159
|
# File 'lib/brightbox-cli/database_server.rb', line 155
def self.weekday_index(user_input)
DateTime.parse(user_input).wday.to_s
rescue ArgumentError
user_input.to_s
end
|
Instance Method Details
#cloud_ip_addresses ⇒ Object
Lists the CIP IP addresses
117
118
119
|
# File 'lib/brightbox-cli/database_server.rb', line 117
def cloud_ip_addresses
cloud_ips.map { |cip| cip["public_ip"] }
end
|
#cloud_ip_ids ⇒ Object
Lists the CIP identifiers (cip-12345)
112
113
114
|
# File 'lib/brightbox-cli/database_server.rb', line 112
def cloud_ip_ids
cloud_ips.map { |cip| cip["id"] }
end
|
#cloud_ips ⇒ Object
107
108
109
|
# File 'lib/brightbox-cli/database_server.rb', line 107
def cloud_ips
super.nil? ? [] : super
end
|
#destroy ⇒ Object
31
32
33
|
# File 'lib/brightbox-cli/database_server.rb', line 31
def destroy
fog_model.destroy
end
|
#engine_version ⇒ Object
95
96
97
|
# File 'lib/brightbox-cli/database_server.rb', line 95
def engine_version
[database_engine, database_version].join("-")
end
|
#maintenance_window ⇒ Object
A more humanised version of the maintenance window
100
101
102
103
104
105
|
# File 'lib/brightbox-cli/database_server.rb', line 100
def maintenance_window
return nil if maintenance_weekday.nil?
weekday = Date::DAYNAMES[maintenance_weekday]
format("%s %02d:00 UTC", weekday, maintenance_hour)
end
|
#reset_password ⇒ Object
27
28
29
|
# File 'lib/brightbox-cli/database_server.rb', line 27
def reset_password
fog_model.reset_password
end
|
#to_row ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/brightbox-cli/database_server.rb', line 76
def to_row
a = fog_model.attributes
a[:status] = fog_model.state
a[:locked] = locked?
a[:type] = type_identifier
a[:db_engine] = engine_version
a[:engine] = database_engine
a[:version] = database_version
a[:maintenance_weekday] = maintenance_weekday
a[:maintenance_hour] = maintenance_hour
a[:maintenance_window] = maintenance_window
a[:zone] = zone_handle
a[:created_on] = created_on
a[:allow_access] = allow_access
a[:cloud_ip_ids] = cloud_ip_ids
a[:cloud_ips] = cloud_ip_addresses
a
end
|
#type_identifier ⇒ Object
64
65
66
67
68
|
# File 'lib/brightbox-cli/database_server.rb', line 64
def type_identifier
return unless fog_model.attributes.key?("database_server_type")
fog_model.attributes["database_server_type"]["id"]
end
|
#update(options) ⇒ Object
21
22
23
24
25
|
# File 'lib/brightbox-cli/database_server.rb', line 21
def update(options)
self.class.conn.update_database_server(id, options)
reload
self
end
|
#zone_handle ⇒ Object
70
71
72
73
74
|
# File 'lib/brightbox-cli/database_server.rb', line 70
def zone_handle
return unless fog_model.attributes.key?("zone")
fog_model.attributes["zone"]["handle"]
end
|