Sha256: d3cf58fdaa3f749347a739da635851ee3170f21ebcdd95a01a9a9f294dc6c899

Contents?: true

Size: 949 Bytes

Versions: 34

Compression:

Stored size: 949 Bytes

Contents

module Kontena::Cli::Nodes::Labels
  class RemoveCommand < Kontena::Command
    include Kontena::Cli::Common

    parameter "NODE", "Node name"
    parameter "LABEL ...", "Labels"

    option '--force', :flag, "Do not abort if items in label list are not found"

    requires_current_master
    requires_current_master_token
    requires_current_grid

    def execute
      node_data = client.get("nodes/#{current_grid}/#{self.node}")

      node_data['labels'] ||= []

      found_labels = label_list.uniq & node_data['labels']

      if !force? && found_labels.size != label_list.uniq.size
        missing = label_list - found_labels
        exit_with_error "Label#{'s' if missing.size > 1} #{pastel.cyan(missing.join(', '))} not found on node #{pastel.cyan(node)}"
      end

      return nil if found_labels.empty?

      data = { labels: node_data['labels'] - found_labels }
      client.put("nodes/#{node_data['id']}", data)
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.10 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.9 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.8 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.7 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.6 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.5 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.4 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.3 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.2 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.1 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.7.0 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.9 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.8 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.7 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.6 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.5 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.4 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.3 lib/kontena/cli/nodes/labels/remove_command.rb
krates-1.6.2 lib/kontena/cli/nodes/labels/remove_command.rb