Sha256: 5d523583bb895bcb3145767f9317bd946b98ef4ce14c6e149815b9092b18f07a

Contents?: true

Size: 941 Bytes

Versions: 10

Compression:

Stored size: 941 Bytes

Contents

module Brightbox
  desc 'Remove servers from a server group'
  arg_name 'grp-id [srv-id...]'
  command [:remove_servers] do |c|

    c.desc "Remove all servers from group"
    c.switch [:a, :all]

    c.action do |global_options, options, args|
      grp_id = args.shift
      raise "You must specify the server group and the server ids to remove" unless grp_id && grp_id[/^grp-/] && (!args.empty? || options[:a])

      sg = ServerGroup.find grp_id

      servers = if options[:a]
        sg.server_ids
      else
        Server.find_or_call(args) do |id|
          raise "Couldn't find server #{id}"
        end
      end

      if servers.empty?
        info "Server group #{sg} already contains zero servers"
      else
        info "Removing#{" all" if options[:a]} #{servers.size} servers from server group #{sg}"
        sg.remove_servers servers
      end

      sg.reload
      render_table([sg], global_options)
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
brightbox-cli-0.18.1 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.18.0 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.5 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.4 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.3 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.2 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.1 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.17.0 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.16.0 lib/brightbox-cli/commands/groups-remove-servers.rb
brightbox-cli-0.15.0 lib/brightbox-cli/commands/groups-remove-servers.rb