Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'or' logic doesn't allow 'None' which evaluates as False. #798

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addons:
- libxslt1-dev

install:
- if [ "$TRAVIS_PYTHON_VERSION" == "2.6" ]; then pip install importlib; fi
- if [ "$TRAVIS_PYTHON_VERSION" == "2.6" ]; then pip install importlib 'paramiko>=1.15.2,<2.0'; fi
- "pip install -r development.txt"
- "pip install -r requirements.txt"

Expand Down
12 changes: 8 additions & 4 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,14 @@ def __init__(self, *vargs, **kvargs):
self._ssh_config = kvargs.get('ssh_config')
self._sshconf_lkup()
# but if user or private key is explicit from call, then use it.
self._auth_user = kvargs.get('user') or self._conf_auth_user or \
self._auth_user
self._ssh_private_key_file = kvargs.get('ssh_private_key_file') \
or self._conf_ssh_private_key_file
if 'user' in kvargs:
self._auth_user = kvargs.get('user')
else:
self._auth_user = self._conf_auth_user or self._auth_user
if 'ssh_private_key_file' in kvargs:
self._ssh_private_key_file = kvargs.get('ssh_private_key_file')
else:
self._ssh_private_key_file = self._conf_ssh_private_key_file
self._auth_password = kvargs.get(
'password') or kvargs.get('passwd')

Expand Down
38 changes: 32 additions & 6 deletions lib/jnpr/junos/factory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
import glob
import json
import yaml
import os.path

from jnpr.junos.factory.factory_loader import FactoryLoader

__all__ = ['loadyaml', 'FactoryLoader']
__all__ = ['load', 'loadjson', 'loadyaml', 'FactoryLoader']


def loadyaml(path):
def load(path):
"""
Load a YAML file at :path: that contains Table and View definitions.
Load a file at :path: that contains Table and View definitions.
Returns a <dict> of item-name anditem-class definition.
Supports both json and yaml natively; prefers JSON.
In this way additional support can be added (csv, xml, etc)

If you want to import these definitions directly into your namespace,
(like a module) you would do the following:

globals().update( loadyaml( <path-to-yaml-file> ))
globals().update( load( <path-to-file> ))

If you did not want to do this, you can access the items as the <dict>.
For example, if your YAML file contained a Table called MyTable, then
For example, if your file contained a Table called MyTable, then
you could do something like:

catalog = loadyaml( <path-to-yaml-file> )
catalog = load( <path-to-file> )
MyTable = catalog['MyTable']

table = MyTable(dev)
table.get()
...
"""
ext = os.path.splitext(path)[1]
if ext == '':
# We don't have an ext, find it
candidates = glob.glob(path + '*')
for candy in candidates:
candy_ext = os.path.splitext(candy)[1]
if candy_ext == '.yml' or candy_ext = '.yaml':
return loadyaml(candy)
else:
return loadjson(candy)
elif ext == '.yml' or ext == '.yaml':
return loadyaml(path)
else:
return loadjson(path)

def loadyaml(path):
# if no extension is given, default to '.yml'
if os.path.splitext(path)[1] == '':
path += '.yml'
return FactoryLoader().load(yaml.load(open(path, 'r')))

