Class: DockerPier::Pier
- Inherits:
-
Object
- Object
- DockerPier::Pier
- Defined in:
- lib/docker-pier/pier.rb
Instance Attribute Summary collapse
-
#docker_uri ⇒ Object
readonly
Returns the value of attribute docker_uri.
-
#libvirt_uri ⇒ Object
readonly
Returns the value of attribute libvirt_uri.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ssh_uri ⇒ Object
readonly
Returns the value of attribute ssh_uri.
Class Method Summary collapse
Instance Method Summary collapse
- #bootstrap! ⇒ Object
- #docker ⇒ Object
-
#initialize(pier_uri, opts = {}) ⇒ Pier
constructor
A new instance of Pier.
- #libvirt ⇒ Object
- #logs ⇒ Object
- #nodes ⇒ Object
- #resolved_docker_uri ⇒ Object
- #ssh ⇒ Object
- #ssh_connstring ⇒ Object
- #x509_dir ⇒ Object
Constructor Details
#initialize(pier_uri, opts = {}) ⇒ Pier
Returns a new instance of Pier.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/docker-pier/pier.rb', line 15 def initialize(pier_uri, opts = {}) @name = opts.delete(:name) || ENV['DOCKER_MACHINE_NAME'] || Digest::SHA1.hexdigest(pier_uri) pier_uri = URI.parse(pier_uri.to_s) unless pier_uri.kind_of?(URI) @libvirt_uri = pier_uri.dup.tap do |uri| uri.scheme = 'qemu+ssh' uri.path = '/system' uri.query = 'socket=/var/run/libvirt/libvirt-sock' end @docker_uri = pier_uri.dup.tap do |uri| uri.scheme = 'tcp' uri.user = nil uri.port = 2376 uri.path = '/' end @ssh_uri = pier_uri.dup.tap do |uri| uri.scheme = 'ssh' uri.port = 22 uri.path = '/' end end |
Instance Attribute Details
#docker_uri ⇒ Object (readonly)
Returns the value of attribute docker_uri.
42 43 44 |
# File 'lib/docker-pier/pier.rb', line 42 def docker_uri @docker_uri end |
#libvirt_uri ⇒ Object (readonly)
Returns the value of attribute libvirt_uri.
41 42 43 |
# File 'lib/docker-pier/pier.rb', line 41 def libvirt_uri @libvirt_uri end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/docker-pier/pier.rb', line 40 def name @name end |
#ssh_uri ⇒ Object (readonly)
Returns the value of attribute ssh_uri.
43 44 45 |
# File 'lib/docker-pier/pier.rb', line 43 def ssh_uri @ssh_uri end |
Class Method Details
.current ⇒ Object
11 12 13 |
# File 'lib/docker-pier/pier.rb', line 11 def self.current @current ||= self.new(ENV['PIER']) end |
Instance Method Details
#bootstrap! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/docker-pier/pier.rb', line 79 def bootstrap! own_hostname = `hostname -f`.chomp remote_export_path = Pathname.new('/var/lib/private-x509/clients') + "#{own_hostname}.tar" self.ssh.exec!(" if [ ! -f '\#{remote_export_path}' ]; then\n /var/lib/private-x509/gen_bundle '\#{own_hostname}'\n fi\n EOF\n\n local_export_path = self.x509_dir + 'export.tar'\n\n self.x509_dir.mkpath\n Dir.chdir(self.x509_dir.to_s) do\n self.ssh.scp.download! remote_export_path.to_s, local_export_path.to_s\n system 'tar', '-x', '-f', local_export_path.to_s\n local_export_path.unlink\n end\nend\n") |
#docker ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/docker-pier/pier.rb', line 65 def docker @docker ||= Docker::Connection.new(self.resolved_docker_uri.to_s, scheme: "https", ssl_ca_file: (self.x509_dir + "ca.pem").to_s, client_cert: (self.x509_dir + "cert.pem").to_s, client_key: (self.x509_dir + "key.pem").to_s ) end |
#libvirt ⇒ Object
61 62 63 |
# File 'lib/docker-pier/pier.rb', line 61 def libvirt @libvirt ||= Fog::Compute.new(provider: "Libvirt", libvirt_uri: @libvirt_uri.to_s) end |
#logs ⇒ Object
105 106 107 |
# File 'lib/docker-pier/pier.rb', line 105 def logs DockerPier::LogStream.new(self) end |
#nodes ⇒ Object
100 101 102 103 |
# File 'lib/docker-pier/pier.rb', line 100 def nodes docker_nodes = Docker::Swarm::Node.all({}, self.docker) docker_nodes.map{ |d| DockerPier::Node.new(d, self) } end |
#resolved_docker_uri ⇒ Object
56 57 58 |
# File 'lib/docker-pier/pier.rb', line 56 def resolved_docker_uri @docker_uri.dup.tap{ |u| u.host = Resolv.getaddress(u.host) } end |
#ssh ⇒ Object
74 75 76 |
# File 'lib/docker-pier/pier.rb', line 74 def ssh @ssh ||= Net::SSH.start(@ssh_uri.hostname, @ssh_uri.user, password: @ssh_uri.password) end |
#ssh_connstring ⇒ Object
45 46 47 48 49 50 |
# File 'lib/docker-pier/pier.rb', line 45 def ssh_connstring host_part = @ssh_uri.hostname host_part = ("%s@%s" % [@ssh_uri.user, host_part]) if @ssh_uri.user host_part = ("-p %d %s" % [@ssh_uri.port, host_part]) if (@ssh_uri.port and @ssh_uri.port != 22) host_part end |
#x509_dir ⇒ Object
52 53 54 |
# File 'lib/docker-pier/pier.rb', line 52 def x509_dir Pathname.new(ENV['HOME']) + '.docker-pier' + 'x509' + @name end |