/virttest/libvirt_xml/nwfilter_protocols/ah_ipv6.py

https://github.com/avocado-framework/avocado-vt · Python · 127 lines · 96 code · 8 blank · 23 comment · 1 complexity · b4189f7e0849e955c81c9953da77b4d7 MD5 · raw file

  1. """
  2. ah-ipv6 protocl support class(es)
  3. http://libvirt.org/formatnwfilter.html#nwfelemsRulesProtoMiscv6
  4. """
  5. from virttest.libvirt_xml import accessors, xcepts
  6. from virttest.libvirt_xml.nwfilter_protocols import base
  7. class Ah_ipv6(base.TypedDeviceBase):
  8. """
  9. Create new Ah_ipv6 xml instances
  10. Properties:
  11. attrs: libvirt_xml.nwfilter_protocols.Ah_ipv6.Attr instance
  12. """
  13. __slots__ = ('attrs',)
  14. def __init__(self, type_name='file', virsh_instance=base.base.virsh):
  15. accessors.XMLElementNest('attrs', self, parent_xpath='/',
  16. tag_name='ah_ipv6', subclass=self.Attr,
  17. subclass_dargs={
  18. 'virsh_instance': virsh_instance})
  19. super(Ah_ipv6, self).__init__(protocol_tag='ah-ipv6',
  20. type_name=type_name,
  21. virsh_instance=virsh_instance)
  22. def new_attr(self, **dargs):
  23. """
  24. Return a new Attr instance and set properties from dargs
  25. :param dargs: dict of attributes
  26. :return: new Attr instance
  27. """
  28. new_one = self.Attr(virsh_instance=self.virsh)
  29. for key, value in list(dargs.items()):
  30. setattr(new_one, key, value)
  31. return new_one
  32. def get_attr(self):
  33. """
  34. Return ah-ipv6 attribute dict
  35. :return: None if no ah-ipv6 in xml, dict of ah-ipv6's attributes.
  36. """
  37. try:
  38. ah_node = self.xmltreefile.reroot('/ah-ipv6')
  39. except KeyError as detail:
  40. raise xcepts.LibvirtXMLError(detail)
  41. node = ah_node.getroot()
  42. ah_attr = dict(list(node.items()))
  43. return ah_attr
  44. class Attr(base.base.LibvirtXMLBase):
  45. """
  46. Ah_ipv6 attribute XML class
  47. Properties:
  48. srcmacaddr: string, MAC address of sender
  49. srcmacmask: string, Mask applied to MAC address of sender
  50. dstmacaddr: string, MAC address of destination
  51. dstmacmask: string, Mask applied to MAC address of destination
  52. srcipaddr: string, Source IP address
  53. srcipmask: string, Mask applied to source IP address
  54. dstipaddr: string, Destination IP address
  55. dstipmask: string, Mask applied to destination IP address
  56. srcipfrom: string, Start of range of source IP address
  57. srcipto: string, End of range of source IP address
  58. dstipfrom: string, Start of range of destination IP address
  59. dstipto: string, End of range of destination IP address
  60. comment: string, text with max. 256 characters
  61. state: string, comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE
  62. ipset: The name of an IPSet managed outside of libvirt
  63. ipsetflags: flags for the IPSet; requires ipset attribute
  64. """
  65. __slots__ = ('srcmacaddr', 'srcmacmask', 'dstmacaddr', 'dstmacmask',
  66. 'srcipaddr', 'srcipmask', 'dstipaddr', 'dstipmask',
  67. 'srcipfrom', 'srcipto', 'dstipfrom', 'dstipto',
  68. 'dscp', 'comment', 'state', 'ipset', 'ipsetflags')
  69. def __init__(self, virsh_instance=base.base.virsh):
  70. accessors.XMLAttribute('srcmacaddr', self, parent_xpath='/',
  71. tag_name='ah-ipv6', attribute='srcmacaddr')
  72. accessors.XMLAttribute('srcmacmask', self, parent_xpath='/',
  73. tag_name='ah-ipv6', attribute='srcmacmask')
  74. accessors.XMLAttribute('dstmacaddr', self, parent_xpath='/',
  75. tag_name='ah-ipv6', attribute='dstmacaddr')
  76. accessors.XMLAttribute('dstmacmask', self, parent_xpath='/',
  77. tag_name='ah-ipv6', attribute='dstmacmask')
  78. accessors.XMLAttribute('srcipaddr', self, parent_xpath='/',
  79. tag_name='ah-ipv6', attribute='srcipaddr')
  80. accessors.XMLAttribute('srcipmask', self, parent_xpath='/',
  81. tag_name='ah-ipv6', attribute='srcipmask')
  82. accessors.XMLAttribute('dstipaddr', self, parent_xpath='/',
  83. tag_name='ah-ipv6', attribute='dstipaddr')
  84. accessors.XMLAttribute('dstipmask', self, parent_xpath='/',
  85. tag_name='ah-ipv6', attribute='dstipmask')
  86. accessors.XMLAttribute('srcipfrom', self, parent_xpath='/',
  87. tag_name='ah-ipv6', attribute='srcipfrom')
  88. accessors.XMLAttribute('srcipto', self, parent_xpath='/',
  89. tag_name='ah-ipv6', attribute='srcipto')
  90. accessors.XMLAttribute('dstipfrom', self, parent_xpath='/',
  91. tag_name='ah-ipv6', attribute='dstipfrom')
  92. accessors.XMLAttribute('dstipto', self, parent_xpath='/',
  93. tag_name='ah-ipv6', attribute='dstipto')
  94. accessors.XMLAttribute('dscp', self, parent_xpath='/',
  95. tag_name='ah-ipv6', attribute='dscp')
  96. accessors.XMLAttribute('comment', self, parent_xpath='/',
  97. tag_name='ah-ipv6', attribute='comment')
  98. accessors.XMLAttribute('state', self, parent_xpath='/',
  99. tag_name='ah-ipv6', attribute='state')
  100. accessors.XMLAttribute('ipset', self, parent_xpath='/',
  101. tag_name='ah-ipv6', attribute='ipset')
  102. accessors.XMLAttribute('ipsetflags', self, parent_xpath='/',
  103. tag_name='ah-ipv6', attribute='ipsetflags')
  104. super(self.__class__, self).__init__(virsh_instance=virsh_instance)
  105. self.xml = '<ah-ipv6/>'