Module: Waz::Cmd
- Defined in:
- lib/waz-cmd.rb,
lib/waz-cmd/version.rb
Constant Summary collapse
- VERSION =
"0.4.2"
Instance Method Summary collapse
- #arrayize(x) ⇒ Object
- #make_call(path, method, options, body = nil) ⇒ Object
- #restar_instance(star) ⇒ Object
- #set_defaults(options) ⇒ Object
- #startstop(verb, status) ⇒ Object
- #wait_for_completion(options, requestId) ⇒ Object
Instance Method Details
#arrayize(x) ⇒ Object
51 52 53 54 55 |
# File 'lib/waz-cmd.rb', line 51 def arrayize(x) return [] if x.nil? return x if x.kind_of?(Array) return [x] end |
#make_call(path, method, options, body = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/waz-cmd.rb', line 32 def make_call(path, method, , body=nil) headers = { 'x-ms-version' => '2011-06-01' } headers['Content-Type'] = 'application/xml' unless body.nil? RestClient.proxy = .proxy if .proxy = { :url => "https://management.core.windows.net/#{.subscriptionId}/#{path}", :method => method, :headers => headers, :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read(.pem)), :ssl_client_key => OpenSSL::PKey::RSA.new(File.read(.key)) } [:payload] = body unless body.nil? if block_given? yield RestClient::Request.execute else Crack::XML.parse RestClient::Request.execute end end |
#restar_instance(star) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/waz-cmd.rb', line 57 def restar_instance(star) command "re#{star} instance" do |c| c.syntax = "waz re#{star} instance <application> <production|staging> <instance> [options]" c.description = "Re#{star} the specified instance" c.action do |args, | set_defaults raise 'Subscription ID is required' unless .subscriptionId raise 'Application name is required' unless args[0] raise 'Deployment name is required' unless args[1] raise 'Instance name is required' unless args[2] make_call("services/hostedservices/#{args[0]}/deploymentslots/#{args[1]}/roleinstances/#{args[2]}?comp=re#{star}", :post, , '') do |response| wait_for_completion , response.headers[:x_ms_request_id] end end end end |
#set_defaults(options) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/waz-cmd.rb', line 24 def set_defaults() .default :pem => "#{ENV['HOME']}/.waz/cert.pem", :cer => "#{ENV['HOME']}/.waz/cert.cer", :key => "#{ENV['HOME']}/.waz/key.pem" .default :subscriptionId => $config['subscriptionId'] if $config['subscriptionId'] proxy = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['all_proxy'] || ENV['ALL_PROXY'] proxy = 'https://' + proxy if proxy and not proxy =~ /^https?:\/\//i .default :proxy => proxy if proxy end |
#startstop(verb, status) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/waz-cmd.rb', line 74 def startstop(verb, status) command verb do |c| c.syntax = "waz #{verb} <application> <production|staging> [options]" c.description = "#{verb.capitalize} the deployment in the specified slot of the specified application" c.action do |args, | set_defaults raise 'Subscription ID is required' unless .subscriptionId raise 'Application name is required' unless args[0] raise 'Deployment slot is required' unless args[1] make_call("services/hostedservices/#{args[0]}/deploymentslots/#{args[1]}/?comp=status", :post, , Nokogiri::XML::Builder.new(:encoding => 'utf-8') { |xml| xml.UpdateDeploymentStatus('xmlns' => 'http://schemas.microsoft.com/windowsazure') { xml.Status status } }.to_xml) do |response| wait_for_completion , response.headers[:x_ms_request_id] end end end end |
#wait_for_completion(options, requestId) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/waz-cmd.rb', line 96 def wait_for_completion(, requestId) puts 'Waiting for operation to complete...' done = false while not done status = make_call("operations/#{requestId}", :get, )['Operation'] done = status['Status'] != 'InProgress' if done puts "Operation #{status['Status'].downcase} (#{status['HttpStatusCode']})" if status['Error'] puts "#{status['Error']['Code']}: #{status['Error']['Message']}" end else sleep 10 end end end |