class Rncher::Service
Public Instance Methods
exec()
click to toggle source
# File lib/rncher/service.rb, line 35 def exec app = App.where({system: false, name: options[:app]}).first if app service = Service.where({system: false, stackId: app.id, name: options[:service]}).first container_id = service.instanceIds.first container = Container.find(container_id) credential = container.remote_token(options[:command]) connection = RemoteConnection.new(credential[:url], credential[:token]) connection.start end end
list()
click to toggle source
# File lib/rncher/service.rb, line 6 def list app = App.where({system: false, name: options[: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()
click to toggle source
# File lib/rncher/service.rb, line 50 def logs app = App.where({system: false, name: options[:app]}).first if app service = Service.where({system: false, stackId: app.id, name: options[: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)
click to toggle source
# File lib/rncher/service.rb, line 21 def scale(num) app = App.where({system: false, name: options[:app]}).first if app service = Service.where({system: false, stackId: app.id, name: options[:service]}).first service.scale = num service.save puts 'Done' end end
status()
click to toggle source
# File lib/rncher/service.rb, line 68 def status app = App.where({system: false, name: options[:app]}).first if app service = Service.where({system: false, stackId: app.id, name: options[:service]}).first EventMachine.run do credential = service.request_token connection = RemoteConnection.new(credential[:url], credential[:token]) connection.start_status(service) end end end
upgrade()
click to toggle source
# File lib/rncher/service.rb, line 86 def upgrade app = App.where({system: false, name: options[:app]}).first if app service = Service.where({system: false, stackId: app.id, name: options[:service]}).first launch_config = service.launchConfig if options[:image] launch_config.imageUuid = "docker:#{options[:image]}" end if options[:vars] new_configs = Hash.new options[: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 options[:remove_vars] new_configs = Hash.new launch_config.environment.attributes.each do |k, v| new_configs[k.upcase] = v unless options[:remove_vars].collect{|c| c.upcase}.include?(k.upcase) end launch_config.environment.attributes = new_configs end if options[:image] || options[:vars] || options[: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