lib/cloudstack-cli/commands/port_rule.rb in cloudstack-cli-1.5.9 vs lib/cloudstack-cli/commands/port_rule.rb in cloudstack-cli-1.5.10

- old
+ new

@@ -8,32 +8,32 @@ option :network, required: true, aliases: '-n' option :project option :keyword, desc: "list by keyword" def create(server_name) resolve_project - unless server = client.list_virtual_machines(name: server_name, project_id: options[:project_id]).first + unless server = client.list_virtual_machines( + name: server_name, project_id: options[:project_id], listall: true + ).find {|vm| vm["name"] == server_name } error "Server #{server_name} not found." exit 1 end + ip_addr = nil options[:rules].each do |pf_rule| ip = pf_rule.split(":")[0] unless ip == '' unless ip_addr = client.list_public_ip_addresses(ipaddress: ip, project_id: options[:project_id]).first say "Error: IP #{ip} not found.", :yellow next end else say "Assign a new IP address ", :yellow - say(" OK", :green) if ip_addr = client.associate_ip_address( - networkid: client.list_networks( - project_id: options[:project_id] - ).find {|n| n['name'] == options[:network]}['id'], - project_id: options[:project_id] - ) + net_id = client.list_networks(project_id: options[:project_id]).find {|n| n['name'] == options[:network]}['id'] + say(" OK", :green) if ip_addr = client.associate_ip_address(networkid: net_id)["ipaddress"] end port = pf_rule.split(":")[1] say "Create port forwarding rule #{ip_addr["ipaddress"]}:#{port} for server #{server_name} ", :yellow - say(" OK.", :green) if client.create_port_forwarding_rule( + + say(" OK", :green) if client.create_port_forwarding_rule( ipaddress_id: ip_addr["id"], public_port: port, private_port: port, virtualmachine_id: server["id"], protocol: "TCP"