Skip to content

Commit

Permalink
Drop search-like behavior from show_network
Browse files Browse the repository at this point in the history
The historic output format was not suitable for IPv6 anyway.

Change-Id: I1babae914854bb2d999a9dc9e07e6af567f49374
Reviewed-by: Fred Barnes <Fred.Barnes@morganstanley.com>
  • Loading branch information
gombasg committed May 2, 2017
1 parent 1482885 commit fd08fd7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 100 deletions.
18 changes: 0 additions & 18 deletions etc/input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -759,30 +759,12 @@
<p/>
The 'csv' format contains the following fields, in this order:
Network name, IP, Netmask, Sysloc, Country code, Side, Type, Comments.
<p/>
Note that location searches are inclusive. That is, searching for a
building will include all racks, rooms, etc. inside the building. The
--exact_location option can be used to override this behavior.
<optgroup mandatory="True" fields="one">
<option name="network" type="string">Network name</option>
<option name="ip" type="ip">IP address</option>
<option name="all" type="flag">All</option>
<optgroup fields="one">
<option name="organization" type="string">Organization</option>
<option name="hub" type="string">Hub</option>
<option name="continent" type="string">Continent</option>
<option name="country" type="string">Country</option>
<option name="campus" type="string">Campus</option>
<option name="city" type="string">City</option>
<option name="building" type="string">Building</option>
<option name="room" type="string">Room</option>
<option name="bunker" type="string">Bunker</option>
<option name="rack" type="string">Rack</option>
<option name="desk" type="string">Desk</option>
</optgroup>
</optgroup>
<optgroup>
<option name="exact_location" type="flag">Match the location exactly</option>
<option name="network_environment" type="string">Network environment (default: internal)</option>
<option name="hosts" type="flag">Hosts</option>
</optgroup>
Expand Down
25 changes: 8 additions & 17 deletions lib/aquilon/worker/commands/show_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from aquilon.aqdb.model import Network, NetworkEnvironment
from aquilon.worker.broker import BrokerCommand
from aquilon.worker.dbwrappers.location import get_location
from aquilon.worker.dbwrappers.network import get_network_byname, get_network_byip
from aquilon.worker.formats.network import SimpleNetworkList
from aquilon.worker.formats.network import NetworkHostList


Expand All @@ -31,7 +29,7 @@ class CommandShowNetwork(BrokerCommand):
required_parameters = []

def render(self, session, network, ip, network_environment, all, hosts,
exact_location, **arguments):
**arguments):
options = [undefer('comments'),
joinedload('location'),
undefer('routers.comments'),
Expand All @@ -44,31 +42,24 @@ def render(self, session, network, ip, network_environment, all, hosts,
joinedload("assignments.interface"),
joinedload("assignments.interface.hardware_entity"),
joinedload("assignments.dns_records")])

dbnet_env = NetworkEnvironment.get_unique_or_default(session,
network_environment)
dbnetwork = network and get_network_byname(session, network, dbnet_env,
query_options=options) or None
dbnetwork = ip and get_network_byip(session, ip, dbnet_env,
query_options=options) or dbnetwork
if dbnetwork:

if network or ip:
dbnetwork = Network.get_unique(session, name=network, ip=ip,
network_environment=dbnet_env,
query_options=options, compel=True)
if hosts:
return NetworkHostList([dbnetwork])
else:
return dbnetwork

q = session.query(Network)
q = q.filter_by(network_environment=dbnet_env)

dblocation = get_location(session, **arguments)
if dblocation:
if exact_location:
q = q.filter_by(location=dblocation)
else:
childids = dblocation.offspring_ids()
q = q.filter(Network.location_id.in_(childids))
q = q.order_by(Network.ip)
q = q.options(*options)
if hosts:
return NetworkHostList(q.all())
else:
return SimpleNetworkList(q.all())
return q.all()
17 changes: 0 additions & 17 deletions lib/aquilon/worker/dbwrappers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@
from aquilon.aqdb.model import Network, AddressAssignment, ARecord


def get_network_byname(session, netname, environment, query_options=None):
try:
q = session.query(Network)
q = q.filter_by(network_environment=environment)
q = q.filter_by(name=netname)
if query_options:
q = q.options(*query_options)
dbnetwork = q.one()
except NoResultFound:
raise NotFoundException("Network %s not found." % netname)
# FIXME: network names should be unique
except MultipleResultsFound:
raise ArgumentError("There are multiple networks with name %s." %
netname)
return dbnetwork


