Class: Rncher::Service
- Inherits:
-
Thor
- Object
- Thor
- Rncher::Service
- Defined in:
- lib/rncher/service.rb
Instance Method Summary collapse
- #exec ⇒ Object
- #list ⇒ Object
- #logs ⇒ Object
- #scale(num) ⇒ Object
- #status ⇒ Object
- #upgrade ⇒ Object
Instance Method Details
#exec ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rncher/service.rb', line 35 def exec app = App.where({system: false, name: [:app]}).first if app service = Service.where({system: false, stackId: app.id, name: [:service]}).first container_id = service.instanceIds.first container = Container.find(container_id) credential = container.remote_token([:command]) connection = RemoteConnection.new(credential[:url], credential[:token]) connection.start end end |
#list ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rncher/service.rb', line 6 def list app = App.where({system: false, name: [:app]}).first if app services = Service.where({system: false, stackId: app.id}) table = TTY::Table.new header: ['name','state', 'health', 'scale'] services.each do |app| table << [app.name, app.state, app.healthState, app.scale] end puts table.render(:ascii, border:{separator: :each_row}) end end |
#logs ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rncher/service.rb', line 50 def logs app = App.where({system: false, name: [:app]}).first if app service = Service.where({system: false, stackId: app.id, name: [:service]}).first EventMachine.run do service.instanceIds.each do |container_id| container = Container.find(container_id) credential = container.logs_token connection = RemoteConnection.new(credential[:url], credential[:token]) connection.start_logs(container) end end end end |
#scale(num) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/rncher/service.rb', line 21 def scale(num) app = App.where({system: false, name: [:app]}).first if app service = Service.where({system: false, stackId: app.id, name: [:service]}).first service.scale = num service.save puts 'Done' end end |
#status ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rncher/service.rb', line 68 def status app = App.where({system: false, name: [:app]}).first if app service = Service.where({system: false, stackId: app.id, name: [:service]}).first EventMachine.run do credential = service.request_token connection = RemoteConnection.new(credential[:url], credential[:token]) connection.start_status(service) end end end |
#upgrade ⇒ Object
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 |
# File 'lib/rncher/service.rb', line 86 def upgrade app = App.where({system: false, name: [:app]}).first if app service = Service.where({system: false, stackId: app.id, name: [:service]}).first launch_config = service.launchConfig if [:image] launch_config.imageUuid = "docker:#{[:image]}" end if [:vars] new_configs = Hash.new [:vars].map{|k, v| new_configs[k.upcase] = v} new_attributes = launch_config.environment.attributes.merge(new_configs) launch_config.environment.attributes = new_attributes end if [:remove_vars] new_configs = Hash.new launch_config.environment.attributes.each do |k, v| new_configs[k.upcase] = v unless [:remove_vars].collect{|c| c.upcase}.include?(k.upcase) end launch_config.environment.attributes = new_configs end if [:image] || [:vars] || [:remove_vars] attributes = { "inServiceStrategy": { "batchSize": 1, "intervalMillis": 2000, "launchConfig": launch_config, "startFirst": true }, "toServiceStrategy": "null" } service.upgrade(attributes) service = Service.find(service.id) state = service.state while(state=='upgrading') do sleep 2 service = Service.find(service.id) state = service.state end service.finish_upgrade end end end |