cli: Support --network link_state=up|down

This commit is contained in:
Cole Robinson 2015-11-18 13:59:15 -05:00
parent 35792f7dd6
commit e9d5347395
4 changed files with 34 additions and 14 deletions

View File

@ -165,6 +165,7 @@
<source portgroup="foo"/>
<mac address="12:34:56:78:11:22"/>
<model type="virtio"/>
<link state="down"/>
</interface>
<interface type="bridge">
<source bridge="foobar"/>
@ -179,6 +180,7 @@
<virtualport type="openvswitch">
<parameters profileid="demo" interfaceid="09b11c53-8b5c-4eeb-8f00-d84eaa0aaa3b"/>
</virtualport>
<link state="up"/>
</interface>
<interface type="direct">
<source dev="eth5" mode="vepa"/>

View File

@ -461,9 +461,9 @@ c.add_compare(""" \
--disk vol=gluster-pool/test-gluster.raw,startup_policy=optional \
--disk %(DIR)s,device=floppy \
\
--network user,mac=12:34:56:78:11:22,portgroup=foo \
--network user,mac=12:34:56:78:11:22,portgroup=foo,link_state=down \
--network bridge=foobar,model=virtio,driver_name=qemu,driver_queues=3 \
--network bridge=ovsbr,virtualport_type=openvswitch,virtualport_profileid=demo,virtualport_interfaceid=09b11c53-8b5c-4eeb-8f00-d84eaa0aaa3b \
--network bridge=ovsbr,virtualport_type=openvswitch,virtualport_profileid=demo,virtualport_interfaceid=09b11c53-8b5c-4eeb-8f00-d84eaa0aaa3b,link_state=yes \
--network type=direct,source=eth5,source_mode=vepa,target=mytap12,virtualport_type=802.1Qbg,virtualport_managerid=12,virtualport_typeid=1193046,virtualport_typeidversion=1,virtualport_instanceid=09b11c53-8b5c-4eeb-8f00-d84eaa0aaa3b,boot_order=1 \
\
--graphics sdl \

View File

@ -738,22 +738,23 @@ def add_disk_option(stog, editexample=False):
# (for options like --disk, --network, etc. #
#############################################
def _raw_on_off_convert(s):
tvalues = ["y", "yes", "1", "true", "t", "on"]
fvalues = ["n", "no", "0", "false", "f", "off"]
s = (s or "").lower()
if s in tvalues:
return True
elif s in fvalues:
return False
return None
def _on_off_convert(key, val):
if val is None:
return None
def _yes_no_convert(s):
tvalues = ["y", "yes", "1", "true", "t", "on"]
fvalues = ["n", "no", "0", "false", "f", "off"]
s = (s or "").lower()
if s in tvalues:
return True
elif s in fvalues:
return False
return None
val = _yes_no_convert(val)
val = _raw_on_off_convert(val)
if val is not None:
return val
raise fail(_("%(key)s must be 'yes' or 'no'") % {"key": key})
@ -1770,6 +1771,21 @@ class ParserNetwork(VirtCLIParser):
else:
inst.type = val
def set_link_state(opts, inst, cliname, val):
ignore = opts
ignore = cliname
if val in ["up", "down"]:
inst.link_state = val
return
ret = _raw_on_off_convert(val)
if ret is True:
val = "up"
elif ret is False:
val = "down"
inst.link_state = val
self.set_param("type", "type", setter_cb=set_type_cb)
self.set_param("source", "source")
self.set_param("source_mode", "source_mode")
@ -1779,6 +1795,7 @@ class ParserNetwork(VirtCLIParser):
self.set_param("macaddr", "mac", setter_cb=set_mac_cb)
self.set_param("filterref", "filterref")
self.set_param("boot.order", "boot_order")
self.set_param("link_state", "link_state", setter_cb=set_link_state)
self.set_param("driver_name", "driver_name")
self.set_param("driver_queues", "driver_queues")

View File

@ -232,6 +232,7 @@ class VirtualNetworkInterface(VirtualDevice):
model = XMLProperty("./model/@type")
target_dev = XMLProperty("./target/@dev")
filterref = XMLProperty("./filterref/@filter")
link_state = XMLProperty("./link/@state")
driver_name = XMLProperty("./driver/@name")
driver_queues = XMLProperty("./driver/@queues", is_int=True)