umbreo_cli 1.0.141

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.env +2 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.lock +106 -0
  5. data/README.md +1625 -0
  6. data/Rakefile +44 -0
  7. data/bin/manifests/init.pp +20 -0
  8. data/bin/umbreo +1684 -0
  9. data/bin/umbreo.json +34 -0
  10. data/lib/umbreo.rb +49 -0
  11. data/lib/umbreo/helpers/alert_message.rb +58 -0
  12. data/lib/umbreo/helpers/error_exception.rb +15 -0
  13. data/lib/umbreo/helpers/file_generator.rb +13 -0
  14. data/lib/umbreo/helpers/json_base_convert.rb +30 -0
  15. data/lib/umbreo/helpers/table.rb +45 -0
  16. data/lib/umbreo/models/amazon_web_service_provider.rb +260 -0
  17. data/lib/umbreo/models/authentication.rb +99 -0
  18. data/lib/umbreo/models/blueprint.rb +241 -0
  19. data/lib/umbreo/models/cloud_provider.rb +143 -0
  20. data/lib/umbreo/models/configuration.rb +98 -0
  21. data/lib/umbreo/models/digital_ocean_provider.rb +204 -0
  22. data/lib/umbreo/models/google_compute_engine_provider.rb +232 -0
  23. data/lib/umbreo/models/instance.rb +170 -0
  24. data/lib/umbreo/models/module.rb +61 -0
  25. data/lib/umbreo/models/openstack_provider.rb +260 -0
  26. data/lib/umbreo/models/profile.rb +61 -0
  27. data/lib/umbreo/models/provider.rb +164 -0
  28. data/lib/umbreo/models/service.rb +244 -0
  29. data/lib/umbreo/models/service_provider.rb +185 -0
  30. data/lib/umbreo/models/stack.rb +181 -0
  31. data/lib/umbreo/models/system.rb +43 -0
  32. data/lib/umbreo/models/umbreo_stack_template.rb +163 -0
  33. data/lib/umbreo/models/xenserver_provider.rb +200 -0
  34. data/lib/umbreo/version.rb +3 -0
  35. data/manifests/init.pp +20 -0
  36. data/manifests1/init.pp +9 -0
  37. data/umbreo.gemspec +28 -0
  38. metadata +241 -0
