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
data/bin/umbreo.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "apache",
3
+ "parameters": [
4
+ {
5
+ "name": "version",
6
+ "displayed": "Version",
7
+ "description": "",
8
+ "default": "latest",
9
+ "type": "string",
10
+ "scope": ""
11
+ },
12
+ {
13
+ "name": "service_ensure",
14
+ "displayed": "Service Ensure",
15
+ "description": "",
16
+ "default": "running",
17
+ "type": "string",
18
+ "scope": ""
19
+ },
20
+ {
21
+ "name": "service_enable",
22
+ "displayed": "Service Enable",
23
+ "description": "",
24
+ "default": true,
25
+ "type": "boolean",
26
+ "scope": ""
27
+ }
28
+ ],
29
+ "informations": {
30
+ "display_name": "Apache Web Server",
31
+ "data": {
32
+ }
33
+ }
34
+ }
data/lib/umbreo.rb ADDED
@@ -0,0 +1,49 @@
1
+ # Gem Dependencies
2
+ require 'typhoeus'
3
+ require 'byebug'
4
+ require 'json'
5
+ require 'base64'
6
+ require 'rainbow'
7
+ require 'parseconfig'
8
+ require 'terminal-table'
9
+
10
+ # Active Support
11
+ require 'active_support/all'
12
+
13
+ # Library Code
14
+ require 'umbreo/version'
15
+
16
+ require 'umbreo/helpers/table'
17
+ require 'umbreo/helpers/alert_message'
18
+ require 'umbreo/helpers/error_exception'
19
+ require 'umbreo/helpers/file_generator'
20
+ require 'umbreo/helpers/json_base_convert'
21
+
22
+ require 'umbreo/models/authentication'
23
+ require 'umbreo/models/configuration'
24
+ require 'umbreo/models/instance'
25
+ require 'umbreo/models/module'
26
+ require 'umbreo/models/profile'
27
+ require 'umbreo/models/cloud_provider'
28
+ require 'umbreo/models/provider'
29
+ require 'umbreo/models/digital_ocean_provider'
30
+ require 'umbreo/models/amazon_web_service_provider'
31
+ require 'umbreo/models/google_compute_engine_provider'
32
+ require 'umbreo/models/openstack_provider'
33
+ require 'umbreo/models/xenserver_provider'
34
+ require 'umbreo/models/blueprint'
35
+ require 'umbreo/models/system'
36
+ require 'umbreo/models/stack'
37
+ require 'umbreo/models/umbreo_stack_template'
38
+ require 'umbreo/models/service_provider'
39
+ require 'umbreo/models/service'
40
+
41
+ # Add requires for other files you add to your project here, so
42
+ # you just need to require this one file in your bin file
43
+
44
+ module Umbreo
45
+
46
+ SERVER_END_POINT = "https://beta.umbreo.com"
47
+ FILE_CONFIG = `eval echo ~$USER`.delete("\n") + "/.umbreoconfig"
48
+
49
+ end
@@ -0,0 +1,58 @@
1
+ module Umbreo
2
+ module Helpers
3
+ class AlertMessage
4
+
5
+ def self.show_success_message(message, inline = false)
6
+ if inline
7
+ Rainbow(message).green
8
+ else
9
+ puts Rainbow(message).green
10
+ end
11
+ end
12
+
13
+ def self.show_error_message(message, inline = false)
14
+ if inline
15
+ Rainbow(message).red.bright
16
+ else
17
+ puts Rainbow(message).red.bright
18
+ end
19
+ end
20
+
21
+ def self.show_information_message(message, inline = false)
22
+ if inline
23
+ Rainbow(message).cyan
24
+ else
25
+ puts Rainbow(message).cyan
26
+ end
27
+ end
28
+
29
+ def self.show_content_success_message(message, inline = false)
30
+ if inline
31
+ yield.gsub("#message", Rainbow(message).green)
32
+ else
33
+ puts yield.gsub("#message", Rainbow(message).green)
34
+ end
35
+ end
36
+
37
+ def self.show_content_error_message(message, inline = false)
38
+ if inline
39
+ yield.gsub("#message", Rainbow(message).red.bright)
40
+ else
41
+ puts yield.gsub("#message", Rainbow(message).red.bright)
42
+ end
43
+ end
44
+
45
+ def self.show_content_information_message(message, inline = false)
46
+ if inline
47
+ yield.gsub("#message", Rainbow(message).cyan)
48
+ else
49
+ puts yield.gsub("#message", Rainbow(message).cyan)
50
+ end
51
+ end
52
+
53
+ def self.show_error_exception(e)
54
+ puts Rainbow("An error of type #{e.class} happened.").red.bright
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ module Umbreo
2
+ module Helpers
3
+ class ErrorException
4
+
5
+ def self.rescue
6
+ begin
7
+ yield
8
+ rescue Exception => e
9
+ Helpers::AlertMessage.show_error_exception(e)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Umbreo
2
+ module Helpers
3
+ class FileGenerator
4
+
5
+ def self.create(name, data)
6
+ File.open("#{name}.json", "w+") do |f|
7
+ f.write(JSON.generate(data))
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Umbreo
2
+ module Helpers
3
+
4
+ class JsonBaseConvert
5
+
6
+ def self.encode(source)
7
+ if source.is_a? Hash
8
+ Base64.strict_encode64(source.to_json)
9
+ end
10
+ end
11
+
12
+ def self.decode(source)
13
+ if source.is_a? String
14
+ JSON.parse Base64.strict_decode64(source)
15
+ end
16
+ end
17
+
18
+ # used by umbreo_service_client/master.json
19
+ def self.encode_service_param(source)
20
+ Base64.strict_decode64(source)
21
+ end
22
+
23
+ def self.decode_service_param(source)
24
+ Base64.strict_decode64(source)
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ module Umbreo
2
+ module Helpers
3
+ class Table
4
+
5
+ def self.table_callback_retrieve_data(data, title)
6
+ if data.present?
7
+ rows = []
8
+ data.each do |data|
9
+ data = data['name'].present? ? data['name'] : data
10
+ rows << [ data ]
11
+ end
12
+ table = Terminal::Table.new :title => title, :headings => ['Name'], :rows => rows
13
+ puts table
14
+ end
15
+ end
16
+
17
+ def self.show_table(data, title, headings = [])
18
+ if data.present?
19
+ rows = []
20
+ data.each do |data|
21
+
22
+ sub_arr = data.is_a?(Array) ? data : data.to_a
23
+ cell = []
24
+
25
+ if data.is_a? Array
26
+ sub_arr.each do |arr|
27
+ cell << arr
28
+ end
29
+ else
30
+ sub_arr.each do |arr|
31
+ cell << arr[1]
32
+ end
33
+ end
34
+
35
+ rows << cell
36
+ end
37
+
38
+ table = Terminal::Table.new :title => title, :headings => headings, :rows => rows
39
+ puts table
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,260 @@
1
+ module Umbreo
2
+ module Models
3
+ class AmazonWebServiceProvider
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 image of amazon web service
21
+ #
22
+ def aws_image_list
23
+ @errors << "ID or Name provider is required." if @name_or_id.blank?
24
+
25
+ if valid?
26
+ Helpers::ErrorException.rescue do
27
+ data = Typhoeus.get(
28
+ "#{@endpoint}/api/v1/amazon_web_services/image_list",
29
+ body: {
30
+ authenticate_token: @api_key,
31
+ email: @email,
32
+ id: @name_or_id
33
+ }
34
+ )
35
+
36
+ data = JSON.parse data.response_body
37
+
38
+ if data['success']
39
+ Helpers::Table.show_table(data['images'], "List AWS Image", ['Image Name', 'Image ID'])
40
+ else
41
+ Helpers::AlertMessage.show_error_message(data['message'])
42
+ end
43
+ end
44
+ else
45
+ Helpers::AlertMessage.show_error_message(error)
46
+ end
47
+ end
48
+
49
+ #
50
+ # get list size of amazon web service
51
+ #
52
+ def aws_size_list
53
+ @errors << "ID or Name provider is required." if @name_or_id.blank?
54
+
55
+ if valid?
56
+ Helpers::ErrorException.rescue do
57
+ data = Typhoeus.get(
58
+ "#{@endpoint}/api/v1/amazon_web_services/size_list",
59
+ body: {
60
+ authenticate_token: @api_key,
61
+ email: @email,
62
+ id: @name_or_id
63
+ }
64
+ )
65
+
66
+ data = JSON.parse data.response_body
67
+
68
+ if data['success']
69
+ Helpers::Table.show_table(data['sizes'], "List AWS Size", ['Size Name', 'Size ID'])
70
+ else
71
+ Helpers::AlertMessage.show_error_message(data['message'])
72
+ end
73
+ end
74
+ else
75
+ Helpers::AlertMessage.show_error_message(error)
76
+ end
77
+ end
78
+
79
+ #
80
+ # get list size of amazon web service
81
+ #
82
+ def region_list
83
+ @errors << "ID or Name provider is required." if @name_or_id.blank?
84
+
85
+ if valid?
86
+ Helpers::ErrorException.rescue do
87
+ data = Typhoeus.get(
88
+ "#{@endpoint}/api/v1/amazon_web_services/region_list",
89
+ body: {
90
+ authenticate_token: @api_key,
91
+ email: @email,
92
+ id: @name_or_id
93
+ }
94
+ )
95
+
96
+ data = JSON.parse data.response_body
97
+
98
+ if data['success']
99
+ Helpers::Table.table_callback_retrieve_data(data['regions'], "List AWS Region")
100
+ else
101
+ Helpers::AlertMessage.show_error_message(data['message'])
102
+ end
103
+ end
104
+ else
105
+ Helpers::AlertMessage.show_error_message(error)
106
+ end
107
+ end
108
+
109
+ #
110
+ # get list size of amazon web service
111
+ #
112
+ def keypairs_list
113
+ @errors << "ID or Name provider is required." if @name_or_id.blank?
114
+
115
+ if valid?
116
+ Helpers::ErrorException.rescue do
117
+ data = Typhoeus.get(
118
+ "#{@endpoint}/api/v1/amazon_web_services/keypair_list",
119
+ body: {
120
+ authenticate_token: @api_key,
121
+ email: @email,
122
+ id: @name_or_id
123
+ }
124
+ )
125
+
126
+ data = JSON.parse data.response_body
127
+
128
+ if data['success']
129
+ Helpers::Table.table_callback_retrieve_data(data['keypairs'], "List AWS Keypair")
130
+ else
131
+ Helpers::AlertMessage.show_error_message(data['message'])
132
+ end
133
+ end
134
+ else
135
+ Helpers::AlertMessage.show_error_message(error)
136
+ end
137
+ end
138
+
139
+ #
140
+ # get list size of amazon web service
141
+ #
142
+ def security_group_list
143
+ @errors << "ID or Name provider is required." if @name_or_id.blank?
144
+
145
+ if valid?
146
+ Helpers::ErrorException.rescue do
147
+ data = Typhoeus.get(
148
+ "#{@endpoint}/api/v1/amazon_web_services/security_group_list",
149
+ body: {
150
+ authenticate_token: @api_key,
151
+ email: @email,
152
+ id: @name_or_id
153
+ }
154
+ )
155
+
156
+ data = JSON.parse data.response_body
157
+
158
+ if data['success']
159
+ Helpers::Table.table_callback_retrieve_data(data['security_groups'], "List AWS Security Group")
160
+ else
161
+ Helpers::AlertMessage.show_error_message(data['message'])
162
+ end
163
+ end
164
+ else
165
+ Helpers::AlertMessage.show_error_message(error)
166
+ end
167
+ end
168
+
169
+ #
170
+ # get json credential file
171
+ #
172
+ def export
173
+ @errors << "ID or Slug is required." if @name_or_id.blank?
174
+
175
+ if valid?
176
+ Helpers::ErrorException.rescue do
177
+ data = Typhoeus.get(
178
+ "#{@endpoint}/api/v1/digital_ocean_services/export",
179
+ body: {
180
+ authenticate_token: @api_key,
181
+ email: @email,
182
+ id: @name_or_id
183
+ }
184
+ )
185
+
186
+ data = JSON.parse data.response_body rescue nil
187
+ user_provider = data["user_provider"]
188
+
189
+ if user_provider.present?
190
+ name_file = "amazon_web_service_provider"
191
+ Helpers::FileGenerator.create(name_file, user_provider)
192
+ Helpers::AlertMessage.show_success_message("Success export amazon web service provider. Your file is saved on json file with name #{name_file}.json")
193
+ else
194
+ Helpers::AlertMessage.show_error_message(data["message"])
195
+ end
196
+ end
197
+ else
198
+ Helpers::AlertMessage.show_error_message(error)
199
+ end
200
+ end
201
+
202
+ #
203
+ # check valid json params
204
+ #
205
+ def validate(file_path)
206
+ @errors << "File directory is required." if file_path.blank?
207
+
208
+ begin
209
+ file = File.open(file_path, "r")
210
+ content = file.read
211
+ json = JSON.parse(content)
212
+ encode = Helpers::JsonBaseConvert.encode(json)
213
+ rescue
214
+ @errors << "Error on file. Please check again."
215
+ end
216
+
217
+ @errors << "Content of file is required." if content.blank?
218
+
219
+ if valid?
220
+ Helpers::ErrorException.rescue do
221
+
222
+ response = Typhoeus.get(
223
+ "#{@endpoint}/api/v1/amazon_web_services/validate",
224
+ body: {
225
+ authenticate_token: @api_key,
226
+ email: @email,
227
+ content: encode
228
+ }
229
+ )
230
+
231
+ @response = JSON.parse response.response_body
232
+
233
+ if @response["success"]
234
+ Helpers::AlertMessage.show_success_message(@response["message"])
235
+ else
236
+ Helpers::AlertMessage.show_error_message(@response["message"])
237
+ end
238
+ end
239
+ else
240
+ Helpers::AlertMessage.show_error_message(error)
241
+ end
242
+ end
243
+
244
+ #
245
+ # check no errors
246
+ #
247
+ def valid?
248
+ @errors.blank?
249
+ end
250
+
251
+ #
252
+ # call errors
253
+ #
254
+ def error
255
+ @errors.first
256
+ end
257
+
258
+ end
259
+ end
260
+ end