Module: Morpheus::Cli::VdiHelper
- Included in:
- VdiAllocationsCommand, VdiAppsCommand, VdiGatewaysCommand, VdiPoolsCommand
- Defined in:
- lib/morpheus/cli/mixins/vdi_helper.rb
Overview
Provides common finder methods for VDI Pool management commands
Class Method Summary collapse
Instance Method Summary collapse
- #find_vdi_allocation_by_id(id) ⇒ Object
- #find_vdi_app_by_id(id) ⇒ Object
- #find_vdi_app_by_name(name) ⇒ Object
- #find_vdi_app_by_name_or_id(val) ⇒ Object
- #find_vdi_gateway_by_id(id) ⇒ Object
- #find_vdi_gateway_by_name(name) ⇒ Object
- #find_vdi_gateway_by_name_or_id(val) ⇒ Object
- #find_vdi_pool_by_id(id) ⇒ Object
- #find_vdi_pool_by_name(name) ⇒ Object
- #find_vdi_pool_by_name_or_id(val) ⇒ Object
- #format_vdi_allocation_status(vdi_allocation, return_color = cyan) ⇒ Object
- #format_vdi_pool_status(vdi_pool, return_color = cyan) ⇒ Object
- #get_available_vdi_apps(refresh = false) ⇒ Object
- #get_vdi_app_by_name_or_code(name) ⇒ Object
- #vdi_allocation_list_key ⇒ Object
- #vdi_allocation_object_key ⇒ Object
-
#vdi_allocations_interface ⇒ Object
VDI Allocations.
- #vdi_app_list_key ⇒ Object
- #vdi_app_object_key ⇒ Object
-
#vdi_apps_interface ⇒ Object
VDI Apps.
- #vdi_gateway_list_key ⇒ Object
- #vdi_gateway_object_key ⇒ Object
-
#vdi_gateways_interface ⇒ Object
VDI Gateways.
- #vdi_pool_list_key ⇒ Object
- #vdi_pool_object_key ⇒ Object
-
#vdi_pools_interface ⇒ Object
VDI Pools.
Class Method Details
.included(klass) ⇒ Object
5 6 7 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 5 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#find_vdi_allocation_by_id(id) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 93 def find_vdi_allocation_by_id(id) begin json_response = vdi_allocations_interface.get(id.to_i) return json_response[vdi_allocation_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "VDI Allocation not found by id '#{id}'" else raise e end end end |
#find_vdi_app_by_id(id) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 159 def find_vdi_app_by_id(id) begin json_response = vdi_apps_interface.get(id.to_i) return json_response[vdi_app_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "VDI App not found by id '#{id}'" else raise e end end end |
#find_vdi_app_by_name(name) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 172 def find_vdi_app_by_name(name) json_response = vdi_apps_interface.list({name: name.to_s}) vdi_apps = json_response[vdi_app_list_key] if vdi_apps.empty? print_red_alert "VDI App not found by name '#{name}'" return nil elsif vdi_apps.size > 1 print_red_alert "#{vdi_apps.size} VDI App found by name '#{name}'" print_error "\n" puts_error as_pretty_table(vdi_apps, {"ID" => 'id', "NAME" => 'name'}, {color:red}) print_red_alert "Try using ID instead" print_error reset,"\n" return nil else return vdi_apps[0] end end |
#find_vdi_app_by_name_or_id(val) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 151 def find_vdi_app_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_vdi_app_by_id(val) else return find_vdi_app_by_name(val) end end |
#find_vdi_gateway_by_id(id) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 214 def find_vdi_gateway_by_id(id) begin json_response = vdi_gateways_interface.get(id.to_i) return json_response[vdi_gateway_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "VDI Gateway not found by id '#{id}'" else raise e end end end |
#find_vdi_gateway_by_name(name) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 227 def find_vdi_gateway_by_name(name) json_response = vdi_gateways_interface.list({name: name.to_s}) vdi_gateways = json_response[vdi_gateway_list_key] if vdi_gateways.empty? print_red_alert "VDI Gateway not found by name '#{name}'" return nil elsif vdi_gateways.size > 1 print_red_alert "#{vdi_gateways.size} VDI Gateway found by name '#{name}'" print_error "\n" puts_error as_pretty_table(vdi_gateways, {"ID" => 'id', "NAME" => 'name'}, {color:red}) print_red_alert "Try using ID instead" print_error reset,"\n" return nil else return vdi_gateways[0] end end |
#find_vdi_gateway_by_name_or_id(val) ⇒ Object
206 207 208 209 210 211 212 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 206 def find_vdi_gateway_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_vdi_gateway_by_id(val) else return find_vdi_gateway_by_name(val) end end |
#find_vdi_pool_by_id(id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 32 def find_vdi_pool_by_id(id) begin json_response = vdi_pools_interface.get(id.to_i) return json_response[vdi_pool_object_key] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "VDI Pool not found by id '#{id}'" else raise e end end end |
#find_vdi_pool_by_name(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 45 def find_vdi_pool_by_name(name) json_response = vdi_pools_interface.list({name: name.to_s}) vdi_pools = json_response[vdi_pool_list_key] if vdi_pools.empty? print_red_alert "VDI Pool not found by name '#{name}'" return nil elsif vdi_pools.size > 1 print_red_alert "#{vdi_pools.size} VDI Pools found by name '#{name}'" print_error "\n" puts_error as_pretty_table(vdi_pools, [:id, :name], {color:red}) print_red_alert "Try using ID instead" print_error reset,"\n" return nil else return vdi_pools[0] end end |
#find_vdi_pool_by_name_or_id(val) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 24 def find_vdi_pool_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_vdi_pool_by_id(val) else return find_vdi_pool_by_name(val) end end |
#format_vdi_allocation_status(vdi_allocation, return_color = cyan) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 106 def format_vdi_allocation_status(vdi_allocation, return_color=cyan) out = "" status_string = vdi_allocation['status'].to_s.downcase if status_string if ['available'].include?(status_string) out << "#{green}#{status_string.upcase}" # elsif ['preparing'].include?(status_string) # out << "#{yellow}#{status_string.upcase}" # elsif ['reserved', 'shutdown'].include?(status_string) # out << "#{yellow}#{status_string.upcase}" elsif ['failed'].include?(status_string) out << "#{red}#{status_string.upcase}" else out << "#{return_color}#{status_string.upcase}" end end out + return_color end |
#format_vdi_pool_status(vdi_pool, return_color = cyan) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 63 def format_vdi_pool_status(vdi_pool, return_color=cyan) out = "" status_string = vdi_pool['status'].to_s.downcase if status_string if ['available'].include?(status_string) out << "#{green}#{status_string.upcase}" elsif ['unavailable'].include?(status_string) out << "#{red}#{status_string.upcase}" else out << "#{return_color}#{status_string.upcase}" end end out + return_color end |
#get_available_vdi_apps(refresh = false) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 125 def get_available_vdi_apps(refresh=false) if !@available_vdi_apps || refresh @available_vdi_apps = @vdi_apps_interface.list({max:-1})['vdiApps'] # || [] end return @available_vdi_apps end |
#get_vdi_app_by_name_or_code(name) ⇒ Object
132 133 134 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 132 def get_vdi_app_by_name_or_code(name) return get_available_vdi_apps().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase} end |
#vdi_allocation_list_key ⇒ Object
89 90 91 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 89 def vdi_allocation_list_key 'vdiAllocations' end |
#vdi_allocation_object_key ⇒ Object
85 86 87 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 85 def vdi_allocation_object_key 'vdiAllocation' end |
#vdi_allocations_interface ⇒ Object
VDI Allocations
80 81 82 83 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 80 def vdi_allocations_interface raise "#{self.class} has not defined @vdi_allocations_interface" if @vdi_allocations_interface.nil? @vdi_allocations_interface end |
#vdi_app_list_key ⇒ Object
147 148 149 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 147 def vdi_app_list_key 'vdiApps' end |
#vdi_app_object_key ⇒ Object
143 144 145 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 143 def vdi_app_object_key 'vdiApp' end |
#vdi_apps_interface ⇒ Object
VDI Apps
138 139 140 141 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 138 def vdi_apps_interface raise "#{self.class} has not defined @vdi_apps_interface" if @vdi_apps_interface.nil? @vdi_apps_interface end |
#vdi_gateway_list_key ⇒ Object
202 203 204 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 202 def vdi_gateway_list_key 'vdiGateways' end |
#vdi_gateway_object_key ⇒ Object
198 199 200 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 198 def vdi_gateway_object_key 'vdiGateway' end |
#vdi_gateways_interface ⇒ Object
VDI Gateways
193 194 195 196 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 193 def vdi_gateways_interface raise "#{self.class} has not defined @vdi_gateways_interface" if @vdi_gateways_interface.nil? @vdi_gateways_interface end |
#vdi_pool_list_key ⇒ Object
20 21 22 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 20 def vdi_pool_list_key 'vdiPools' end |
#vdi_pool_object_key ⇒ Object
16 17 18 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 16 def vdi_pool_object_key 'vdiPool' end |
#vdi_pools_interface ⇒ Object
VDI Pools
11 12 13 14 |
# File 'lib/morpheus/cli/mixins/vdi_helper.rb', line 11 def vdi_pools_interface raise "#{self.class} has not defined @vdi_pools_interface" if @vdi_pools_interface.nil? @vdi_pools_interface end |