lib/wco/serverhost.rb in ish_models-0.0.33.287 vs lib/wco/serverhost.rb in ish_models-0.0.33.291
- old
+ new
@@ -1,26 +1,27 @@
require 'net/scp'
-# require 'autoinc'
class Wco::Serverhost
include Mongoid::Document
include Mongoid::Timestamps
# include Mongoid::Autoinc
field :name, type: :string
- validates :name, uniqueness: { scope: :leadset_id }, presence: true
+ # validates :name, uniqueness: { scope: :leadset_id }, presence: true
+ validates :name, uniqueness: { scope: :wco_leadset }, presence: true
+ # field :leadset_id, type: :integer
+ # has_and_belongs_to_many :leadsets, class_name: 'Wco::Leadset', inverse_of: :serverhosts
+ belongs_to :wco_leadset, class_name: 'Wco::Leadset'
+
field :next_port, type: :integer, default: 8000
- # increments :next_port
- field :leadset_id, type: :integer
-
## net-ssh, sshkit
field :ssh_host
- field :ssh_username
- field :ssh_key
+ # field :ssh_username
+ # field :ssh_key
field :nginx_root, default: '/opt/nginx'
has_many :appliances, class_name: 'Wco::Appliance'
# def nginx_add_site rendered_str=nil, config={}
@@ -48,51 +49,52 @@
end
end
- def docker_add_service rendered_str=nil, config={}
- # puts! config, '#docker_add_service'
- File.write( "/Users/piousbox/projects/docker_demo/dc-#{config[:service_name]}.yml", rendered_str )
- out = ` mkdir /Users/piousbox/projects/docker_demo/#{config[:service_name]}_data `
- puts! out, 'out'
- out = ` cd /Users/piousbox/projects/docker_demo/ ; \
- docker compose -f dc-#{config[:service_name]}.yml up -d #{config[:service_name]} ; \
- echo ok
- `;
- puts! out, 'out'
- end
+ WORKDIR = "/opt/projects/docker"
- def load_data rendered_str=nil, config={}
- File.write( "/Users/piousbox/projects/docker_demo/#{config[:service_name]}_data/index.html", rendered_str )
+ def add_docker_service app={}
+ puts! app, '#add_docker_service'
+
+ ac = ActionController::Base.new
+ ac.instance_variable_set( :@app, app )
+ ac.instance_variable_set( :@workdir, WORKDIR )
+ rendered_str = ac.render_to_string("docker-compose/dc-#{app[:kind]}")
+ puts '+++ add_docker_service rendered_str:'
+ print rendered_str
+
+ file = Tempfile.new('prefix')
+ file.write rendered_str
+ file.close
+ puts! file.path, 'file.path'
+
+ `scp #{file.path} #{ssh_host}:#{WORKDIR}/dc-#{app[:service_name]}.yml`
+ `ssh #{ssh_host} 'cd #{WORKDIR} ; \
+ docker compose -f dc-#{app[:service_name]}.yml up -d #{app[:service_name]} ; \
+ echo ok #add_docker_service ' `
end
+ def create_volume app={}
+ # puts! app, '#create_volume'
-end
+ ac = ActionController::Base.new
+ ac.instance_variable_set( :@app, app )
+ ac.instance_variable_set( :@workdir, WORKDIR )
+ rendered_str = ac.render_to_string("scripts/create_volume")
+ # puts '+++ create_volume rendered_str:'
+ # print rendered_str
-# class Instance
-# def chmod
-# start do |ssh|
-# ssh.exec "sudo chmod +x /tmp/provision.sh"
-# # other operations on ssh
-# end
-# end
-# private
-# def start
-# Net::SSH.start(ip, 'ubuntu', keys: "mykey.pem" ) do |ssh|
-# yield ssh
-# end
-# end
-# end
+ file = Tempfile.new('prefix')
+ file.write rendered_str
+ file.close
+ # puts! file.path, 'file.path'
+ `scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume`
+ `ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
+ #{WORKDIR}/scripts/create_volume ' `
+ end
+ # alias_method :create_volume, :create_volume_2
-## works:
-# nginx_root = '/opt/nginx'
-# config = { service_name: 'abba', }
-# Net::SSH.start( "18.209.12.11", "ubuntu", keys: "access/mac_id_rsa_3.pem" ) do |ssh|
-# out = ssh.scp.upload! "tmp/#{config[:service_name]}", "/opt/tmp/two.txt" do |ch, name, sent, total|
-# puts "#{name}: #{sent}/#{total}"
-# end
-# puts! out, 'out'
-# end
+end