Class: PortRule
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- PortRule
- Defined in:
- lib/cloudstack-cli/commands/port_rule.rb
Constant Summary
Constants included from CloudstackCli::Helper
CloudstackCli::Helper::ASYNC_STATES
Instance Attribute Summary
Attributes inherited from CloudstackCli::Base
Instance Method Summary collapse
Methods inherited from CloudstackCli::Base
Methods included from CloudstackCli::Helper
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #print_job_status, #print_options, #update_job_status, #watch_jobs
Instance Method Details
#create(server_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudstack-cli/commands/port_rule.rb', line 11 def create(server_name) projectid = find_project['id'] if [:project] unless server = client.get_server(server_name, projectid) error "Server #{server_name} not found." exit 1 end frontendip = nil [:rules].each do |pf_rule| ip = pf_rule.split(":")[0] if ip != '' ip_addr = client.get_public_ip_address(ip, projectid) unless ip_addr say "Error: IP #{ip} not found.", :red next end else ip_addr = frontendip ||= client.associate_ip_address( client.get_network([:network], projectid) ) 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cloudstack-cli/commands/port_rule.rb', line 41 def list project_id = find_project['id'] if [: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 say "Total number of rules: #{rules.count}" end end |