Sha256: 8aef1af2d2deb2cef665cecb5ce9aa8d54c218b0a1a837d4cd71ac2019099197

Contents?: true

Size: 893 Bytes

Versions: 5

Compression:

Stored size: 893 Bytes

Contents

module SmartMachine
  class Machines
    class Network < SmartMachine::Base
      def initialize(name:)
        config = SmartMachine.config.network.dig(name.to_sym)
        raise "network config for #{name} not found." unless config

        @driver = config.dig(:driver)

        @name = name.to_s
        @home_dir = File.expand_path('~')
      end

      def uper
        raise "Error: Could not create network: #{@name}" unless system(command.compact.join(' '), out: File::NULL)

        puts "Created network: #{@name}"
      end

      def downer
        raise "Error: Could not remove network: #{@name}" unless system("docker network rm '#{@name}'", out: File::NULL)

        puts "Removed network: #{@name}"
      end

      private

      def command
        [
          'docker network create',
          "--driver=#{@driver}",
          @name
        ]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
smartmachine-1.3.0 lib/smart_machine/machines/network.rb
smartmachine-1.2.3 lib/smart_machine/machines/network.rb
smartmachine-1.2.1 lib/smart_machine/machines/network.rb
smartmachine-1.2.0 lib/smart_machine/machines/network.rb
smartmachine-1.2.0.dev lib/smart_machine/machines/network.rb