class Domain

Public Instance Methods

create(name) click to toggle source
   # File lib/cloudstack-cli/commands/domain.rb
30 def create(name)
31   create_domains([options.merge(name: name)])
32 end
create_domains(domains) click to toggle source
   # File lib/cloudstack-cli/commands/domain.rb
42 def create_domains(domains)
43   puts domains
44   domains.each do |domain|
45     say "Creating domain '#{domain['name']}'... "
46 
47     if dom = client.list_domains(name: domain["name"], listall: true).first
48       unless domain["parent_domain"] && dom['parentdomainname'] != domain["parent_domain"]
49         say "domain '#{domain["name"]}' already exists.", :yellow
50         next
51       end
52     end
53 
54     if domain["parent_domain"]
55       parent = client.list_domains(name: domain["parent_domain"], listall: true).first
56       unless parent
57         say "parent domain '#{domain["parent_domain"]}' of domain '#{domain["name"]}' not found.", :yellow
58         next
59       end
60       domain['parentdomain_id'] = parent['id']
61     end
62 
63     client.create_domain(domain) ? say("OK.", :green) : say("Failed.", :red)
64   end
65 end
delete(name) click to toggle source
   # File lib/cloudstack-cli/commands/domain.rb
36 def delete(name)
37   delete_domains([options.merge(name: name)])
38 end
delete_domains(domains) click to toggle source
   # File lib/cloudstack-cli/commands/domain.rb
67 def delete_domains(domains)
68   domains.each do |domain|
69     print "Deleting domain '#{domain['name']}'..."
70     if dom = client.list_domains(name: domain["name"], listall: true).first
71       if domain["parent_domain"] && dom['parentdomainname'] =! domain["parent_domain"]
72         say "domain '#{domain["name"]}' with same name found, but parent_domain '#{domain["parent_domain"]}' does not match.", :yellow
73         next
74       end
75       client.delete_domain(id: dom['id']) ? say(" OK.", :green) : say(" Failed.", :red)
76     else
77       say "domain '#{domain["name"]}' not found.", :yellow
78     end
79   end
80 end
list() click to toggle source
   # File lib/cloudstack-cli/commands/domain.rb
 6 def list
 7   domains = client.list_domains
 8   if domains.size < 1
 9     puts "No domains found."
10   else
11     case options[:format].to_sym
12     when :yaml
13       puts({domains: domains}.to_yaml)
14     when :json
15       puts JSON.pretty_generate(domains: domains)
16     else
17       table = [%w(Name Path)]
18       domains.each do |domain|
19         table << [domain['name'], domain['path']]
20       end
21       print_table table
22       say "Total number of domains: #{domains.size}"
23     end
24   end
25 end