Sha256: 46a164cdcb1c09e61e87ce58f5bcada73865747ddf13ece517cacf0542df548d

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require_relative '../grid_options'
require_relative 'services_helper'

module Kontena::Cli::Services
  class LinkCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include ServicesHelper

    parameter "NAME", "Service name"
    parameter "TARGET", "Link target service name"

    def execute
      require_api_url
      token = require_token
      target_service = target

      target_service = "null/#{target_service}" unless target_service.include?('/')

      service = client(token).get("services/#{parse_service_id(name)}")
      existing_targets = service['links'].map{ |l| l['id'].split('/', 2)[1] }
      if existing_targets.include?(target_service.to_s)
        exit_with_error("Service is already linked to #{target.to_s}")
      end
      links = service['links'].map{ |l|
        { name: l['id'].split('/', 2)[1], alias: l['alias'] }
      }
      links << {name: target_service.to_s, alias: target.to_s}
      links.compact!
      data = {links: links}
      spinner "Linking #{name.colorize(:cyan)} to #{target.colorize(:cyan)} " do
        update_service(token, name, data)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
kontena-cli-1.2.0.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.2.0.pre3 lib/kontena/cli/services/link_command.rb
kontena-cli-1.2.0.pre2 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.6 lib/kontena/cli/services/link_command.rb
kontena-cli-1.2.0.pre1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.5 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.4 lib/kontena/cli/services/link_command.rb
kontena-cli-1.2.0.dev1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.3 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.2 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.1 lib/kontena/cli/services/link_command.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/services/link_command.rb