lib/cloudstack-cli/commands/ip_address.rb in cloudstack-cli-0.15.1 vs lib/cloudstack-cli/commands/ip_address.rb in cloudstack-cli-1.0.0.rc1
- old
+ new
@@ -1,39 +1,48 @@
class IpAddress < CloudstackCli::Base
- desc "release ID", "release public IP address"
- def release(id)
- say("OK", :green) if client.disassociate_ip_address(id)
+ desc "release ID [ID2 ID3]", "release public IP address by ID"
+ def release(*ids)
+ ids.each do |id|
+ say(" OK, released address with ID #{id}", :green) if client.disassociate_ip_address(id: id)
+ end
end
desc "ip_address assign NETWORK", "assign a public IP address"
option :project
def assign(network)
- project = find_project if options[:project]
- unless network = client.get_network(network, project ? project["id"] : nil)
- error "Network #{network} not found."
- exit 1
- end
- ip = client.associate_ip_address(network["id"])
- puts
- say ip['ipaddress']
+ resolve_project
+ options[:name] = network
+ unless network = client.list_networks(options).first
+ error "Network #{network} not found."
+ exit 1
+ end
+
+ if address = client.associate_ip_address(networkid: network["id"])
+ say " OK. Assigned IP address:", :green
+ table = [%w(ID Address Account Zone)]
+ table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
+ print_table table
+ end
end
desc "list", "list public IP address"
option :project
option :account
option :listall
def list
- table = [["Address", "Account", "Zone"]]
+ resolve_account
+ resolve_project
addresses = client.list_public_ip_addresses(options)
if addresses.size < 1
say "No ip addresses found."
else
+ table = [%w(ID Address Account Zone)]
addresses.each do |address|
- table << [address["ipaddress"], address["account"], address["zonename"]]
+ table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
end
print_table table
say "Total number of addresses: #{addresses.size}"
end
end
-end
\ No newline at end of file
+end