Class: RightScaleCLI::ServerTemplates
- Inherits:
-
Thor
- Object
- Thor
- RightScaleCLI::ServerTemplates
- Defined in:
- lib/rightscale_cli/server_templates.rb
Instance Method Summary collapse
- #inputs(server_template_id) ⇒ Object
- #inputs_dashboard(server_template_id) ⇒ Object
- #list ⇒ Object
- #show(server_template_id) ⇒ Object
Instance Method Details
#inputs(server_template_id) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rightscale_cli/server_templates.rb', line 66 def inputs(server_template_id) log = CLILogger.new rightscale = RightApi::Client.new(RightScaleCLI::Config::API) server_template_inputs = [] rightscale.server_templates(:id => server_template_id).show.inputs.index.each { |input| server_template_inputs.push(input.raw) } if [:xml] puts server_template_inputs.to_xml(:root => 'server_template') elsif [:json] puts JSON.pretty_generate(server_template_inputs) else puts server_template_inputs.to_yaml end end |
#inputs_dashboard(server_template_id) ⇒ Object
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 |
# File 'lib/rightscale_cli/server_templates.rb', line 83 def inputs_dashboard(server_template_id) rightscale = RightApi::Client.new(RightScaleCLI::Config::API) uri = URI.parse("#{rightscale.api_url}/acct/#{rightscale.account_id}/inputs/edit_inputs?container_id=#{server_template_id}&container_type=ServerTemplate") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) request.add_field("Referer", "#{rightscale.api_url}/acct/#{rightscale.account_id}/server_templates/#{server_template_id}") request.add_field("X-Requested-With", "XMLHttpRequest") request.add_field("Cookie", rightscale.last_request[:request].headers[:cookie]) response = http.request(request) puts response.body if [:debug] require 'nokogiri' inputs = [] html = Nokogiri::HTML(response.body) input_list = html.css('ul[class=inputList]').css('li[class=inputContainer]').css('div[class=inputInformation]').each { |input_html| input = {} input['name'] = input_html.css('div')[0].text.gsub!(/\s+/, "") input['possible_values'] = [] input_html.css('div[class=inputValue]').css('select[class=possible_values] option').each { |option| input['current'] = option['value'] if option['selected'] == 'selected' input['possible_values'].push(option['value']) } inputs.push(input) } if [:xml] puts inputs.to_xml(:root => 'inputs') elsif [:json] puts JSON.pretty_generate(inputs) else puts inputs.to_yaml end end |
#list ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rightscale_cli/server_templates.rb', line 32 def list() log = CLILogger.new rightscale = RightApi::Client.new(RightScaleCLI::Config::API) server_templates = [] rightscale.server_templates.index.each { |server_template| server_templates.push(server_template.raw) } if [:xml] puts server_templates.to_xml(:root => 'server_templates') elsif [:json] puts JSON.pretty_generate(server_templates) else puts server_templates.to_yaml end end |
#show(server_template_id) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rightscale_cli/server_templates.rb', line 50 def show(server_template_id) log = CLILogger.new rightscale = RightApi::Client.new(RightScaleCLI::Config::API) server_template = rightscale.server_templates(:id => server_template_id).show.raw if [:xml] puts server_template.to_xml(:root => 'server_template') elsif [:json] puts JSON.pretty_generate(server_template) else puts server_template.to_yaml end end |