@@ -0,0 +1,61 @@
1
+ module Umbreo
2
+ module Models
3
+ class Profile
4
+
5
+ def initialize(credentials = {})
6
+ if credentials.present?
7
+ @email = credentials[:email]
8
+ @api_key = credentials[:api_key]
9
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
10
+ end
11
+ end
12
+
13
+ def retrieve_data(filter = {})
14
+ Helpers::ErrorException.rescue do
15
+ data = Typhoeus.get(
16
+ "#{@endpoint}/api/v1/profiles",
17
+ body: {
18
+ authenticate_token: @api_key,
19
+ email: @email,
20
+ filter: filter
21
+ }
22
+ )
23
+
24
+ @data = JSON.parse data.response_body
25
+ end
26
+ end
27
+
28
+ def all(filter = {})
29
+ @errors << "Search keyword is required." if filter[:keyword].blank? && filter[:search]
30
+
31
+ if valid?
32
+ retrieve_data(filter)
33
+
34
+ if @data['umbreo_profiles'].present?
35
+ page = " | Page: #{filter[:page]} of #{@data['total_page']} pages"
36
+ Helpers::Table.show_table(@data['umbreo_profiles'], "List Profile#{ page if @data['total_page'] > 1 }", ['ID', 'Name', 'Description'])
37
+ else
38
+ Helpers::AlertMessage.show_error_message(@data["message"])
39
+ end
40
+ else
41
+ Helpers::AlertMessage.show_error_message(error)
42
+ end
43
+ end
44
+
45
+ #
46
+ # Check no error from validation
47
+ #
48
+ def valid?
49
+ @errors.blank?
50
+ end
51
+
52
+ #
53
+ # Get first error
54
+ #
55
+ def error
56
+ @errors.first
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,164 @@
1
+ module Umbreo
2
+ module Models
3
+ class Provider
4
+
5
+ #
6
+ # init params which required for create cloud provider
7
+ #
8
+ def initialize(credentials = {}, name_or_id = nil)
9
+ if credentials.present?
10
+ @email = credentials[:email]
11
+ @api_key = credentials[:api_key]
12
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
13
+ end
14
+
15
+ @errors = []
16
+ @name_or_id = name_or_id
17
+ end
18
+
19
+ #
20
+ # get list of my providers
21
+ #
22
+ def retrieve_data(filter = {})
23
+ Helpers::ErrorException.rescue do
24
+ data = Typhoeus.get(
25
+ "#{@endpoint}/api/v1/providers",
26
+ body: {
27
+ authenticate_token: @api_key,
28
+ email: @email,
29
+ filter: filter
30
+ }
31
+ )
32
+
33
+ @data = JSON.parse data.response_body
34
+ end
35
+ end
36
+
37
+ #
38
+ # callback for retrieve data
39
+ #
40
+ def all(filter = {})
41
+ @errors << "Please choose correct option cloud provider |all, aws, gcompute, docean, openstack, XenServer|" if CloudProvider::CLOUDS.exclude?(filter[:umbreo_cloud_provider_id].try(:to_sym)) && filter[:umbreo_cloud_provider_id].present?
42
+
43
+ if valid?
44
+ retrieve_data(filter)
45
+
46
+ if @data['user_providers'].present?
47
+ page = " | Page: #{filter[:page]} of #{@data['total_page']} pages"
48
+ Helpers::Table.show_table(@data['user_providers'], "List My Provider#{ page if @data['total_page'] > 1 }", ['ID', 'Name', 'Cloud Provider', 'Description'])
49
+ else
50
+ Helpers::AlertMessage.show_error_message(@data["message"])
51
+ end
52
+ else
53
+ Helpers::AlertMessage.show_error_message(error)
54
+ end
55
+
56
+ end
57
+
58
+ #
59
+ # get instance data
60
+ #
61
+ def show
62
+ @errors << "ID or Name is required." if @name_or_id.blank?
63
+
64
+ if valid?
65
+ Helpers::ErrorException.rescue do
66
+ data = Typhoeus.get(
67
+ "#{@endpoint}/api/v1/providers/show",
68
+ body: {
69
+ authenticate_token: @api_key,
70
+ email: @email,
71
+ name_or_id: @name_or_id
72
+ }
73
+ )
74
+
75
+ @data = JSON.parse data.response_body
76
+
77
+ if @data['success']
78
+ Helpers::AlertMessage.show_content_information_message(@data['id']) { "ID: #message" }
79
+ Helpers::AlertMessage.show_content_information_message(@data['name']) { "Name: #message" }
80
+ Helpers::AlertMessage.show_content_information_message(@data['description']) { "Description: #message" }
81
+ Helpers::AlertMessage.show_content_information_message(@data['umbreo_cloud_provider']) { "Cloud provider: #message" }
82
+ Helpers::AlertMessage.show_content_information_message(Date.parse(@data['created_at']).to_s) { "Created At: #message" }
83
+ else
84
+ Helpers::AlertMessage.show_error_message(@data['message'])
85
+ end
86
+ end
87
+ else
88
+ Helpers::AlertMessage.show_error_message(error)
89
+ end
90
+ end
91
+
92
+ #
93
+ # validation params
94
+ #
95
+ def check_validation!
96
+ @errors << 'Invalid cloud provider' if CloudProvider::CLOUDS.exclude?(@cloud_provider.to_sym)
97
+ @errors << 'Invalid cloud provider credential' if @provider_credential.blank?
98
+ end
99
+
100
+ #
101
+ # check no errors
102
+ #
103
+ def valid?
104
+ @errors.blank?
105
+ end
106
+
107
+ #
108
+ # call errors
109
+ #
110
+ def error
111
+ @errors.first
112
+ end
113
+
114
+ #
115
+ # create provider
116
+ #
117
+ def create(cloud, name, description = nil, file_path)
118
+ @name = name
119
+ @desc = description
120
+ @cloud_provider = cloud
121
+
122
+ @errors << "File directory is required." if file_path.blank?
123
+ @errors << "Name is required." if name.blank?
124
+ begin
125
+ file = File.open(file_path, "r")
126
+ content = file.read
127
+ @json = JSON.parse(content)
128
+ @encode = Helpers::JsonBaseConvert.encode(@json)
129
+ rescue
130
+ @errors << "Error on file. Please check again."
131
+ end
132
+ @errors << "Content of file is required." if content.blank?
133
+
134
+ if valid?
135
+ url = "#{@endpoint}/api/v1/providers"
136
+
137
+ Helpers::ErrorException.rescue do
138
+ data = Typhoeus.post(
139
+ url,
140
+ body: {
141
+ authenticate_token: @api_key,
142
+ email: @email,
143
+ provider: @cloud_provider,
144
+ name_provider: @name,
145
+ description_provider: @desc,
146
+ provider_credential: @encode
147
+ }
148
+ )
149
+ data = JSON.parse data.response_body
150
+
151
+ if data['success']
152
+ Helpers::AlertMessage.show_success_message(data['message'])
153
+ else
154
+ Helpers::AlertMessage.show_error_message(data['message'])
155
+ end
156
+ end
157
+ else
158
+ Helpers::AlertMessage.show_error_message(error)
159
+ end
160
+ end
161
+
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,244 @@
1
+ module Umbreo
2
+ module Models
3
+ class Service
4
+
5
+ def initialize(credentials = {}, name_or_id = nil)
6
+ if credentials.present?
7
+ @email = credentials[:email]
8
+ @api_key = credentials[:api_key]
9
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
10
+ end
11
+
12
+ @name_or_id = name_or_id
13
+ @errors = []
14
+ end
15
+
16
+ #
17
+ # retrieve data instance
18
+ #
19
+ def retrieve_data(filter = {})
20
+ Helpers::ErrorException.rescue do
21
+ data = Typhoeus.get(
22
+ "#{@endpoint}/api/v1/services",
23
+ body: {
24
+ authenticate_token: @api_key,
25
+ email: @email,
26
+ filter: filter
27
+ }
28
+ )
29
+
30
+ @data = JSON.parse data.response_body
31
+ end
32
+ end
33
+
34
+ #
35
+ # callback for retrieve data
36
+ #
37
+ def all(filter = {})
38
+ @errors << "Please choose correct state |all, active, unactive|" if ['active', 'unactive'].exclude?(filter[:state]) && filter[:state].present?
39
+ @errors << "Search keyword is required." if filter[:keyword].blank? && filter[:search]
40
+
41
+ if valid?
42
+ retrieve_data(filter)
43
+
44
+ if @data['user_services'].present?
45
+ page = " | Page: #{filter[:page]} of #{@data['total_page']} pages"
46
+ Helpers::Table.show_table(@data['user_services'], "List Service#{ page if @data['total_page'] > 1 }", ['ID', 'Name', 'Service Provider', 'Link Type', 'Active'])
47
+ else
48
+ Helpers::AlertMessage.show_error_message(@data["message"])
49
+ end
50
+ else
51
+ Helpers::AlertMessage.show_error_message(error)
52
+ end
53
+ end
54
+
55
+ #
56
+ # get instance data
57
+ #
58
+ def show
59
+ @errors << "ID or Name is required." if @name_or_id.blank?
60
+
61
+ if valid?
62
+ Helpers::ErrorException.rescue do
63
+ data = Typhoeus.get(
64
+ "#{@endpoint}/api/v1/services/show",
65
+ body: {
66
+ authenticate_token: @api_key,
67
+ email: @email,
68
+ id: @name_or_id
69
+ }
70
+ )
71
+
72
+ @data = JSON.parse data.response_body
73
+
74
+ if @data['success']
75
+ Helpers::AlertMessage.show_content_information_message(@data['id']) { "ID: #message" }
76
+ Helpers::AlertMessage.show_content_information_message(@data['name']) { "Name: #message" }
77
+ Helpers::AlertMessage.show_content_information_message(@data['umbreo_service']) { "Service Provider: #message" }
78
+ Helpers::AlertMessage.show_content_information_message(@data['link_type']) { "Link type: #message" }
79
+ Helpers::AlertMessage.show_content_information_message(@data['is_active']) { "Active: #message" }
80
+ Helpers::AlertMessage.show_content_information_message(@data['description']) { "Description: #message" }
81
+ else
82
+ Helpers::AlertMessage.show_error_message(@data['message'])
83
+ end
84
+ end
85
+ else
86
+ Helpers::AlertMessage.show_error_message(error)
87
+ end
88
+ end
89
+
90
+ #
91
+ # export umbreo stack template params
92
+ #
93
+ def export
94
+ Helpers::ErrorException.rescue do
95
+ response = Typhoeus.get(
96
+ "#{@endpoint}/api/v1/services/export",
97
+ body: {
98
+ authenticate_token: @api_key,
99
+ email: @email,
100
+ id: @name_or_id
101
+ }
102
+ )
103
+
104
+ @response = JSON.parse response.response_body rescue nil
105
+
106
+ if @response["user_service"].present?
107
+ name_file = @response["user_service"]["name"].downcase.titleize.delete(" ").underscore
108
+ Helpers::FileGenerator.create(name_file, @response["user_service"])
109
+
110
+ Helpers::AlertMessage.show_success_message("Success export service. your service is saved on json file with name #{name_file}.json")
111
+ else
112
+ Helpers::AlertMessage.show_error_message(@response["message"])
113
+ end
114
+ end
115
+ end
116
+
117
+ #
118
+ # check valid json params
119
+ #
120
+ def validate(file_path)
121
+ @errors << "File directory is required." if file_path.blank?
122
+
123
+ begin
124
+ file = File.open(file_path, "r")
125
+ content = file.read
126
+ json = JSON.parse(content)
127
+ encode = Helpers::JsonBaseConvert.encode(json)
128
+ rescue
129
+ @errors << "Error on file. Please check again."
130
+ end
131
+ @errors << "Content of file is required." if content.blank?
132
+
133
+ if valid?
134
+ Helpers::ErrorException.rescue do
135
+
136
+ response = Typhoeus.get(
137
+ "#{@endpoint}/api/v1/services/validate",
138
+ body: {
139
+ authenticate_token: @api_key,
140
+ email: @email,
141
+ content: encode
142
+ }
143
+ )
144
+
145
+ @response = JSON.parse response.response_body
146
+
147
+ if @response["success"]
148
+ Helpers::AlertMessage.show_success_message(@response["message"])
149
+ else
150
+ Helpers::AlertMessage.show_error_message(@response["message"])
151
+ end
152
+ end
153
+ else
154
+ Helpers::AlertMessage.show_error_message(error)
155
+ end
156
+ end
157
+
158
+ #
159
+ # create user provider
160
+ #
161
+ def create(parameters)
162
+
163
+ @errors << "Name is required" if parameters[:name].blank?
164
+
165
+ file_path = parameters[:params]
166
+ if file_path.present?
167
+ begin
168
+ file = File.open(file_path, "r")
169
+ content = file.read
170
+ json = JSON.parse(content)
171
+ parameters[:params] = Helpers::JsonBaseConvert.encode(json)
172
+ rescue
173
+ @errors << "Error on #{ file_path } file. Please check again."
174
+ end
175
+ end
176
+
177
+ if parameters[:user_node_attributes].present?
178
+ main_param = parameters[:user_node_attributes]
179
+
180
+ @errors << "#{main_param[:name]} ##{index} Blueprint Json file is required" if main_param[:name].blank?
181
+ @errors << "#{main_param[:name]} ##{index} Deployment type is required" if main_param[:type].blank?
182
+ @errors << "#{main_param[:name]} ##{index} Compute Provider Json file is required" if main_param[:provider].blank? && main_param[:type] == "provider"
183
+
184
+ main_param[:file_parameter] = {}
185
+
186
+ [:blueprint, :service_logging, :service_monitoring, :service_backup, :provider].each do |file_name|
187
+ file_path = main_param[file_name] rescue nil
188
+
189
+ if file_path.present?
190
+ begin
191
+ file = File.open(file_path, "r")
192
+ content = file.read
193
+ json = JSON.parse(content)
194
+ main_param[file_name] = Helpers::JsonBaseConvert.encode(json)
195
+ rescue
196
+ @errors << "Error on #{ file_path } file. Please check again."
197
+ end
198
+ end
199
+ end
200
+ end
201
+
202
+ if valid?
203
+ Helpers::ErrorException.rescue do
204
+
205
+ response = Typhoeus.post(
206
+ "#{@endpoint}/api/v1/services",
207
+ body: {
208
+ authenticate_token: @api_key,
209
+ email: @email,
210
+ user_service: parameters
211
+ }
212
+ )
213
+
214
+ @response = JSON.parse response.response_body
215
+
216
+ if @response["success"]
217
+ Helpers::AlertMessage.show_success_message("Service successfully created.")
218
+ else
219
+ Helpers::AlertMessage.show_error_message(@response["message"])
220
+ end
221
+ end
222
+ else
223
+ Helpers::AlertMessage.show_error_message(error)
224
+ end
225
+
226
+ end
227
+
228
+ #
229
+ # Check no error from validation
230
+ #
231
+ def valid?
232
+ @errors.blank?
233
+ end
234
+
235
+ #
236
+ # Get first error
237
+ #
238
+ def error
239
+ @errors.first
240
+ end
241
+
242
+ end
243
+ end
244
+ end