Sha256: d5e52c011b16f9ac71a569e44cae8624a0f6c792140d7120c7e42a47a0e6e82c

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'singleton'
require 'fileutils'
require 'shellwords'
require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0)

module Specinfra
  module Backend
    # LXD transport
    class Lxd < Exec
      def build_command(cmd)
        lxc_cmd = %W[lxc exec #{instance}]
        lxc_cmd << '-t' if get_config(:interactive_shell)
        lxc_cmd << '--'
        (lxc_cmd << super(cmd)).join(' ')
      end

      def send_file(source, destination)
        flags = %w[--create-dirs]
        if File.directory?(source)
          flags << '--recursive'
          destination = Pathname.new(destination).dirname.to_s
        end
        cmd = %W[lxc file push #{source} #{instance}#{destination}] + flags
        spawn_command(cmd.join(' '))
      end

      private

      def instance
        raise 'Please specify lxd_instance' unless (instance = get_config(:lxd_instance))
        raise 'Please specify lxd_remote' unless (remote = get_config(:lxd_remote))

        [remote, instance].compact.join(':')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/backend/lxd.rb
specinfra-2.90.1 lib/specinfra/backend/lxd.rb
specinfra-2.90.0 lib/specinfra/backend/lxd.rb
specinfra-2.89.0 lib/specinfra/backend/lxd.rb
specinfra-2.88.2 lib/specinfra/backend/lxd.rb
specinfra-2.88.1 lib/specinfra/backend/lxd.rb