Class: PortRule
Instance Attribute Summary
#config
Instance Method Summary
collapse
exit_on_failure?
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #get_async_job_status, #print_options, #watch_jobs
Instance Method Details
#create(server_name) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/cloudstack-cli/commands/port_rule.rb', line 10
def create(server_name)
unless server = client.get_server(server_name)
error "Server #{server_name} not found."
exit 1
end
frontendip = nil
project = client.get_project(project)
options[:rules].each do |pf_rule|
ip = pf_rule.split(":")[0]
if ip != ''
ip_addr = client.get_public_ip_address(ip)
else
ip_addr = frontendip ||= client.associate_ip_address(
client.get_network(options[:network], project ? project["id"] : nil)["id"]
)
end
port = pf_rule.split(":")[1]
puts
say "Create port forwarding rule #{ip_addr["ipaddress"]}:#{port} for server #{server_name}.", :yellow
client.create_port_forwarding_rule(ip_addr["id"], port, 'TCP', port, server["id"])
puts
end
end
|
#list ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/cloudstack-cli/commands/port_rule.rb', line 36
def list
project_id = find_project['id'] if options[:project]
rules = client.list_port_forwarding_rules(ip_address_id=nil, project_id)
if rules.size < 1
puts "No rules found."
else
table = [["IP", "Server", "Public-Port", "Private-Port", "Protocol", "State"]]
rules.each do |rule|
table << [
rule['ipaddress'],
rule['virtualmachinename'],
print_ports(rule, 'public'),
print_ports(rule, 'private'),
rule['protocol'],
rule['state']
]
end
print_table table
end
end
|