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,185 @@
1
+ module Umbreo
2
+ module Models
3
+ class ServiceProvider
4
+
5
+ #
6
+ # service type
7
+ TYPE = ["logging", "monitoring", "backup"]
8
+ # resource type
9
+ RESOURCE = ["master", "client"]
10
+
11
+ def initialize(credentials = {}, name_or_id = nil)
12
+ if credentials.present?
13
+ @email = credentials[:email]
14
+ @api_key = credentials[:api_key]
15
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
16
+ end
17
+
18
+ @name_or_id = name_or_id
19
+ @errors = []
20
+ end
21
+
22
+ #
23
+ # retrieve data instance
24
+ #
25
+ def retrieve_data(filter = {})
26
+ Helpers::ErrorException.rescue do
27
+ data = Typhoeus.get(
28
+ "#{@endpoint}/api/v1/service_providers",
29
+ body: {
30
+ authenticate_token: @api_key,
31
+ email: @email,
32
+ filter: filter
33
+ }
34
+ )
35
+
36
+ @data = JSON.parse data.response_body
37
+ end
38
+ end
39
+
40
+ #
41
+ # callback for retrieve data
42
+ #
43
+ def all(filter = {})
44
+ @errors << "Please choose correct option service type |all, logging, monitoring, backup|" if TYPE.exclude?(filter[:type]) && filter[:type].present?
45
+ @errors << "Please choose correct option resource type |all, master, client|" if RESOURCE.exclude?(filter[:resource]) && filter[:resource].present?
46
+ @errors << "Search keyword is required." if filter[:keyword].blank? && filter[:search]
47
+
48
+ if valid?
49
+ retrieve_data(filter)
50
+
51
+ if @data['umbreo_services'].present?
52
+ page = " | Page: #{filter[:page]} of #{@data['total_page']} pages"
53
+ Helpers::Table.show_table(@data['umbreo_services'], "List Service Provider#{ page if @data['total_page'] > 1 }", ['ID', 'Name', 'Resource Type', 'Service Type', 'Slug'])
54
+ else
55
+ Helpers::AlertMessage.show_error_message(@data["message"])
56
+ end
57
+ else
58
+ Helpers::AlertMessage.show_error_message(error)
59
+ end
60
+ end
61
+
62
+ #
63
+ # get instance data
64
+ #
65
+ def show(need_show = true)
66
+ @errors << "ID or Name is required." if @name_or_id.blank?
67
+
68
+ if valid?
69
+ Helpers::ErrorException.rescue do
70
+ data = Typhoeus.get(
71
+ "#{@endpoint}/api/v1/service_providers/show",
72
+ body: {
73
+ authenticate_token: @api_key,
74
+ email: @email,
75
+ id: @name_or_id
76
+ }
77
+ )
78
+
79
+ @data = JSON.parse data.response_body
80
+
81
+ if @data['success']
82
+ if need_show
83
+ Helpers::AlertMessage.show_content_information_message(@data['id']) { "ID: #message" }
84
+ Helpers::AlertMessage.show_content_information_message(@data['name']) { "Name: #message" }
85
+ Helpers::AlertMessage.show_content_information_message(@data['resource_type']) { "Resource type: #message" }
86
+ Helpers::AlertMessage.show_content_information_message(@data['umbreo_service_type']) { "Service Type: #message" }
87
+ Helpers::AlertMessage.show_content_information_message(@data['slug']) { "Slug: #message" }
88
+ Helpers::AlertMessage.show_content_information_message(@data['description']) { "Description: #message" }
89
+ else
90
+ @data
91
+ end
92
+ else
93
+ Helpers::AlertMessage.show_error_message(@data['message'])
94
+ end
95
+ end
96
+ else
97
+ Helpers::AlertMessage.show_error_message(error)
98
+ end
99
+ end
100
+
101
+ #
102
+ # export umbreo stack template params
103
+ #
104
+ def export
105
+ Helpers::ErrorException.rescue do
106
+ response = Typhoeus.get(
107
+ "#{@endpoint}/api/v1/service_providers/export",
108
+ body: {
109
+ authenticate_token: @api_key,
110
+ email: @email,
111
+ id: @name_or_id
112
+ }
113
+ )
114
+
115
+ @response = JSON.parse response.response_body rescue nil
116
+
117
+ if @response["umbreo_service"].present?
118
+ name_file = @response["umbreo_service"]["name"].downcase.titleize.delete(" ").underscore
119
+ Helpers::FileGenerator.create(name_file, @response["umbreo_service"])
120
+
121
+ Helpers::AlertMessage.show_success_message("Success export umbreo service provider. your service provider is saved on json file with name #{name_file}.json")
122
+ else
123
+ Helpers::AlertMessage.show_error_message(@response["message"])
124
+ end
125
+ end
126
+ end
127
+
128
+ #
129
+ # check valid json params
130
+ #
131
+ def validate(file_path)
132
+ @errors << "File directory is required." if file_path.blank?
133
+
134
+ begin
135
+ file = File.open(file_path, "r")
136
+ content = file.read
137
+ json = JSON.parse(content)
138
+ encode = Helpers::JsonBaseConvert.encode(json)
139
+ rescue
140
+ @errors << "Error on file. Please check again."
141
+ end
142
+ @errors << "Content of file is required." if content.blank?
143
+
144
+ if valid?
145
+ Helpers::ErrorException.rescue do
146
+
147
+ response = Typhoeus.get(
148
+ "#{@endpoint}/api/v1/service_providers/validate",
149
+ body: {
150
+ authenticate_token: @api_key,
151
+ email: @email,
152
+ content: encode
153
+ }
154
+ )
155
+
156
+ @response = JSON.parse response.response_body
157
+
158
+ if @response["success"]
159
+ Helpers::AlertMessage.show_success_message(@response["message"])
160
+ else
161
+ Helpers::AlertMessage.show_error_message(@response["message"])
162
+ end
163
+ end
164
+ else
165
+ Helpers::AlertMessage.show_error_message(error)
166
+ end
167
+ end
168
+
169
+ #
170
+ # Check no error from validation
171
+ #
172
+ def valid?
173
+ @errors.blank?
174
+ end
175
+
176
+ #
177
+ # Get first error
178
+ #
179
+ def error
180
+ @errors.first
181
+ end
182
+
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,181 @@
1
+ module Umbreo
2
+ module Models
3
+ class Stack
4
+
5
+ def initialize(credentials = {}, name_or_id = nil, status = false)
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
+ @is_custom = status
14
+ @errors = []
15
+ end
16
+
17
+ def retrive_data
18
+ Helpers::ErrorException.rescue do
19
+ data = Typhoeus.get(
20
+ "#{@endpoint}/api/v1/stacks",
21
+ body: {
22
+ authenticate_token: @api_key,
23
+ email: @email
24
+ }
25
+ )
26
+
27
+ @data = JSON.parse data.response_body
28
+ end
29
+ end
30
+
31
+ def all
32
+ retrive_data
33
+
34
+ if @data['user_stacks'].present?
35
+ Helpers::Table.show_table(@data['user_stacks'], "List My Stack", ['ID', 'Name', 'Description', 'Umbreo Stack'])
36
+ else
37
+ Helpers::AlertMessage.show_error_message("Stack is not found, you have to create your own stack.")
38
+ end
39
+ end
40
+
41
+ def custom
42
+ @custom_blueprints = @data['my'] rescue []
43
+ end
44
+
45
+ def show
46
+ if @name_or_id.present?
47
+ Helpers::ErrorException.rescue do
48
+ stack = Typhoeus.get(
49
+ "#{@endpoint}/api/v1/stacks/#{@name_or_id}",
50
+ body: {
51
+ authenticate_token: @api_key,
52
+ email: @email,
53
+ name: @name_or_id,
54
+ status: @is_custom
55
+ }
56
+ )
57
+
58
+ @data = JSON.parse stack.response_body rescue nil
59
+
60
+ if @data["success"]
61
+ Helpers::AlertMessage.show_content_information_message(@data['id']) { "ID: #message" }
62
+ Helpers::AlertMessage.show_content_information_message(@data['name']) { "Name: #message" }
63
+ Helpers::AlertMessage.show_content_information_message(@data['description']) { "Description: #message" }
64
+ Helpers::AlertMessage.show_content_information_message(@data['umbreo_stack_template']) { "Stack Template: #message" }
65
+ Helpers::Table.show_table(@data['user_nodes'], "List Nodes of #{@data['name']} stack", ['ID', 'Name', 'Description'])
66
+ else
67
+ Helpers::show_error_message("Stack is not found. Please try again with different name or try to search.")
68
+ end
69
+ end
70
+ else
71
+ Helpers::AlertMessage.show_error_message("Name or id is required")
72
+ end
73
+ end
74
+
75
+ #
76
+ # search data stack
77
+ #
78
+ def search(keyword)
79
+ Helpers::ErrorException.rescue do
80
+ data = Typhoeus.get(
81
+ "#{@endpoint}/api/v1/stacks/search",
82
+ body: {
83
+ authenticate_token: @api_key,
84
+ email: @email,
85
+ keyword: keyword
86
+ }
87
+ )
88
+
89
+ @data = JSON.parse data.response_body
90
+
91
+ if @data['success']
92
+ Helpers::Table.show_table(@data['stacks'], "Search Result List My Stack", ['ID', 'Name', 'Description', 'Umbreo Stack'])
93
+ else
94
+ Helpers::AlertMessage.show_error_message(@data["message"])
95
+ end
96
+ end
97
+ end
98
+
99
+ #
100
+ # deploy stack
101
+ #
102
+ def deploy(parameters = {})
103
+
104
+ @errors << "Name is required" if parameters[:name].blank?
105
+ @errors << "You need to add a instance" if parameters[:user_node_attributes].blank?
106
+
107
+ if parameters[:user_node_attributes].present?
108
+ parameters[:user_node_attributes].each_with_index do |user_node, index|
109
+ main_param = parameters[:user_node_attributes][index]
110
+
111
+ @errors << "#{main_param[:name]} ##{index} Blueprint Json file is required" if main_param[:name].blank?
112
+ @errors << "#{main_param[:name]} ##{index} Deployment type is required" if main_param[:type].blank?
113
+ @errors << "#{main_param[:name]} ##{index} Compute Provider Json file is required" if main_param[:provider].blank? && main_param[:type] == "provider"
114
+
115
+ main_param[:file_parameter] = {}
116
+
117
+ [:blueprint, :service_logging, :service_monitoring, :service_backup, :provider].each do |file_name|
118
+ file_path = user_node[file_name]
119
+ if file_path.present?
120
+ begin
121
+ file = File.open(file_path, "r")
122
+ content = file.read
123
+ json = JSON.parse(content)
124
+ main_param[file_name] = Helpers::JsonBaseConvert.encode(json)
125
+ rescue
126
+ @errors << "Error on #{ file_path } file. Please check again."
127
+ end
128
+ end
129
+ end
130
+
131
+ end
132
+ end
133
+
134
+ if valid?
135
+ Helpers::ErrorException.rescue do
136
+
137
+ response = Typhoeus.post(
138
+ "#{@endpoint}/api/v1/stacks",
139
+ body: {
140
+ authenticate_token: @api_key,
141
+ email: @email,
142
+ user_stack: {
143
+ name: parameters[:name],
144
+ description: parameters[:desc],
145
+ umbreo_stack_template_id: parameters[:umbreo_stack_template_id],
146
+ user_nodes_attributes: parameters[:user_node_attributes]
147
+ }
148
+ }
149
+ )
150
+
151
+ @response = JSON.parse response.response_body
152
+
153
+ if @response["success"]
154
+ Helpers::AlertMessage.show_success_message("Stack successfully created.")
155
+ else
156
+ Helpers::AlertMessage.show_error_message(@response["message"])
157
+ end
158
+ end
159
+ else
160
+ Helpers::AlertMessage.show_error_message(error)
161
+ end
162
+
163
+ end
164
+
165
+ #
166
+ # Check no error from validation
167
+ #
168
+ def valid?
169
+ @errors.blank?
170
+ end
171
+
172
+ #
173
+ # Get first error
174
+ #
175
+ def error
176
+ @errors.first
177
+ end
178
+
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,43 @@
1
+ module Umbreo
2
+ module Models
3
+ class System
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
14
+ Helpers::ErrorException.rescue do
15
+ data = Typhoeus.get(
16
+ "#{@endpoint}/api/v1/systems",
17
+ body: {
18
+ authenticate_token: @api_key,
19
+ email: @email
20
+ }
21
+ )
22
+
23
+ @data = JSON.parse data.response_body
24
+ @data['systems']
25
+ end
26
+ end
27
+
28
+ #
29
+ # callback for retrieve data
30
+ #
31
+ def all
32
+ retrieve_data
33
+
34
+ if @data['systems'].present?
35
+ Helpers::Table.show_table(@data['systems'], "List System", ['ID', 'Name'])
36
+ else
37
+ Helpers::AlertMessage.show_error_message(@data["message"])
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,163 @@
1
+ module Umbreo
2
+ module Models
3
+ class UmbreoStackTemplate
4
+
5
+ def initialize(credentials = {}, name_or_id = nil)
6
+ if credentials.present?
7
+ @credentials = credentials
8
+ @email = credentials[:email]
9
+ @api_key = credentials[:api_key]
10
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
11
+ end
12
+
13
+ @name_or_id = name_or_id
14
+ end
15
+
16
+ #
17
+ # retrieve all data umbreo stack
18
+ #
19
+ def retrive_data
20
+ Helpers::ErrorException.rescue do
21
+ data = Typhoeus.get(
22
+ "#{@endpoint}/api/v1/stack_templates",
23
+ body: {
24
+ authenticate_token: @api_key,
25
+ email: @email
26
+ }
27
+ )
28
+
29
+ @data = JSON.parse data.response_body
30
+ end
31
+ end
32
+
33
+ #
34
+ # show umbreo stack template
35
+ #
36
+ def show(just_response = false)
37
+ Helpers::ErrorException.rescue do
38
+ response = Typhoeus.get(
39
+ "#{@endpoint}/api/v1/stack_templates/show",
40
+ body: {
41
+ authenticate_token: @api_key,
42
+ email: @email,
43
+ id: @name_or_id
44
+ }
45
+ )
46
+
47
+ @response = JSON.parse response.response_body
48
+
49
+ if @response["success"]
50
+ if just_response
51
+ @response
52
+ else
53
+ Helpers::AlertMessage.show_content_information_message(@response['id']) { "ID: #message" }
54
+ Helpers::AlertMessage.show_content_information_message(@response['name']) { "Name: #message" }
55
+ Helpers::AlertMessage.show_content_information_message(@response['description']) { "Description: #message" }
56
+ Helpers::Table.show_table(@response['roles'], "List Blueprints of #{@response['name']} stack template", ['ID Blueprint', 'Name', 'Max Server'])
57
+ end
58
+
59
+ else
60
+ Helpers::show_error_message("Stack is not found. Please try again with different name or try to search.")
61
+ end
62
+ end
63
+ end
64
+
65
+ #
66
+ # search data umbreo stack template
67
+ #
68
+ def search(keyword)
69
+ Helpers::ErrorException.rescue do
70
+ data = Typhoeus.get(
71
+ "#{@endpoint}/api/v1/stack_templates/search",
72
+ body: {
73
+ authenticate_token: @api_key,
74
+ email: @email,
75
+ keyword: keyword
76
+ }
77
+ )
78
+
79
+ @data = JSON.parse data.response_body
80
+
81
+ if @data['success']
82
+ Helpers::Table.show_table(@data['umbreo_stack_templates'], "List Search Result Umbreo Stack Template", ['ID', 'Name', 'Description'])
83
+ else
84
+ Helpers::AlertMessage.show_error_message(@data["message"])
85
+ end
86
+ end
87
+ end
88
+
89
+ #
90
+ # parsing data umbreo stack to table
91
+ #
92
+ def all
93
+ retrive_data
94
+
95
+ if @data['umbreo_stack_templates'].present?
96
+ Helpers::Table.show_table(@data['umbreo_stack_templates'], "List Umbreo Stack Template", ['ID', 'Name', 'Blueprints'])
97
+ else
98
+ Helpers::AlertMessage.show_error_message("Umbreo Stack Template is not found.")
99
+ end
100
+ end
101
+
102
+ #
103
+ # export umbreo stack template params
104
+ #
105
+ def export
106
+ Helpers::ErrorException.rescue do
107
+ response = Typhoeus.get(
108
+ "#{@endpoint}/api/v1/stack_templates/export",
109
+ body: {
110
+ authenticate_token: @api_key,
111
+ email: @email,
112
+ id: @name_or_id
113
+ }
114
+ )
115
+
116
+ @response = JSON.parse response.response_body rescue nil
117
+
118
+ if @response["umbreo_stack_template"].present?
119
+ name_file = @response["umbreo_stack_template"]["name"].downcase.titleize.delete(" ").underscore
120
+ Helpers::FileGenerator.create(name_file, @response["umbreo_stack_template"])
121
+
122
+ Helpers::AlertMessage.show_success_message("Success export umbreo stack template. your stack template is saved on json file with name #{name_file}.json")
123
+ else
124
+ Helpers::AlertMessage.show_error_message(@response["message"])
125
+ end
126
+ end
127
+ end
128
+
129
+ #
130
+ # export all blueprint of umbreo stack template to files
131
+ #
132
+ def export_bluprints
133
+ Helpers::ErrorException.rescue do
134
+ response = Typhoeus.get(
135
+ "#{@endpoint}/api/v1/stack_templates/retrieve_blueprints",
136
+ body: {
137
+ authenticate_token: @api_key,
138
+ email: @email,
139
+ id: @name_or_id
140
+ }
141
+ )
142
+
143
+ @response = JSON.parse response.response_body
144
+
145
+ if @response["data"].present?
146
+ Helpers::AlertMessage.show_success_message("Creating JSON Files ...")
147
+
148
+ @response["data"].each do |blueprint|
149
+ new_blueprint = Models::Blueprint.new(@credentials, blueprint["id"])
150
+ new_blueprint.export
151
+ end
152
+
153
+ Helpers::AlertMessage.show_success_message("JSON Blueprints of #{ @name_or_id } stack template already created.")
154
+ else
155
+ Helpers::AlertMessage.show_error_message(@response["message"])
156
+ end
157
+
158
+ end
159
+ end
160
+
161
+ end
162
+ end
163
+ end