|
|
@ -35,7 +35,19 @@ options:
|
|
|
|
bridge:
|
|
|
|
bridge:
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of bridge to manage
|
|
|
|
- Name of bridge or fake bridge to manage
|
|
|
|
|
|
|
|
parent:
|
|
|
|
|
|
|
|
version_added: 2.2
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Bridge parent of the fake bridge to manage
|
|
|
|
|
|
|
|
vlan:
|
|
|
|
|
|
|
|
version_added: 2.2
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- The VLAN id of the fake bridge to manage (must be between 0 and 4095)
|
|
|
|
state:
|
|
|
|
state:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: "present"
|
|
|
|
default: "present"
|
|
|
@ -67,6 +79,9 @@ EXAMPLES = '''
|
|
|
|
# Create a bridge named br-int
|
|
|
|
# Create a bridge named br-int
|
|
|
|
- openvswitch_bridge: bridge=br-int state=present
|
|
|
|
- openvswitch_bridge: bridge=br-int state=present
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a fake bridge named br-int within br-parent on the VLAN 405
|
|
|
|
|
|
|
|
- openvswitch_bridge: bridge=br-int parent=br-parent vlan=405 state=present
|
|
|
|
|
|
|
|
|
|
|
|
# Create an integration bridge
|
|
|
|
# Create an integration bridge
|
|
|
|
- openvswitch_bridge: bridge=br-int state=present fail_mode=secure
|
|
|
|
- openvswitch_bridge: bridge=br-int state=present fail_mode=secure
|
|
|
|
args:
|
|
|
|
args:
|
|
|
@ -80,10 +95,18 @@ class OVSBridge(object):
|
|
|
|
def __init__(self, module):
|
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
|
|
|
self.module = module
|
|
|
|
self.bridge = module.params['bridge']
|
|
|
|
self.bridge = module.params['bridge']
|
|
|
|
|
|
|
|
self.parent = module.params['parent']
|
|
|
|
|
|
|
|
self.vlan = module.params['vlan']
|
|
|
|
self.state = module.params['state']
|
|
|
|
self.state = module.params['state']
|
|
|
|
self.timeout = module.params['timeout']
|
|
|
|
self.timeout = module.params['timeout']
|
|
|
|
self.fail_mode = module.params['fail_mode']
|
|
|
|
self.fail_mode = module.params['fail_mode']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.parent and self.vlan is None:
|
|
|
|
|
|
|
|
self.module.fail_json(msg='VLAN id must be set when parent is defined')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.vlan < 0 or self.vlan > 4095:
|
|
|
|
|
|
|
|
self.module.fail_json(msg='Invalid VLAN ID (must be between 0 and 4095)')
|
|
|
|
|
|
|
|
|
|
|
|
def _vsctl(self, command):
|
|
|
|
def _vsctl(self, command):
|
|
|
|
'''Run ovs-vsctl command'''
|
|
|
|
'''Run ovs-vsctl command'''
|
|
|
|
return self.module.run_command(['ovs-vsctl', '-t',
|
|
|
|
return self.module.run_command(['ovs-vsctl', '-t',
|
|
|
@ -100,7 +123,11 @@ class OVSBridge(object):
|
|
|
|
|
|
|
|
|
|
|
|
def add(self):
|
|
|
|
def add(self):
|
|
|
|
'''Create the bridge'''
|
|
|
|
'''Create the bridge'''
|
|
|
|
rtc, _, err = self._vsctl(['add-br', self.bridge])
|
|
|
|
if self.parent and self.vlan: # Add fake bridge
|
|
|
|
|
|
|
|
rtc, _, err = self._vsctl(['add-br', self.bridge, self.parent, self.vlan])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
rtc, _, err = self._vsctl(['add-br', self.bridge])
|
|
|
|
|
|
|
|
|
|
|
|
if rtc != 0:
|
|
|
|
if rtc != 0:
|
|
|
|
self.module.fail_json(msg=err)
|
|
|
|
self.module.fail_json(msg=err)
|
|
|
|
if self.fail_mode:
|
|
|
|
if self.fail_mode:
|
|
|
@ -249,6 +276,8 @@ def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec={
|
|
|
|
argument_spec={
|
|
|
|
'bridge': {'required': True},
|
|
|
|
'bridge': {'required': True},
|
|
|
|
|
|
|
|
'parent': {'default': None},
|
|
|
|
|
|
|
|
'vlan': {'default': None, 'type': 'int'},
|
|
|
|
'state': {'default': 'present', 'choices': ['present', 'absent']},
|
|
|
|
'state': {'default': 'present', 'choices': ['present', 'absent']},
|
|
|
|
'timeout': {'default': 5, 'type': 'int'},
|
|
|
|
'timeout': {'default': 5, 'type': 'int'},
|
|
|
|
'external_ids': {'default': None, 'type': 'dict'},
|
|
|
|
'external_ids': {'default': None, 'type': 'dict'},
|
|
|
|