1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Keywords to manipulate interface configuration using Honeycomb REST API.
16 The keywords make possible to put and get configuration data and to get
20 from resources.libraries.python.HTTPRequest import HTTPCodes
21 from resources.libraries.python.honeycomb.HoneycombSetup import HoneycombError
22 from resources.libraries.python.honeycomb.HoneycombUtil \
23 import DataRepresentation
24 from resources.libraries.python.honeycomb.HoneycombUtil \
25 import HoneycombUtil as HcUtil
28 # pylint: disable=too-many-public-methods
29 # pylint: disable=too-many-lines
30 class InterfaceKeywords(object):
31 """Keywords for Interface manipulation.
33 Implements keywords which get configuration and operational data about
34 vpp interfaces and set the interface's parameters using Honeycomb REST API.
37 INTF_PARAMS = ("name", "description", "type", "enabled",
38 "link-up-down-trap-enable", "v3po:l2")
39 IPV4_PARAMS = ("enabled", "forwarding", "mtu")
40 IPV6_PARAMS = ("enabled", "forwarding", "mtu", "dup-addr-detect-transmits")
41 IPV6_AUTOCONF_PARAMS = ("create-global-addresses",
42 "create-temporary-addresses",
43 "temporary-valid-lifetime",
44 "temporary-preferred-lifetime")
45 ETH_PARAMS = ("mtu", )
46 ROUTING_PARAMS = ("vrf-id", )
47 VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id")
48 L2_PARAMS = ("bridge-domain", "split-horizon-group",
49 "bridged-virtual-interface")
50 L2_REWRITE_TAG_PARAMS = ("rewrite-operation",
54 TAP_PARAMS = ("tap-name", "mac", "device-instance")
55 VHOST_USER_PARAMS = ("socket", "role")
56 SUB_INTF_PARAMS = ("super-interface",
71 def _configure_interface(node, interface, data,
72 data_representation=DataRepresentation.JSON):
73 """Send interface configuration data and check the response.
75 :param node: Honeycomb node.
76 :param interface: The name of interface.
77 :param data: Configuration data to be sent in PUT request.
78 :param data_representation: How the data is represented.
82 :type data_representation: DataRepresentation
83 :return: Content of response.
85 :raises HoneycombError: If the status code in response on PUT is not
89 status_code, resp = HcUtil.\
90 put_honeycomb_data(node, "config_vpp_interfaces", data,
91 data_representation=data_representation)
92 if status_code != HTTPCodes.OK:
94 "The configuration of interface '{0}' was not successful. "
95 "Status code: {1}.".format(interface, status_code))
99 def get_all_interfaces_cfg_data(node):
100 """Get configuration data about all interfaces from Honeycomb.
102 :param node: Honeycomb node.
104 :return: Configuration data about all interfaces from Honeycomb.
106 :raises HoneycombError: If it is not possible to get configuration data.
109 status_code, resp = HcUtil.\
110 get_honeycomb_data(node, "config_vpp_interfaces")
111 if status_code != HTTPCodes.OK:
112 raise HoneycombError(
113 "Not possible to get configuration information about the "
114 "interfaces. Status code: {0}.".format(status_code))
116 return resp["interfaces"]["interface"]
118 except (KeyError, TypeError):
122 def get_interface_cfg_data(node, interface):
123 """Get configuration data about the given interface from Honeycomb.
125 :param node: Honeycomb node.
126 :param interface: The name of interface.
129 :return: Configuration data about the given interface from Honeycomb.
133 intfs = InterfaceKeywords.get_all_interfaces_cfg_data(node)
135 if intf["name"] == interface:
140 def get_all_interfaces_oper_data(node):
141 """Get operational data about all interfaces from Honeycomb.
143 :param node: Honeycomb node.
145 :return: Operational data about all interfaces from Honeycomb.
147 :raises HoneycombError: If it is not possible to get operational data.
150 status_code, resp = HcUtil.\
151 get_honeycomb_data(node, "oper_vpp_interfaces")
152 if status_code != HTTPCodes.OK:
153 raise HoneycombError(
154 "Not possible to get operational information about the "
155 "interfaces. Status code: {0}.".format(status_code))
157 return resp["interfaces-state"]["interface"]
159 except (KeyError, TypeError):
163 def get_interface_oper_data(node, interface):
164 """Get operational data about the given interface from Honeycomb.
166 :param node: Honeycomb node.
167 :param interface: The name of interface.
170 :return: Operational data about the given interface from Honeycomb.
174 intfs = InterfaceKeywords.get_all_interfaces_oper_data(node)
176 if intf["name"] == interface:
181 def _set_interface_properties(node, interface, path, new_value=None):
182 """Set interface properties.
184 This method reads interface configuration data, creates, changes or
185 removes the requested data and puts it back to Honeycomb.
187 :param node: Honeycomb node.
188 :param interface: The name of interface.
189 :param path: Path to data we want to change / create / remove.
190 :param new_value: The new value to be set. If None, the item will be
195 :type new_value: str, dict or list
196 :return: Content of response.
198 :raises HoneycombError: If it is not possible to get or set the data.
201 status_code, resp = HcUtil.\
202 get_honeycomb_data(node, "config_vpp_interfaces")
203 if status_code != HTTPCodes.OK:
204 raise HoneycombError(
205 "Not possible to get configuration information about the "
206 "interfaces. Status code: {0}.".format(status_code))
209 new_data = HcUtil.set_item_value(resp, path, new_value)
211 new_data = HcUtil.remove_item(resp, path)
212 return InterfaceKeywords._configure_interface(node, interface, new_data)
215 def set_interface_state(node, interface, state="up"):
216 """Set VPP interface state.
218 The keyword changes the administration state of interface to up or down
219 depending on the parameter "state".
221 :param node: Honeycomb node.
222 :param interface: The name of interface.
223 :param state: The requested state, only "up" and "down" are valid
228 :return: Content of response.
230 :raises KeyError: If the argument "state" is nor "up" or "down".
231 :raises HoneycombError: If the interface is not present on the node.
234 intf_state = {"up": "true",
237 path = ("interfaces", ("interface", "name", str(interface)), "enabled")
238 return InterfaceKeywords._set_interface_properties(
239 node, interface, path, intf_state[state.lower()])
242 def set_interface_up(node, interface):
243 """Set the administration state of VPP interface to up.
245 :param node: Honeycomb node.
246 :param interface: The name of interface.
249 :return: Content of response
253 return InterfaceKeywords.set_interface_state(node, interface, "up")
256 def set_interface_down(node, interface):
257 """Set the administration state of VPP interface to down.
259 :param node: Honeycomb node.
260 :param interface: The name of interface.
263 :return: Content of response.
267 return InterfaceKeywords.set_interface_state(node, interface, "down")
270 def add_bridge_domain_to_interface(node, interface, bd_name,
271 split_horizon_group=None, bvi=None):
272 """Add a new bridge domain to an interface and set its parameters.
274 :param node: Honeycomb node.
275 :param interface: The name of interface.
276 :param bd_name: Bridge domain name.
277 :param split_horizon_group: Split-horizon group name.
278 :param bvi: The bridged virtual interface.
282 :type split_horizon_group: str
284 :return: Content of response.
286 :raises HoneycombError: If the interface is not present on the node.
289 v3po_l2 = {"bridge-domain": str(bd_name)}
290 if split_horizon_group:
291 v3po_l2["split-horizon-group"] = str(split_horizon_group)
293 v3po_l2["bridged-virtual-interface"] = str(bvi)
295 path = ("interfaces", ("interface", "name", str(interface)), "v3po:l2")
297 return InterfaceKeywords._set_interface_properties(
298 node, interface, path, v3po_l2)
301 def configure_interface_base(node, interface, param, value):
302 """Configure the base parameters of interface.
304 :param node: Honeycomb node.
305 :param interface: The name of interface.
306 :param param: Parameter to configure (set, change, remove)
307 :param value: The value of parameter. If None, the parameter will be
313 :return: Content of response.
315 :raises HoneycombError: If the parameter is not valid.
318 if param not in InterfaceKeywords.INTF_PARAMS:
319 raise HoneycombError("The parameter {0} is invalid.".format(param))
321 path = ("interfaces", ("interface", "name", interface), param)
322 return InterfaceKeywords._set_interface_properties(
323 node, interface, path, value)
326 def configure_interface_ipv4(node, interface, param, value):
327 """Configure IPv4 parameters of interface
329 :param node: Honeycomb node.
330 :param interface: The name of interface.
331 :param param: Parameter to configure (set, change, remove)
332 :param value: The value of parameter. If None, the parameter will be
338 :return: Content of response.
340 :raises HoneycombError: If the parameter is not valid.
343 if param not in InterfaceKeywords.IPV4_PARAMS:
344 raise HoneycombError("The parameter {0} is invalid.".format(param))
346 path = ("interfaces", ("interface", "name", interface),
347 "ietf-ip:ipv4", param)
348 return InterfaceKeywords._set_interface_properties(
349 node, interface, path, value)
352 def add_first_ipv4_address(node, interface, ip_addr, network):
353 """Add the first IPv4 address.
355 If there are any other addresses configured, they will be removed.
357 :param node: Honeycomb node.
358 :param interface: The name of interface.
359 :param ip_addr: IPv4 address to be set.
360 :param network: Netmask or length of network prefix.
364 :type network: str or int
365 :return: Content of response.
369 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
370 if isinstance(network, basestring):
371 address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
372 elif isinstance(network, int) and (0 < network < 33):
373 address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
375 raise HoneycombError("Value {0} is not a valid netmask or network "
376 "prefix length.".format(network))
377 return InterfaceKeywords._set_interface_properties(
378 node, interface, path, address)
381 def add_ipv4_address(node, interface, ip_addr, network):
384 :param node: Honeycomb node.
385 :param interface: The name of interface.
386 :param ip_addr: IPv4 address to be set.
387 :param network: Netmask or length of network prefix.
391 :type network: str or int
392 :return: Content of response.
396 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
398 if isinstance(network, basestring):
399 address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
400 elif isinstance(network, int) and (0 < network < 33):
401 address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
403 raise HoneycombError("Value {0} is not a valid netmask or network "
404 "prefix length.".format(network))
405 return InterfaceKeywords._set_interface_properties(
406 node, interface, path, address)
409 def remove_all_ipv4_addresses(node, interface):
410 """Remove all IPv4 addresses from interface.
412 :param node: Honeycomb node.
413 :param interface: The name of interface.
416 :return: Content of response.
420 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
422 return InterfaceKeywords._set_interface_properties(
423 node, interface, path, None)
426 def add_first_ipv4_neighbor(node, interface, ip_addr, link_layer_address):
427 """Add the first IPv4 neighbour.
429 If there are any other neighbours configured, they will be removed.
431 :param node: Honeycomb node.
432 :param interface: The name of interface.
433 :param ip_addr: IPv4 address of neighbour to be set.
434 :param link_layer_address: Link layer address.
438 :type link_layer_address: str
439 :return: Content of response.
443 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
444 neighbor = {"neighbor": [{"ip": ip_addr,
445 "link-layer-address": link_layer_address}, ]}
446 return InterfaceKeywords._set_interface_properties(
447 node, interface, path, neighbor)
450 def add_ipv4_neighbor(node, interface, ip_addr, link_layer_address):
451 """Add the IPv4 neighbour.
453 :param node: Honeycomb node.
454 :param interface: The name of interface.
455 :param ip_addr: IPv4 address of neighbour to be set.
456 :param link_layer_address: Link layer address.
460 :type link_layer_address: str
461 :return: Content of response.
465 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
467 neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ]
468 return InterfaceKeywords._set_interface_properties(
469 node, interface, path, neighbor)
472 def remove_all_ipv4_neighbors(node, interface):
473 """Remove all IPv4 neighbours.
475 :param node: Honeycomb node.
476 :param interface: The name of interface.
479 :return: Content of response.
483 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
485 return InterfaceKeywords._set_interface_properties(
486 node, interface, path, None)
489 def configure_interface_ipv6(node, interface, param, value):
490 """Configure IPv6 parameters of interface
492 :param node: Honeycomb node.
493 :param interface: The name of interface.
494 :param param: Parameter to configure (set, change, remove)
495 :param value: The value of parameter. If None, the parameter will be
501 :return: Content of response.
503 :raises HoneycombError: If the parameter is not valid.
506 if param in InterfaceKeywords.IPV6_PARAMS:
507 path = ("interfaces", ("interface", "name", interface),
508 "ietf-ip:ipv6", param)
509 elif param in InterfaceKeywords.IPV6_AUTOCONF_PARAMS:
510 path = ("interfaces", ("interface", "name", interface),
511 "ietf-ip:ipv6", "autoconf", param)
513 raise HoneycombError("The parameter {0} is invalid.".format(param))
515 return InterfaceKeywords._set_interface_properties(
516 node, interface, path, value)
519 def add_first_ipv6_address(node, interface, ip_addr, prefix_len):
520 """Add the first IPv6 address.
522 If there are any other addresses configured, they will be removed.
524 :param node: Honeycomb node.
525 :param interface: The name of interface.
526 :param ip_addr: IPv6 address to be set.
527 :param prefix_len: Prefix length.
531 :type prefix_len: str
532 :return: Content of response.
536 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6")
537 address = {"address": [{"ip": ip_addr, "prefix-length": prefix_len}, ]}
538 return InterfaceKeywords._set_interface_properties(
539 node, interface, path, address)
542 def add_ipv6_address(node, interface, ip_addr, prefix_len):
545 :param node: Honeycomb node.
546 :param interface: The name of interface.
547 :param ip_addr: IPv6 address to be set.
548 :param prefix_len: Prefix length.
552 :type prefix_len: str
553 :return: Content of response.
557 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
559 address = [{"ip": ip_addr, "prefix-length": prefix_len}, ]
560 return InterfaceKeywords._set_interface_properties(
561 node, interface, path, address)
564 def remove_all_ipv6_addresses(node, interface):
565 """Remove all IPv6 addresses from interface.
567 :param node: Honeycomb node.
568 :param interface: The name of interface.
571 :return: Content of response.
575 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
577 return InterfaceKeywords._set_interface_properties(
578 node, interface, path, None)
581 def add_first_ipv6_neighbor(node, interface, ip_addr, link_layer_address):
582 """Add the first IPv6 neighbour.
584 If there are any other neighbours configured, they will be removed.
586 :param node: Honeycomb node.
587 :param interface: The name of interface.
588 :param ip_addr: IPv6 address of neighbour to be set.
589 :param link_layer_address: Link layer address.
593 :type link_layer_address: str
594 :return: Content of response.
598 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6")
599 neighbor = {"neighbor": [{"ip": ip_addr,
600 "link-layer-address": link_layer_address}, ]}
601 return InterfaceKeywords._set_interface_properties(
602 node, interface, path, neighbor)
605 def add_ipv6_neighbor(node, interface, ip_addr, link_layer_address):
606 """Add the IPv6 neighbour.
608 :param node: Honeycomb node.
609 :param interface: The name of interface.
610 :param ip_addr: IPv6 address of neighbour to be set.
611 :param link_layer_address: Link layer address.
615 :type link_layer_address: str
616 :return: Content of response.
620 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
622 neighbor = [{"ip": ip_addr, "link-layer-address": link_layer_address}, ]
623 return InterfaceKeywords._set_interface_properties(
624 node, interface, path, neighbor)
627 def remove_all_ipv6_neighbors(node, interface):
628 """Remove all IPv6 neighbours.
630 :param node: Honeycomb node.
631 :param interface: The name of interface.
634 :return: Content of response.
638 path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv6",
640 return InterfaceKeywords._set_interface_properties(
641 node, interface, path, None)
644 def configure_interface_ethernet(node, interface, param, value):
645 """Configure the ethernet parameters of interface.
647 :param node: Honeycomb node.
648 :param interface: The name of interface.
649 :param param: Parameter to configure (set, change, remove)
650 :param value: The value of parameter. If None, the parameter will be
656 :return: Content of response.
658 :raises HoneycombError: If the parameter is not valid.
661 if param not in InterfaceKeywords.ETH_PARAMS:
662 raise HoneycombError("The parameter {0} is invalid.".format(param))
663 path = ("interfaces", ("interface", "name", interface), "v3po:ethernet",
665 return InterfaceKeywords._set_interface_properties(
666 node, interface, path, value)
669 def configure_interface_routing(node, interface, param, value):
670 """Configure the routing parameters of interface.
672 :param node: Honeycomb node.
673 :param interface: The name of interface.
674 :param param: Parameter to configure (set, change, remove)
675 :param value: The value of parameter. If None, the parameter will be
681 :return: Content of response.
683 :raises HoneycombError: If the parameter is not valid.
686 if param not in InterfaceKeywords.ROUTING_PARAMS:
687 raise HoneycombError("The parameter {0} is invalid.".format(param))
689 path = ("interfaces", ("interface", "name", interface), "v3po:routing",
691 return InterfaceKeywords._set_interface_properties(
692 node, interface, path, value)
695 def create_vxlan_interface(node, interface, **kwargs):
696 """Create a new VxLAN interface.
698 :param node: Honeycomb node.
699 :param interface: The name of interface.
700 :param kwargs: Parameters and their values. The accepted parameters are
701 defined in InterfaceKeywords.VXLAN_PARAMS.
705 :return: Content of response.
707 :raises HoneycombError: If the parameter is not valid.
712 "type": "v3po:vxlan-tunnel",
715 for param, value in kwargs.items():
716 if param not in InterfaceKeywords.VXLAN_PARAMS:
717 raise HoneycombError("The parameter {0} is invalid.".
719 new_vx_lan["v3po:vxlan"][param] = value
721 path = ("interfaces", "interface")
722 vx_lan_structure = [new_vx_lan, ]
723 return InterfaceKeywords._set_interface_properties(
724 node, interface, path, vx_lan_structure)
727 def delete_interface(node, interface):
728 """Delete an interface.
730 :param node: Honeycomb node.
731 :param interface: The name of interface.
734 :return: Content of response.
736 :raises HoneycombError: If it is not possible to get information about
737 interfaces or it is not possible to delete the interface.
740 path = ("interfaces", ("interface", "name", interface))
742 status_code, resp = HcUtil.\
743 get_honeycomb_data(node, "config_vpp_interfaces")
744 if status_code != HTTPCodes.OK:
745 raise HoneycombError(
746 "Not possible to get configuration information about the "
747 "interfaces. Status code: {0}.".format(status_code))
749 new_data = HcUtil.remove_item(resp, path)
750 status_code, resp = HcUtil.\
751 put_honeycomb_data(node, "config_vpp_interfaces", new_data)
752 if status_code != HTTPCodes.OK:
753 raise HoneycombError("Not possible to remove interface {0}. "
755 format(interface, status_code))
759 def configure_interface_vxlan(node, interface, **kwargs):
760 """Configure VxLAN on the interface.
762 The keyword configures VxLAN parameters on the given interface. The type
763 of interface must be set to "v3po:vxlan-tunnel".
764 The new VxLAN parameters overwrite the current configuration. If a
765 parameter in new configuration is missing, it is removed from VxLAN
767 If the dictionary kwargs is empty, VxLAN configuration is removed.
769 :param node: Honeycomb node.
770 :param interface: The name of interface.
771 :param kwargs: Parameters and their values. The accepted parameters are
772 defined in InterfaceKeywords.VXLAN_PARAMS.
776 :return: Content of response.
778 :raises HoneycombError: If the parameter is not valid.
781 vx_lan_structure = dict()
782 for param, value in kwargs.items():
783 if param not in InterfaceKeywords.VXLAN_PARAMS:
784 raise HoneycombError("The parameter {0} is invalid.".
786 vx_lan_structure[param] = value
788 path = ("interfaces", ("interface", "name", interface), "v3po:vxlan")
789 return InterfaceKeywords._set_interface_properties(
790 node, interface, path, vx_lan_structure)
793 def configure_interface_l2(node, interface, param, value):
794 """Configure the L2 parameters of interface.
796 :param node: Honeycomb node.
797 :param interface: The name of interface.
798 :param param: Parameter to configure (set, change, remove)
799 :param value: The value of parameter. If None, the parameter will be
805 :return: Content of response.
807 :raises HoneycombError: If the parameter is not valid.
810 if param not in InterfaceKeywords.L2_PARAMS:
811 raise HoneycombError("The parameter {0} is invalid.".format(param))
812 path = ("interfaces", ("interface", "name", interface), "v3po:l2",
814 return InterfaceKeywords._set_interface_properties(
815 node, interface, path, value)
818 def create_tap_interface(node, interface, **kwargs):
819 """Create a new TAP interface.
821 :param node: Honeycomb node.
822 :param interface: The name of interface.
823 :param kwargs: Parameters and their values. The accepted parameters are
824 defined in InterfaceKeywords.TAP_PARAMS.
828 :return: Content of response.
830 :raises HoneycombError: If the parameter is not valid.
838 for param, value in kwargs.items():
839 if param not in InterfaceKeywords.TAP_PARAMS:
840 raise HoneycombError("The parameter {0} is invalid.".
842 new_tap["v3po:tap"][param] = value
844 path = ("interfaces", "interface")
845 new_tap_structure = [new_tap, ]
846 return InterfaceKeywords._set_interface_properties(
847 node, interface, path, new_tap_structure)
850 def configure_interface_tap(node, interface, **kwargs):
851 """Configure TAP on the interface.
853 The keyword configures TAP parameters on the given interface. The type
854 of interface must be set to "v3po:tap".
855 The new TAP parameters overwrite the current configuration. If a
856 parameter in new configuration is missing, it is removed from TAP
858 If the dictionary kwargs is empty, TAP configuration is removed.
860 :param node: Honeycomb node.
861 :param interface: The name of interface.
862 :param kwargs: Parameters and their values. The accepted parameters are
863 defined in InterfaceKeywords.TAP_PARAMS.
867 :return: Content of response.
869 :raises HoneycombError: If the parameter is not valid.
872 tap_structure = dict()
873 for param, value in kwargs.items():
874 if param not in InterfaceKeywords.TAP_PARAMS:
875 raise HoneycombError("The parameter {0} is invalid.".
877 tap_structure[param] = value
879 path = ("interfaces", ("interface", "name", interface), "v3po:tap")
880 return InterfaceKeywords._set_interface_properties(
881 node, interface, path, tap_structure)
884 def configure_interface_vhost_user(node, interface, **kwargs):
885 """Configure vhost-user on the interface.
887 The keyword configures vhost-user parameters on the given interface.
888 The type of interface must be set to "v3po:vhost-user".
889 The new vhost-user parameters overwrite the current configuration. If a
890 parameter in new configuration is missing, it is removed from vhost-user
892 If the dictionary kwargs is empty, vhost-user configuration is removed.
894 :param node: Honeycomb node.
895 :param interface: The name of interface.
896 :param kwargs: Parameters and their values. The accepted parameters are
897 defined in InterfaceKeywords.VHOST_USER_PARAMS.
901 :return: Content of response.
903 :raises HoneycombError: If the parameter is not valid.
906 vhost_structure = dict()
907 for param, value in kwargs.items():
908 if param not in InterfaceKeywords.VHOST_USER_PARAMS:
909 raise HoneycombError("The parameter {0} is invalid.".
911 vhost_structure[param] = value
913 path = ("interfaces", ("interface", "name", interface),
915 return InterfaceKeywords._set_interface_properties(
916 node, interface, path, vhost_structure)
919 def create_vhost_user_interface(node, interface, **kwargs):
920 """Create a new vhost-user interface.
922 :param node: Honeycomb node.
923 :param interface: The name of interface.
924 :param kwargs: Parameters and their values. The accepted parameters are
925 defined in InterfaceKeywords.VHOST_USER_PARAMS.
929 :return: Content of response.
931 :raises HoneycombError: If the parameter is not valid.
936 "type": "v3po:vhost-user",
937 "v3po:vhost-user": {}
939 for param, value in kwargs.items():
940 if param not in InterfaceKeywords.VHOST_USER_PARAMS:
941 raise HoneycombError("The parameter {0} is invalid.".
943 new_vhost["v3po:vhost-user"][param] = value
945 path = ("interfaces", "interface")
946 new_vhost_structure = [new_vhost, ]
947 return InterfaceKeywords._set_interface_properties(
948 node, interface, path, new_vhost_structure)
951 def create_sub_interface(node, super_interface, identifier, **kwargs):
952 """Create a new sub-interface.
954 :param node: Honeycomb node.
955 :param super_interface: The name of super interface.
956 :param identifier: sub-interface identifier.
957 :param kwargs: Parameters and their values. The accepted parameters are
958 defined in InterfaceKeywords.SUB_INTF_PARAMS.
960 :type super_interface: str
961 :type identifier: int
963 :return: Content of response.
965 :raises HoneycombError: If the parameter is not valid.
968 # These parameters are empty types (in JSON represented as empty
969 # dictionary) but ODL internally represents them as Booleans. If the
970 # value is an empty dictionary, it is True, if the parameter is
971 # missing, it is False.
972 empty_types = ("match-any-outer-id",
973 "match-any-inner-id",
977 sub_interface_name = "{0}.{1}".format(super_interface, str(identifier))
978 new_sub_interface = {
979 "name": sub_interface_name,
980 "type": "v3po:sub-interface",
983 "super-interface": super_interface,
984 "identifier": identifier
987 for param, value in kwargs.items():
988 if param in InterfaceKeywords.INTF_PARAMS:
989 new_sub_interface[param] = value
990 elif param in InterfaceKeywords.SUB_INTF_PARAMS:
991 if param in empty_types:
993 new_sub_interface["sub-interface"][param] = dict()
995 new_sub_interface["sub-interface"][param] = value
997 raise HoneycombError("The parameter {0} is invalid.".
1000 path = ("interfaces", "interface")
1001 new_sub_interface_structure = [new_sub_interface, ]
1002 return InterfaceKeywords._set_interface_properties(
1003 node, sub_interface_name, path, new_sub_interface_structure)
1006 def add_vlan_tag_rewrite_to_sub_interface(node, sub_interface, **kwargs):
1007 """Add vlan tag rewrite to a sub-interface.
1009 :param node: Honeycomb node.
1010 :param sub_interface: The name of sub-interface.
1011 :param kwargs: Parameters and their values. The accepted parameters are
1012 defined in InterfaceKeywords.L2_REWRITE_TAG_PARAMS.
1014 :type sub_interface: str
1016 :return: Content of response.
1018 :raises HoneycombError: If the parameter is not valid.
1021 new_rewrite = dict()
1022 for param, value in kwargs.items():
1023 if param in InterfaceKeywords.L2_REWRITE_TAG_PARAMS:
1024 new_rewrite[param] = value
1026 raise HoneycombError("The parameter {0} is invalid.".
1029 path = ("interfaces", ("interface", "name", sub_interface), "v3po:l2",
1031 return InterfaceKeywords._set_interface_properties(
1032 node, sub_interface, path, new_rewrite)
1035 def remove_vlan_tag_rewrite_from_sub_interface(node, sub_interface):
1036 """Remove vlan tag rewrite from a sub-interface.
1038 :param node: Honeycomb node.
1039 :param sub_interface: The name of sub-interface.
1041 :type sub_interface: str
1043 :raises HoneycombError: If the parameter is not valid.
1046 path = ("interfaces", ("interface", "name", sub_interface), "v3po:l2",
1048 return InterfaceKeywords._set_interface_properties(
1049 node, sub_interface, path, None)