def get_network_byip(session, ipaddr, environment, query_options=None):
try:
q = session.query(Network)
Expand Down
27 changes: 0 additions & 27 deletions lib/aquilon/worker/formats/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,30 +338,3 @@ def format_raw(self, objects, indent="", embedded=True, indirect_attrs=True):
for network in sorted(objects, key=attrgetter("ip")))

ObjectFormatter.handlers[NetworkList] = NetworkListFormatter()


class SimpleNetworkList(list):
"""By convention, holds a list of networks to be formatted in a simple
network map type format."""
pass


class SimpleNetworkListFormatter(NetworkListFormatter):
fields = ["Network", "IP", "Netmask", "Sysloc", "Country", "Side", "Network Type", "Discoverable", "Discovered", "Comments"]

def format_raw(self, nlist, indent="", embedded=True, indirect_attrs=True):
details = [indent + "\t".join(self.fields)]
for network in sorted(nlist, key=attrgetter("ip")):
details.append(indent + "\t".join([network.name,
str(network.ip),
str(network.netmask),
str(network.location.sysloc()),
str(network.location.country),
network.side,
network.network_type,
"False",
"False",
str(network.comments)]))
return "\n".join(details)

ObjectFormatter.handlers[SimpleNetworkList] = SimpleNetworkListFormatter()
22 changes: 11 additions & 11 deletions tests/broker/test_add_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def test_360_shownetworkcomments(self):
out = self.commandtest(command.split(" "))
self.matchoutput(out, "Comments: Some network comments", command)

def test_370_shownetworkbuilding(self):
command = "show_network --building ut"
def test_370_searchnetworkbuilding(self):
command = "search network --building ut"
out = self.commandtest(command.split(" "))
for network in self.net:
if not network.autocreate:
Expand All @@ -203,7 +203,7 @@ def test_370_shownetworkbuilding(self):
def test_380_shownetworkcsv(self):
# Use --exact_location here, so we don't have to worry about networks
# mapped to child locations
command = "show_network --building ut --exact_location --format csv"
command = "search_network --building ut --exact_location --format csv"
out = self.commandtest(command.split(" "))
for network in self.net:
if not network.autocreate:
Expand All @@ -216,8 +216,8 @@ def test_380_shownetworkcsv(self):
else:
self.matchclean(out, str(network.ip), command)

def test_390_shownetworkproto(self):
command = "show network --building ut --format proto"
def test_390_searchnetworkproto(self):
command = "search network --building ut --format proto"
self.protobuftest(command.split(" "))

def test_400_addlocalnet(self):
Expand All @@ -226,26 +226,26 @@ def test_400_addlocalnet(self):
"--building", "ut"]
self.noouttest(command)

def test_410_shownetworknoenv(self):
command = "show network --building np"
def test_410_searchnetworknoenv(self):
command = "search network --building np --fullinfo"
out = self.commandtest(command.split(" "))
self.matchclean(out, "excx-net", command)

command = "show network --building ut"
command = "search network --building ut --fullinfo"
out = self.commandtest(command.split(" "))
self.matchclean(out, "utcolo-net", command)
self.matchoutput(out, "netsvcmap", command)
self.matchoutput(out, "netperssvcmap", command)

def test_420_shownetworkwithenv(self):
command = "show network --building np --network_environment excx"
def test_420_searchnetworkwithenv(self):
command = "search network --building np --network_environment excx --fullinfo"
out = self.commandtest(command.split(" "))
self.matchoutput(out, "excx-net", command)

def test_430_showexcxnoenv(self):
command = "show network --network excx-net"
out = self.notfoundtest(command.split(" "))
self.matchoutput(out, "Network excx-net not found.", command)
self.matchoutput(out, "Network excx-net, network environment internal not found.", command)

def test_440_showexcxwithenv(self):
net = self.net["unknown0"]
Expand Down
16 changes: 6 additions & 10 deletions tests/broker/test_del_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ def test_240_shownetworkall(self):
command = "show network --ip %s --hosts" % network.ip
self.notfoundtest(command.split(" "))

def test_230_shownetwork(self):
command = "show network --building ut"
out = self.commandtest(command.split(" "))
# Unfortunately this command prints a header even if the output is
# otherwise empty. Check for a dot, as that will match any IP addresses,
# but not the header.
self.matchclean(out, ".", command)

def test_250_shownetworkproto(self):
command = "show network --building ut --format proto"
def test_230_searchnetwork(self):
command = "search network --building ut"
out = self.noouttest(command.split(" "))

def test_250_searchnetworkproto(self):
command = "search network --building ut --format proto"
self.protobuftest(command.split(" "), expect=0)

def test_210_delnetworkcards(self):
Expand Down

0 comments on commit fd08fd7

Please sign in to comment.