Class: PI::Cli::Command::Dns
Instance Method Summary
collapse
#check_status, #choose_app, #choose_project
Methods inherited from Base
#auth_token, #client, #initialize, #target_url
Instance Method Details
#app_dns(appname = nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/cli/commands/dns.rb', line 27
def app_dns(appname=nil)
unless appname
useproject = choose_project
projectid = useproject[:id]
useapp = choose_app(projectid)
appname = useapp[:name]
end
dns = client.app_dns(appname)
return display JSON.pretty_generate(dns) if @options[:json]
return display "No DNS!" if dns.nil? || dns.empty?
dns_table = table do |t|
t.headings = 'Mapped DNS Name'
dns.each do |s|
t << s
end
end
display dns_table
end
|
#map_dns(appname = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/cli/commands/dns.rb', line 46
def map_dns(appname=nil)
unless appname
useproject = choose_project
projectid = useproject[:id]
useapp = choose_app(projectid)
appname = useapp[:name]
end
app = client.app_get_byname(appname)
err "The application is not found! App name :#{appname}" unless (appname == app[:name] ? true : false)
dns = client.usable_dns(appname)
err "No usable dns!" if dns.nil? || dns.empty?
choices = Array.new
dns.each do |s|
choices << s[:name]
end
manifest = ask "Select dns, indexed list?", :choices => choices, :indexed => true
manifest = manifest.to_a
display "Selected dns: ",false
display "#{manifest}"
display "Mapping dns: ",false
t = Thread.new do
loop do
display '.', false
sleep (1)
break unless t.alive?
end
end
client.map_dns(appname,manifest)
Thread.kill(t)
display "OK".green
end
|
#unmap_dns(appname = nil) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/cli/commands/dns.rb', line 81
def unmap_dns(appname=nil)
unless appname
useproject = choose_project
projectid = useproject[:id]
useapp = choose_app(projectid)
appname = useapp[:name]
end
app = client.app_get_byname(appname)
err "The application is not found! App name :#{appname}" unless (appname == app[:name] ? true : false)
dns = client.app_dns(appname)
err "No mapped dns!" if dns.nil? || dns.empty?
usedns = nil
choose do ||
display "=============DNS============"
.prompt = "Select DNS: "
.select_by = :index_or_name
dns.each do |d|
.choice("#{d}") { usedns = d }
end
end
display "Selected DNS: ",false
display "#{usedns}"
manifest = [usedns]
display "Unmapping dns: ",false
t = Thread.new do
loop do
display '.', false
sleep (1)
break unless t.alive?
end
end
client.unmap_dns(appname,manifest)
Thread.kill(t)
display "OK".green
end
|
#usable_dns(appname = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/cli/commands/dns.rb', line 7
def usable_dns(appname=nil)
unless appname
useproject = choose_project
projectid = useproject[:id]
useapp = choose_app(projectid)
appname = useapp[:name]
end
dns = client.usable_dns(appname)
return display JSON.pretty_generate(dns) if @options[:json]
return display "No Dns" if dns.nil? || dns.empty?
dns.sort! {|a, b| a[:name] <=> b[:name] }
dns_table = table do |t|
t.headings = 'Name'
dns.each do |s|
t << [s[:name]]
end
end
display dns_table
end
|