schema constants: Update the constant list

Add new content and refactor a bit the constants.

Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
Edward Haas 2019-02-20 16:36:40 +02:00 committed by Gris Ge
parent 6f9b4801cf
commit a2f08a9db2
2 changed files with 27 additions and 3 deletions

View File

@ -30,6 +30,7 @@ from libnmstate.appliers import linux_bridge
from libnmstate.nm import nmclient
from libnmstate.prettystate import format_desired_current_state_diff
from libnmstate.schema import Constants
from libnmstate.schema import InterfaceType
class ApplyError(Exception):
@ -405,7 +406,7 @@ def _remove_down_virt_iface_entries(ifaces_desired_state):
for ifname, ifstate in six.viewitems(ifaces_desired_state):
is_virt_down = (
ifstate.get('state') == 'down' and
ifstate.get('type') in Constants.VIRT_IFACE_TYPES
ifstate.get('type') in InterfaceType.VIRT_TYPES
)
if not is_virt_down:
ifaces[ifname] = ifstate

View File

@ -28,8 +28,31 @@ def load(schema_name):
ifaces_schema = load('operational-state')
class Interface(object):
KEY = 'interfaces'
NAME = 'name'
TYPE = 'type'
STATE = 'state'
IPV4 = 'ipv4'
IPV6 = 'ipv6'
class Constants(object):
INTERFACES = 'interfaces'
INTERFACES = Interface.KEY
class InterfaceState(object):
KEY = Interface.STATE
DOWN = 'down'
UP = 'up'
ABSENT = 'absent'
class InterfaceType(object):
KEY = Interface.TYPE
BOND = 'bond'
LINUX_BRIDGE = 'linux-bridge'
@ -38,7 +61,7 @@ class Constants(object):
OVS_INTERFACE = 'ovs-interface'
VLAN = 'vlan'
VIRT_IFACE_TYPES = (
VIRT_TYPES = (
BOND,
LINUX_BRIDGE,
OVS_BRIDGE,