Sha256: 784485cf855b4821c4df739af82a9d843f6e38a4f30bd79a45ff503e77d2e87c

Contents?: true

Size: 1012 Bytes

Versions: 4

Compression:

Stored size: 1012 Bytes

Contents

module Brightbox
  command [:cloudips] do |cmd|

    cmd.desc "destroy Cloud IPs"
    cmd.arg_name "[cloudip-id...]"
    cmd.command [:destroy] do |c|

      c.desc "Unmap mapped IPs before destroying them"
      c.switch [:u, "unmap"], :negatable => false

      c.action do |global_options, options, args|

        if args.empty?
          raise "You must specify the Cloud IPs you want to destroy"
        end

        ips = CloudIP.find_or_call(args) do |id|
          raise "Couldn't find Cloud IP #{id}"
        end

        ips.each do |ip|

          if ip.mapped?
            if options[:u]
              info "Unmapping Cloud IP #{ip}"
              ip.unmap
              3.times do
                break unless ip.mapped?
                sleep 1
                ip.reload
              end
            else
              raise "Cannot destroy mapped Cloud IP #{ip}"
            end
          end
          info "Destroying Cloud IP #{ip}"
          ip.destroy
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brightbox-cli-1.1.0 lib/brightbox-cli/commands/cloudips-destroy.rb
brightbox-cli-1.0.0 lib/brightbox-cli/commands/cloudips-destroy.rb
brightbox-cli-1.0.0.rc2 lib/brightbox-cli/commands/cloudips-destroy.rb
brightbox-cli-1.0.0.rc1 lib/brightbox-cli/commands/cloudips-destroy.rb