lib/network.rb in forj-0.0.30 vs lib/network.rb in forj-0.0.31

- old
+ new

@@ -25,10 +25,29 @@ # # Network module # module Network + def get_or_create_network(name) + network = get_network(name) + if network == nil + network = create_network(name) + end + network + end + + def get_network(name) + begin + info = 'getting network %s' % [name] + Logging.info(info) + Connection.network.networks.all(:name => name)[0] + rescue => e + puts e.message + Logging.error(e.message) + end + end + def create_network(name) begin info = 'creating network %s' % [name] Logging.info(info) Connection.network.networks.create(:name => name) @@ -37,11 +56,23 @@ end end def delete_network(network_name) begin - network = Connection.network.networks.all(:name => network_name)[0] + network = get_network(network_name) Connection.network.networks.get(network.id).destroy + rescue => e + Logging.error(e.message) + end + end + + def get_or_create_subnet(network_id, name) + begin + subnet = get_subnet(name) + if subnet == nil + subnet = create_subnet(network_id, name) + end + subnet rescue => e Logging.error(e.message) end end