Module: Morpheus::Cli::ProvisioningHelper
- Included in:
- Instances
- Defined in:
- lib/morpheus/cli/mixins/provisioning_helper.rb
Overview
Provides common methods for provisioning instances
Class Method Summary collapse
Instance Method Summary collapse
-
#prompt_instance_volumes(plan_info, options = {}, api_client = nil, api_params = {}) ⇒ Object
This recreates the behavior of multi_disk.js returns array of volumes based on service plan options (plan_info).
-
#prompt_resize_instance_volumes(current_volumes, plan_info, options = {}, api_client = nil, api_params = {}) ⇒ Object
This recreates the behavior of multi_disk.js returns array of volumes based on service plan options (plan_info).
Class Method Details
.included(klass) ⇒ Object
7 8 9 |
# File 'lib/morpheus/cli/mixins/provisioning_helper.rb', line 7 def self.included(klass) klass.include Morpheus::Cli::PrintHelper end |
Instance Method Details
#prompt_instance_volumes(plan_info, options = {}, api_client = nil, api_params = {}) ⇒ Object
This recreates the behavior of multi_disk.js returns array of volumes based on service plan options (plan_info)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/morpheus/cli/mixins/provisioning_helper.rb', line 13 def prompt_instance_volumes(plan_info, ={}, api_client=nil, api_params={}) #puts "Configure Volumes:" no_prompt = ([:no_prompt] || ([:options] && [:options][:no_prompt])) volumes = [] plan_size = nil if plan_info['maxStorage'] plan_size = plan_info['maxStorage'].to_i / (1024 * 1024 * 1024) end root_storage_types = [] if plan_info['rootStorageTypes'] plan_info['rootStorageTypes'].each do |opt| root_storage_types << {'name' => opt['name'], 'value' => opt['id']} end end storage_types = [] if plan_info['storageTypes'] plan_info['storageTypes'].each do |opt| storage_types << {'name' => opt['name'], 'value' => opt['id']} end end = [] if plan_info['supportsAutoDatastore'] if plan_info['autoOptions'] plan_info['autoOptions'].each do |opt| << {'name' => opt['name'], 'value' => opt['id']} end end end if plan_info['datastores'] plan_info['datastores'].each do |k, v| v.each do |opt| << {'name' => "#{k}: #{opt['name']}", 'value' => opt['id']} end end end #puts "Configure Root Volume" field_context = "rootVolume" if root_storage_types.empty? # this means there's no configuration, just send a single root volume to the server storage_type_id = nil storage_type = nil else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => 'Root Storage Type', 'selectOptions' => root_storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], [:options]) storage_type_id = v_prompt[field_context]['storageType'] storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i } end # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form = [] if plan_info['rootCustomSizeOptions'] && plan_info['rootCustomSizeOptions'][storage_type_id.to_s] plan_info['rootCustomSizeOptions'][storage_type_id.to_s].each do |opt| << {'name' => opt['value'], 'value' => opt['key']} end end volume_label = 'root' volume = { 'id' => -1, 'rootVolume' => true, 'name' => volume_label, 'size' => plan_size, 'sizeId' => nil, 'storageType' => storage_type_id, 'datastoreId' => nil } if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customLabel'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Root Volume Label', 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume_label}], [:options]) volume['name'] = v_prompt[field_context]['name'] end if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customSize'] if .empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => 'Root Volume Size (GB)', 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => plan_size}], [:options]) volume['size'] = v_prompt[field_context]['size'] volume['sizeId'] = nil #volume.delete('sizeId') else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => 'Root Volume Size', 'selectOptions' => , 'required' => true, 'description' => 'Choose a volume size.'}], [:options]) volume['sizeId'] = v_prompt[field_context]['sizeId'] volume['size'] = nil #volume.delete('size') end else # might need different logic here ? =o volume['size'] = plan_size volume['sizeId'] = nil #volume.delete('sizeId') end if !.empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => 'Root Datastore', 'selectOptions' => , 'required' => true, 'description' => 'Choose a datastore.'}], [:options]) volume['datastoreId'] = v_prompt[field_context]['datastoreId'] end volumes << volume if plan_info['addVolumes'] volume_index = 1 has_another_volume = [:options] && [:options]["dataVolume#{volume_index}"] add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add data volume?")) while add_another_volume do #puts "Configure Data #{volume_index} Volume" field_context = "dataVolume#{volume_index}" v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Storage Type", 'selectOptions' => storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], [:options]) storage_type_id = v_prompt[field_context]['storageType'] storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i } # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form = [] if plan_info['customSizeOptions'] && plan_info['customSizeOptions'][storage_type_id.to_s] plan_info['customSizeOptions'][storage_type_id.to_s].each do |opt| << {'name' => opt['value'], 'value' => opt['key']} end end volume_label = (volume_index == 1 ? 'data' : "data #{volume_index}") volume = { 'id' => -1, 'rootVolume' => false, 'name' => volume_label, 'size' => plan_size, 'sizeId' => nil, 'storageType' => storage_type_id, 'datastoreId' => nil } if plan_info['customizeVolume'] && storage_type['customLabel'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "Disk #{volume_index} Volume Label", 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume_label}], [:options]) volume['name'] = v_prompt[field_context]['name'] end if plan_info['customizeVolume'] && storage_type['customSize'] if .empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => "Disk #{volume_index} Volume Size (GB)", 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => plan_size}], [:options]) volume['size'] = v_prompt[field_context]['size'] volume['sizeId'] = nil #volume.delete('sizeId') else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Volume Size", 'selectOptions' => , 'required' => true, 'description' => 'Choose a volume size.'}], [:options]) volume['sizeId'] = v_prompt[field_context]['sizeId'] volume['size'] = nil #volume.delete('size') end else # might need different logic here ? =o volume['size'] = plan_size volume['sizeId'] = nil #volume.delete('sizeId') end if !.empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Datastore", 'selectOptions' => , 'required' => true, 'description' => 'Choose a datastore.'}], [:options]) volume['datastoreId'] = v_prompt[field_context]['datastoreId'] end volumes << volume # todo: should maxDisk check consider the root volume too? if plan_info['maxDisk'] && volume_index >= plan_info['maxDisk'] add_another_volume = false else volume_index += 1 has_another_volume = [:options] && [:options]["dataVolume#{volume_index}"] add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another data volume?")) end end end return volumes end |
#prompt_resize_instance_volumes(current_volumes, plan_info, options = {}, api_client = nil, api_params = {}) ⇒ Object
This recreates the behavior of multi_disk.js returns array of volumes based on service plan options (plan_info)
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/morpheus/cli/mixins/provisioning_helper.rb', line 194 def prompt_resize_instance_volumes(current_volumes, plan_info, ={}, api_client=nil, api_params={}) #puts "Configure Volumes:" no_prompt = ([:no_prompt] || ([:options] && [:options][:no_prompt])) current_root_volume = current_volumes[0] volumes = [] plan_size = nil if plan_info['maxStorage'] plan_size = plan_info['maxStorage'].to_i / (1024 * 1024 * 1024) end root_storage_types = [] if plan_info['rootStorageTypes'] plan_info['rootStorageTypes'].each do |opt| root_storage_types << {'name' => opt['name'], 'value' => opt['id']} end end storage_types = [] if plan_info['storageTypes'] plan_info['storageTypes'].each do |opt| storage_types << {'name' => opt['name'], 'value' => opt['id']} end end = [] if plan_info['supportsAutoDatastore'] if plan_info['autoOptions'] plan_info['autoOptions'].each do |opt| << {'name' => opt['name'], 'value' => opt['id']} end end end if plan_info['datastores'] plan_info['datastores'].each do |k, v| v.each do |opt| << {'name' => "#{k}: #{opt['name']}", 'value' => opt['id']} end end end #puts "Configure Root Volume" field_context = "rootVolume" if root_storage_types.empty? # this means there's no configuration, just send a single root volume to the server storage_type_id = nil storage_type = nil else #v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => 'Root Storage Type', 'selectOptions' => root_storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], options[:options]) #storage_type_id = v_prompt[field_context]['storageType'] storage_type_id = current_root_volume['type'] || current_root_volume['storageType'] storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i } end # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form = [] if plan_info['rootCustomSizeOptions'] && plan_info['rootCustomSizeOptions'][storage_type_id.to_s] plan_info['rootCustomSizeOptions'][storage_type_id.to_s].each do |opt| << {'name' => opt['value'], 'value' => opt['key']} end end volume = { 'id' => current_root_volume['id'], 'rootVolume' => true, 'name' => current_root_volume['name'], 'size' => current_root_volume['size'] > plan_size ? current_root_volume['size'] : plan_size, 'sizeId' => nil, 'storageType' => storage_type_id, 'datastoreId' => current_root_volume['datastoreId'] } if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customLabel'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Root Volume Label', 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume['name']}], [:options]) volume['name'] = v_prompt[field_context]['name'] end if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customSize'] if .empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => 'Root Volume Size (GB)', 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => volume['size']}], [:options]) volume['size'] = v_prompt[field_context]['size'] volume['sizeId'] = nil #volume.delete('sizeId') else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => 'Root Volume Size', 'selectOptions' => , 'required' => true, 'description' => 'Choose a volume size.'}], [:options]) volume['sizeId'] = v_prompt[field_context]['sizeId'] volume['size'] = nil #volume.delete('size') end else # might need different logic here ? =o volume['size'] = plan_size volume['sizeId'] = nil #volume.delete('sizeId') end # if !datastore_options.empty? # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => 'Root Datastore', 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.'}], options[:options]) # volume['datastoreId'] = v_prompt[field_context]['datastoreId'] # end volumes << volume # modify or delete existing data volumes (1..(current_volumes.size-1)).each do |volume_index| current_volume = current_volumes[volume_index] if current_volume field_context = "dataVolume#{volume_index}" if no_prompt volume_action = 'keep' else = [{'name' => 'Modify', 'value' => 'modify'}, {'name' => 'Keep', 'value' => 'keep'}, {'name' => 'Delete', 'value' => 'delete'}] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'action', 'type' => 'select', 'fieldLabel' => "Modify/Keep/Delete volume '#{current_volume['name']}'", 'selectOptions' => , 'required' => true, 'description' => 'Modify, Keep or Delete existing data volume?'}], [:options]) volume_action = v_prompt[field_context]['action'] end if volume_action == 'delete' # deleted volume is just excluded from post params next elsif volume_action == 'keep' volume = { 'id' => current_volume['id'].to_i, 'rootVolume' => false, 'name' => current_volume['name'], 'size' => current_volume['size'] > plan_size ? current_volume['size'] : plan_size, 'sizeId' => nil, 'storageType' => (current_volume['type'] || current_volume['storageType']), 'datastoreId' => current_volume['datastoreId'] } volumes << volume else # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Storage Type", 'selectOptions' => storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], options[:options]) # storage_type_id = v_prompt[field_context]['storageType'] storage_type_id = current_volume['type'] || current_volume['storageType'] storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i } # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form = [] if plan_info['customSizeOptions'] && plan_info['customSizeOptions'][storage_type_id.to_s] plan_info['customSizeOptions'][storage_type_id.to_s].each do |opt| << {'name' => opt['value'], 'value' => opt['key']} end end volume = { 'id' => current_volume['id'].to_i, 'rootVolume' => false, 'name' => current_volume['name'], 'size' => current_volume['size'] > plan_size ? current_volume['size'] : plan_size, 'sizeId' => nil, 'storageType' => (current_volume['type'] || current_volume['storageType']), 'datastoreId' => current_volume['datastoreId'] } if plan_info['customizeVolume'] && storage_type['customLabel'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "Disk #{volume_index} Volume Label", 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume['name']}], [:options]) volume['name'] = v_prompt[field_context]['name'] end if plan_info['customizeVolume'] && storage_type['customSize'] if .empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => "Disk #{volume_index} Volume Size (GB)", 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => volume['size']}], [:options]) volume['size'] = v_prompt[field_context]['size'] volume['sizeId'] = nil #volume.delete('sizeId') else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Volume Size", 'selectOptions' => , 'required' => true, 'description' => 'Choose a volume size.'}], [:options]) volume['sizeId'] = v_prompt[field_context]['sizeId'] volume['size'] = nil #volume.delete('size') end else # might need different logic here ? =o volume['size'] = plan_size volume['sizeId'] = nil #volume.delete('sizeId') end # if !datastore_options.empty? # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Datastore", 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.'}], options[:options]) # volume['datastoreId'] = v_prompt[field_context]['datastoreId'] # end volumes << volume end end end if plan_info['addVolumes'] volume_index = current_volumes.size has_another_volume = [:options] && [:options]["dataVolume#{volume_index}"] add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add data volume?")) while add_another_volume do #puts "Configure Data #{volume_index} Volume" field_context = "dataVolume#{volume_index}" v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Storage Type", 'selectOptions' => storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], [:options]) storage_type_id = v_prompt[field_context]['storageType'] storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i } # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form = [] if plan_info['customSizeOptions'] && plan_info['customSizeOptions'][storage_type_id.to_s] plan_info['customSizeOptions'][storage_type_id.to_s].each do |opt| << {'name' => opt['value'], 'value' => opt['key']} end end volume_label = (volume_index == 1 ? 'data' : "data #{volume_index}") volume = { 'id' => -1, 'rootVolume' => false, 'name' => volume_label, 'size' => plan_size, 'sizeId' => nil, 'storageType' => storage_type_id, 'datastoreId' => nil } if plan_info['customizeVolume'] && storage_type['customLabel'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "Disk #{volume_index} Volume Label", 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume_label}], [:options]) volume['name'] = v_prompt[field_context]['name'] end if plan_info['customizeVolume'] && storage_type['customSize'] if .empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => "Disk #{volume_index} Volume Size (GB)", 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => plan_size}], [:options]) volume['size'] = v_prompt[field_context]['size'] volume['sizeId'] = nil #volume.delete('sizeId') else v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Volume Size", 'selectOptions' => , 'required' => true, 'description' => 'Choose a volume size.'}], [:options]) volume['sizeId'] = v_prompt[field_context]['sizeId'] volume['size'] = nil #volume.delete('size') end else # might need different logic here ? =o volume['size'] = plan_size volume['sizeId'] = nil #volume.delete('sizeId') end if !.empty? v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Datastore", 'selectOptions' => , 'required' => true, 'description' => 'Choose a datastore.'}], [:options]) volume['datastoreId'] = v_prompt[field_context]['datastoreId'] end volumes << volume # todo: should maxDisk check consider the root volume too? if plan_info['maxDisk'] && volume_index >= plan_info['maxDisk'] add_another_volume = false else volume_index += 1 has_another_volume = [:options] && [:options]["dataVolume#{volume_index}"] add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another data volume?")) end end end return volumes end |