Class: Umbreo::Models::UmbreoStackTemplate
- Inherits:
-
Object
- Object
- Umbreo::Models::UmbreoStackTemplate
- Defined in:
- lib/umbreo/models/umbreo_stack_template.rb
Instance Method Summary collapse
-
#all ⇒ Object
parsing data umbreo stack to table.
-
#export ⇒ Object
export umbreo stack template params.
-
#export_bluprints ⇒ Object
export all blueprint of umbreo stack template to files.
-
#initialize(credentials = {}, name_or_id = nil) ⇒ UmbreoStackTemplate
constructor
A new instance of UmbreoStackTemplate.
-
#retrive_data ⇒ Object
retrieve all data umbreo stack.
-
#search(keyword) ⇒ Object
search data umbreo stack template.
-
#show(just_response = false) ⇒ Object
show umbreo stack template.
Constructor Details
#initialize(credentials = {}, name_or_id = nil) ⇒ UmbreoStackTemplate
Returns a new instance of UmbreoStackTemplate.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 5 def initialize(credentials = {}, name_or_id = nil) if credentials.present? @credentials = credentials @email = credentials[:email] @api_key = credentials[:api_key] @endpoint = credentials[:end_point] || SERVER_END_POINT end @name_or_id = name_or_id end |
Instance Method Details
#all ⇒ Object
parsing data umbreo stack to table
92 93 94 95 96 97 98 99 100 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 92 def all retrive_data if @data['umbreo_stack_templates'].present? Helpers::Table.show_table(@data['umbreo_stack_templates'], "List Umbreo Stack Template", ['ID', 'Name', 'Blueprints']) else Helpers::AlertMessage.("Umbreo Stack Template is not found.") end end |
#export ⇒ Object
export umbreo stack template params
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 105 def export Helpers::ErrorException.rescue do response = Typhoeus.get( "#{@endpoint}/api/v1/stack_templates/export", body: { authenticate_token: @api_key, email: @email, id: @name_or_id } ) @response = JSON.parse response.response_body rescue nil if @response["umbreo_stack_template"].present? name_file = @response["umbreo_stack_template"]["name"].downcase.titleize.delete(" ").underscore Helpers::FileGenerator.create(name_file, @response["umbreo_stack_template"]) Helpers::AlertMessage.("Success export umbreo stack template. your stack template is saved on json file with name #{name_file}.json") else Helpers::AlertMessage.(@response["message"]) end end end |
#export_bluprints ⇒ Object
export all blueprint of umbreo stack template to files
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/umbreo/models/umbreo_stack_template.rb', line 132 def export_bluprints Helpers::ErrorException.rescue do response = Typhoeus.get( "#{@endpoint}/api/v1/stack_templates/retrieve_blueprints", body: { authenticate_token: @api_key, email: @email, id: @name_or_id } ) @response = JSON.parse response.response_body if @response["data"].present? Helpers::AlertMessage.("Creating JSON Files ...") @response["data"].each do |blueprint| new_blueprint = Models::Blueprint.new(@credentials, blueprint["id"]) new_blueprint.export end Helpers::AlertMessage.("JSON Blueprints of #{ @name_or_id } stack template already created.") else Helpers::AlertMessage.(@response["message"]) end end end |
#retrive_data ⇒ Object
retrieve all data umbreo stack
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 19 def retrive_data Helpers::ErrorException.rescue do data = Typhoeus.get( "#{@endpoint}/api/v1/stack_templates", body: { authenticate_token: @api_key, email: @email } ) @data = JSON.parse data.response_body end end |
#search(keyword) ⇒ Object
search data umbreo stack template
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 68 def search(keyword) Helpers::ErrorException.rescue do data = Typhoeus.get( "#{@endpoint}/api/v1/stack_templates/search", body: { authenticate_token: @api_key, email: @email, keyword: keyword } ) @data = JSON.parse data.response_body if @data['success'] Helpers::Table.show_table(@data['umbreo_stack_templates'], "List Search Result Umbreo Stack Template", ['ID', 'Name', 'Description']) else Helpers::AlertMessage.(@data["message"]) end end end |
#show(just_response = false) ⇒ Object
show umbreo stack template
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/umbreo/models/umbreo_stack_template.rb', line 36 def show(just_response = false) Helpers::ErrorException.rescue do response = Typhoeus.get( "#{@endpoint}/api/v1/stack_templates/show", body: { authenticate_token: @api_key, email: @email, id: @name_or_id } ) @response = JSON.parse response.response_body if @response["success"] if just_response @response else Helpers::AlertMessage.(@response['id']) { "ID: #message" } Helpers::AlertMessage.(@response['name']) { "Name: #message" } Helpers::AlertMessage.(@response['description']) { "Description: #message" } Helpers::Table.show_table(@response['roles'], "List Blueprints of #{@response['name']} stack template", ['ID Blueprint', 'Name', 'Max Server']) end else Helpers::("Stack is not found. Please try again with different name or try to search.") end end end |