def loadjson(path):
# if no extension is given, default to '.json'
if os.path.splitext(path)[1] == '':
path += '.json'
return FactoryLoader().load(json.load(open(path, 'r')))
18 changes: 18 additions & 0 deletions lib/jnpr/junos/op/arp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ArpView" : {
"fields" : {
"ip_address" : "ip-address",
"mac_address" : "mac-address",
"interface_name" : "interface-name"
}
},
"ArpTable" : {
"rpc" : "get-arp-table-information",
"item" : "arp-table-entry",
"key" : "mac-address",
"view" : "ArpView",
"args" : {
"no-resolve" : "True"
}
}
}
8 changes: 4 additions & 4 deletions lib/jnpr/junos/op/arp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Pythonifier for ARP Table/View
"""
from jnpr.junos.factory import loadyaml
from os.path import splitext
_YAML_ = splitext(__file__)[0] + '.yml'
globals().update(loadyaml(_YAML_))
import jnpr.junos.factory
import os
_PATH_ = os.path.splitext(__file__)[0]
globals().update(jnpr.junos.factory.load(_PATH_)
14 changes: 0 additions & 14 deletions lib/jnpr/junos/op/arp.yml

This file was deleted.

57 changes: 57 additions & 0 deletions lib/jnpr/junos/op/bfd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"BfdSessionTable" : {
"key" : "session-neighbor",
"rpc" : "get-bfd-session-information",
"args" : {
"extensive" : "True"
},
"item" : "bfd-session",
"view" : "BfdSessionView"
},
"_BfdSessionClientView" : {
"fields" : {
"name" : "client-name",
"reception_interval" : "client-reception-interval",
"transmission_interval" : "client-transmission-interval"
}
},
"_BfdSessionClientTable" : {
"view" : "_BfdSessionClientView",
"item" : "bfd-client"
},
"BfdSessionView" : {
"fields" : {
"bfd_client" : "_BfdSessionClientTable",
"detection_time" : "session-detection-time",
"remote_state" : "remote-state",
"local_diagnostic" : "local-diagnostic",
"no_absorb" : {
"no-absorb" : "True=regex(no-absorb)"
},
"neighbor_minimum_transmission_interval" : "neighbor-minimum-transmission_interval",
"remote_diagnostic" : "remote-diagnostic",
"state" : "session-state",
"neighbor_minimum_reception_interval" : "neighbor-minimum-reception_interval",
"neighbor" : "session-neighbor",
"minimum_reception_interval" : "minimum-reception-interval",
"minimum_asynchronous_interval" : "minimum-asynchronous-interval",
"adaptive_asynchronous_transmission_interval" : "adaptive-asynchronous-transmission_interval",
"echo_mode_state" : "echo-mode-state",
"detection_multiplier" : "detection-multiplier",
"minimum_transmission_interval" : "minimum-transmission-interval",
"no_refresh" : {
"no-refresh" : "True=no-refresh"
},
"echo_mode_desired" : "echo-mode-desired",
"remote_discriminator" : "remote-discriminator",
"adaptive_reception_interval" : "adaptive-reception-interval",
"version" : "session-version",
"adaptive_multiplier" : "session-adaptive-multiplier",
"local_discriminator" : "local-discriminator",
"transmission_interval" : "session-transmission-interval",
"neighbor_session_multiplier" : "neighbor-session-multiplier",
"interface" : "session-interface",
"minimum_slow_interval" : "minimum-slow-interval"
}
}
}
8 changes: 4 additions & 4 deletions lib/jnpr/junos/op/bfd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Pythonifier for BFD Table/View
"""
from jnpr.junos.factory import loadyaml
from os.path import splitext
_YAML_ = splitext(__file__)[0] + '.yml'
globals().update(loadyaml(_YAML_))
import jnpr.junos.factory
import os
_PATH_ = os.path.splitext(__file__)[0]
globals().update(jnpr.junos.factory.load(_PATH_)
47 changes: 0 additions & 47 deletions lib/jnpr/junos/op/bfd.yml

This file was deleted.

18 changes: 18 additions & 0 deletions lib/jnpr/junos/op/bgp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bgpTable" : {
"rpc" : "get-bgp-neighbor-information",
"item" : "bgp-peer",
"key" : "peer-id",
"view" : "bgpView"
},
"bgpView" : {
"fields" : {
"local_address" : "local-address",
"local_as" : "local-as",
"peer_id" : "peer-id",
"route_received" : "bgp-rib/received-prefix-count",
"peer_as" : "peer-as",
"local_id" : "local-id"
}
}
}
8 changes: 4 additions & 4 deletions lib/jnpr/junos/op/bgp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Pythonifier for BGP Table/View
"""
from jnpr.junos.factory import loadyaml
from os.path import splitext
_YAML_ = splitext(__file__)[0] + '.yml'
globals().update(loadyaml(_YAML_))
import jnpr.junos.factory
import os
_PATH_ = os.path.splitext(__file__)[0]
globals().update(jnpr.junos.factory.load(_PATH_)
15 changes: 0 additions & 15 deletions lib/jnpr/junos/op/bgp.yml

This file was deleted.

31 changes: 31 additions & 0 deletions lib/jnpr/junos/op/ccc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"_CCCPortsView" : {
"fields" : {
"status" : "ccc-circuit-status",
"type" : "ccc-circuit-type"
}
},
"CCCView" : {
"fields" : {
"ports" : "_CCCPorts",
"status" : "ccc-connection-status"
}
},
"CCCTable" : {
"key" : "ccc-connection-name",
"view" : "CCCView",
"args" : {
"status" : "True",
"interface-switch" : "True"
},
"item" : "ccc-connection",
"rpc" : "get-ccc-information"
},
"_CCCPorts" : {
"key" : [
"ccc-circuit-name"
],
"view" : "_CCCPortsView",
"item" : "ccc-connection-circuit"
}
}
8 changes: 4 additions & 4 deletions lib/jnpr/junos/op/ccc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Pythonifier for Circuit Cross Connect Table/View (ccc)
"""
from jnpr.junos.factory import loadyaml
from os.path import splitext
_YAML_ = splitext(__file__)[0] + '.yml'
globals().update(loadyaml(_YAML_))
import jnpr.junos.factory
import os
_PATH_ = os.path.splitext(__file__)[0]
globals().update(jnpr.junos.factory.load(_PATH_)
25 changes: 0 additions & 25 deletions lib/jnpr/junos/op/ccc.yml

This file was deleted.

Loading