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
#attributes, cache_all!, cached_get, conn, #created_on, #exists?, find, find_all_or_warn, find_by_handle, find_or_call, #fog_attributes, #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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/brightbox-cli/database_server.rb', line 130
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
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/brightbox-cli/database_server.rb', line 43
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/brightbox-cli/database_server.rb', line 57
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
163
164
165
166
167
|
# File 'lib/brightbox-cli/database_server.rb', line 163
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
125
126
127
|
# File 'lib/brightbox-cli/database_server.rb', line 125
def cloud_ip_addresses
cloud_ips.map { |cip| cip["public_ip"] }
end
|
#cloud_ip_ids ⇒ Object
Lists the CIP identifiers (cip-12345)
120
121
122
|
# File 'lib/brightbox-cli/database_server.rb', line 120
def cloud_ip_ids
cloud_ips.map { |cip| cip["id"] }
end
|
#cloud_ips ⇒ Object
115
116
117
|
# File 'lib/brightbox-cli/database_server.rb', line 115
def cloud_ips
super.nil? ? [] : super
end
|
#destroy ⇒ Object
39
40
41
|
# File 'lib/brightbox-cli/database_server.rb', line 39
def destroy
fog_model.destroy
end
|
#engine_version ⇒ Object
103
104
105
|
# File 'lib/brightbox-cli/database_server.rb', line 103
def engine_version
[database_engine, database_version].join("-")
end
|
#maintenance_window ⇒ Object
A more humanised version of the maintenance window
108
109
110
111
112
113
|
# File 'lib/brightbox-cli/database_server.rb', line 108
def maintenance_window
return nil if maintenance_weekday.nil?
weekday = Date::DAYNAMES[maintenance_weekday]
format("%s %02d:00 UTC", weekday, maintenance_hour)
end
|
#reset ⇒ Object
27
28
29
|
# File 'lib/brightbox-cli/database_server.rb', line 27
def reset
fog_model.reset
end
|
#reset_password ⇒ Object
31
32
33
|
# File 'lib/brightbox-cli/database_server.rb', line 31
def reset_password
fog_model.reset_password
end
|
#resize(options) ⇒ Object
35
36
37
|
# File 'lib/brightbox-cli/database_server.rb', line 35
def resize(options)
fog_model.resize(options[:new_type])
end
|
#to_row ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/brightbox-cli/database_server.rb', line 84
def to_row
attributes.merge(
status: fog_model.state,
locked: locked?,
type: type_identifier,
db_engine: engine_version,
engine: database_engine,
version: database_version,
maintenance_weekday: maintenance_weekday,
maintenance_hour: maintenance_hour,
maintenance_window: maintenance_window,
zone: zone_handle,
created_on: created_on,
allow_access: allow_access,
cloud_ip_ids: cloud_ip_ids,
cloud_ips: cloud_ip_addresses
)
end
|
#type_identifier ⇒ Object
72
73
74
75
76
|
# File 'lib/brightbox-cli/database_server.rb', line 72
def type_identifier
return unless fog_attributes.key?("database_server_type")
fog_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
78
79
80
81
82
|
# File 'lib/brightbox-cli/database_server.rb', line 78
def zone_handle
return unless fog_attributes.key?("zone")
fog_attributes["zone"]["handle"]
end
|