Sha256: cbd626d2cd600628719228e0e6cd46d095ededeffbb9270d7138fc6b0b9689f1

Contents?: true

Size: 1.33 KB

Versions: 13

Compression:

Stored size: 1.33 KB

Contents

class Account < CloudstackCli::Base

  TYPES = {
    0 => 'user',
    1 => 'domain-admin',
    2 => 'admin'
  }

  desc "show NAME", "show detailed infos about an account"
  def show(name)
    unless account = client.list_accounts(name: name, listall: true).first
      say "No account named \"#{name}\" found.", :red
    else
      account.delete 'user'
      account['accounttype'] = "#{account['accounttype']} (#{TYPES[account['accounttype']]})"
      table = account.map do |key, value|
        [ set_color("#{key}", :yellow), "#{value}" ]
      end
      print_table table
    end
  end

  desc "list", "list accounts"
  option :format, default: "table",
    enum: %w(table json yaml)
  def list
    accounts = client.list_accounts(listall: true)
    if accounts.size < 1
      puts "No accounts found."
    else
      case options[:format].to_sym
      when :yaml
        puts({accounts: accounts}.to_yaml)
      when :json
        puts JSON.pretty_generate(accounts: accounts)
      else
        table = [%w(Name Type Domain State)]
        accounts.each do |account|
          table << [
            account['name'],
            TYPES[account['accounttype']],
            account['domain'],
            account['state']
          ]
        end
        print_table table
        say "Total number of accounts: #{accounts.size}"
      end
    end
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cloudstack-cli-1.6.10 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.9 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.8 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.7 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.6 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.5 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.4 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.3 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.2 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.1 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.6.0 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.5.13 lib/cloudstack-cli/commands/account.rb
cloudstack-cli-1.5.12 lib/cloudstack-cli/commands/account.rb