Sha256: 7a7c2f4c653225fa28a5aae64465ae77a90e08340b8be006852624f21704404d

Contents?: true

Size: 1.11 KB

Versions: 38

Compression:

Stored size: 1.11 KB

Contents

module Kontena::Cli::Volumes
  class CreateCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions

    banner "Creates a volume"
    parameter 'NAME', 'Volume name'

    SCOPES = %w(grid stack instance)

    option '--driver', 'DRIVER', 'Volume driver to be used', required: true
    option '--driver-opt', 'DRIVER_OPT', 'Volume driver options', multivalued: true
    option '--scope', 'SCOPE', "Volume scope (#{SCOPES.join(',')})", required: true do |scope|
      exit_with_error "Unknown scope '#{scope}, must be one of #{SCOPES.join(',')}" unless SCOPES.include?(scope)
      scope
    end

    requires_current_master
    requires_current_master_token

    def execute
      volume = {
        name: name,
        scope: scope,
        driver: driver,
        driver_opts: parse_driver_opts
      }
      spinner "Creating volume #{pastel.cyan(name)} " do
        create_volume(volume)
      end
    end

    def parse_driver_opts
      driver_opt_list.map{|opt| opt.split '='}.to_h
    end

    def create_volume(volume)
      client.post("volumes/#{current_grid}", volume)
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
kontena-cli-1.4.1 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.1.rc1 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.1.pre1 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.3.5 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.3.5.rc1 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.rc2 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.rc1 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre14 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre13 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre12 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre11 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre10 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre9 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre8 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre7 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre6 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre5 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre4 lib/kontena/cli/volumes/create_command.rb
kontena-cli-1.4.0.pre3 lib/kontena/cli/volumes/create_command.rb