Module: CloudstackClient::Network
- Defined in:
- lib/cloudstack_client/commands/network.rb
Instance Method Summary collapse
-
#delete_network(id) ⇒ Object
Delete network.
-
#get_default_network(zone = nil) ⇒ Object
Finds the default network.
-
#get_network(name, project_id = nil) ⇒ Object
Finds the network with the specified name.
-
#list_networks(args = {}) ⇒ Object
Lists all available networks.
-
#list_physical_networks ⇒ Object
Lists all physical networks.
-
#networkid_to_name(id, project_id = nil) ⇒ Object
Finds the network with the specified name.
-
#restart_network(id, cleanup = false) ⇒ Object
Restart network.
Instance Method Details
#delete_network(id) ⇒ Object
Delete network.
95 96 97 98 99 100 101 102 |
# File 'lib/cloudstack_client/commands/network.rb', line 95 def delete_network(id) params = { 'command' => 'deleteNetwork', 'id' => id, } p json = send_async_request(params) json['network'] end |
#get_default_network(zone = nil) ⇒ Object
Finds the default network.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cloudstack_client/commands/network.rb', line 44 def get_default_network(zone = nil) params = { 'command' => 'listNetworks', 'isDefault' => true } if zone params['zoneid'] = get_zone(zone)['id'] end json = send_request(params) networks = json['network'] return nil if !networks || networks.empty? return networks.first if networks.length == 1 networks.each { |n| if n['type'] == 'Direct' then return n end } nil end |
#get_network(name, project_id = nil) ⇒ Object
Finds the network with the specified name.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cloudstack_client/commands/network.rb', line 22 def get_network(name, project_id = nil) params = { 'command' => 'listNetworks', 'listall' => true } params['projectid'] = project_id if project_id json = send_request(params) networks = json['network'] return nil unless networks networks.each { |n| if n['name'] == name then return n end } nil end |
#list_networks(args = {}) ⇒ Object
Lists all available networks.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloudstack_client/commands/network.rb', line 69 def list_networks(args = {}) params = { 'command' => 'listNetworks' } params['listall'] = true unless args[:isdefault] params['isDefault'] = true if args[:isdefault] params['projectid'] = args[:project_id] if args[:project_id] params['zoneid'] = args[:zone_id] if args[:zone_id] if args[:account] domain = list_accounts(name: args[:account]) if domain.size > 0 params['account'] = args[:account] params['domainid'] = domain.first["domainid"] else puts "Account #{args[:account]} not found." end end json = send_request(params) json['network'] || [] end |
#list_physical_networks ⇒ Object
Lists all physical networks.
120 121 122 123 124 125 126 |
# File 'lib/cloudstack_client/commands/network.rb', line 120 def list_physical_networks params = { 'command' => 'listPhysicalNetworks', } json = send_request(params) json['physicalnetwork'] || [] end |
#networkid_to_name(id, project_id = nil) ⇒ Object
Finds the network with the specified name.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cloudstack_client/commands/network.rb', line 8 def networkid_to_name(id, project_id=nil) params = { 'command' => 'listNetworks', 'id' => id } params['projectid'] = project_id if project_id json = send_request(params) json['network'] ? json['network'].first['name'] : nil end |
#restart_network(id, cleanup = false) ⇒ Object
Restart network.
107 108 109 110 111 112 113 114 115 |
# File 'lib/cloudstack_client/commands/network.rb', line 107 def restart_network(id, cleanup = false) params = { 'command' => 'restartNetwork', 'id' => id, 'cleanup' => cleanup, } p json = send_async_request(params) json['network'] end |