Sha256: d5cba48153104042a0f139629df24ea097b2830934a94f54e10c15bcea54ab7a

Contents?: true

Size: 1.85 KB

Versions: 18

Compression:

Stored size: 1.85 KB

Contents

class Project < CloudstackCli::Base

  desc "show NAME", "show detailed infos about a project"
  def show(name)
    unless project = client.list_projects(name: name, listall: true).first
      say "Error: No project with name '#{name}' found.", :red
    else
      table = project.map do |key, value|
        [ set_color("#{key}", :yellow), "#{value}" ]
      end
      print_table table
    end
  end

  desc "list", "list projects"
  option :domain, desc: "List only resources belonging to the domain specified"
  def list
    resolve_domain
    projects = client.list_projects(options.merge listall: true)
    if projects.size < 1
      puts "No projects found."
    else
      table = [%w(Name Displaytext VMs CPU Memory Domain)]
      projects.each do |project|
        table << [
          project['name'],
          project['displaytext'],
          project['vmtotal'],
          project['cputotal'],
          project['memorytotal'] / 1024,
          project['domain']
        ]
      end
      print_table(table)
      say "Total number of projects: #{projects.count}"
    end
  end

  desc "list_accounts PROJECT_NAME", "show accounts belonging to a project"
  def list_accounts(name)
    unless project = client.list_projects(name: name, listall: true).first
      say "Error: No project with name '#{name}' found.", :red
    else
      accounts = client.list_project_accounts(project_id: project['id'])
      if accounts.size < 1
        say "No project accounts found."
      else
        table = [%w(Account-Name Account-Type Role Domain)]
        accounts.each do |account|
          table << [
            account['account'],
            Account::TYPES[account['accounttype']],
            account['role'],
            account['domain']
          ]
        end
        print_table table
        say "Total number of project accounts: #{accounts.size}"
      end
    end
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cloudstack-cli-1.4.1 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.4.0 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.3.3 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.3.2 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.3.1 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.3.0 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.7 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.6 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.5 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.4 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.3 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.1 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.2.0 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.1.0 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.0.8 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.0.7 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.0.6 lib/cloudstack-cli/commands/project.rb
cloudstack-cli-1.0.5 lib/cloudstack-cli/commands/project.rb