aboutsummaryrefslogtreecommitdiffstats
path: root/vicn/resource/linux/sym_veth_pair.py
diff options
context:
space:
mode:
Diffstat (limited to 'vicn/resource/linux/sym_veth_pair.py')
-rw-r--r--vicn/resource/linux/sym_veth_pair.py52
1 files changed, 28 insertions, 24 deletions
diff --git a/vicn/resource/linux/sym_veth_pair.py b/vicn/resource/linux/sym_veth_pair.py
index bf79a69b..ebfe2968 100644
--- a/vicn/resource/linux/sym_veth_pair.py
+++ b/vicn/resource/linux/sym_veth_pair.py
@@ -26,12 +26,12 @@ from vicn.core.resource import Resource
from vicn.core.state import ResourceState, AttributeState
from vicn.core.task import BashTask, get_attributes_task
from vicn.core.task import async_task, task, inline_task
-from vicn.core.task import run_task
+from vicn.core.task import run_task, inherit_parent
from vicn.resource.interface import Interface
from vicn.resource.node import Node
from vicn.resource.linux.net_device import NonTapBaseNetDevice
from vicn.resource.linux.link import CMD_DELETE_IF_EXISTS
-from vicn.resource.linux.link import CMD_UP
+from vicn.resource.linux.link import CMD_SET_UP
CMD_CREATE='''
# Create veth pair in the host node
@@ -48,13 +48,13 @@ class SymVethPair(Resource):
resource is that is it not a channel.
"""
- node1 = Attribute(Node,
+ node1 = Attribute(Node,
description = 'Node on which one side of the veth will sit',
mandatory = True)
- node2 = Attribute(Node,
+ node2 = Attribute(Node,
description = 'Node on which the other side of the veth will sit',
mandatory = True)
- capacity = Attribute(Integer,
+ capacity = Attribute(Integer,
description = 'Capacity of the veth pair (Mb/s)')
side1 = Attribute(Interface, description = 'Source interface')
side2 = Attribute(Interface, description = 'Destination interface')
@@ -66,21 +66,22 @@ class SymVethPair(Resource):
async def _commit(self):
# see link.py for explanations
manager = self._state.manager
- await manager._set_resource_state(self.side1,
+ await manager._set_resource_state(self.side1,
ResourceState.INITIALIZED)
- await manager._set_resource_state(self.side2,
+ await manager._set_resource_state(self.side2,
ResourceState.INITIALIZED)
await manager._set_resource_state(self.side1, ResourceState.CREATED)
await manager._set_resource_state(self.side2, ResourceState.CREATED)
await manager._set_attribute_state(self, 'side1', AttributeState.CLEAN)
await manager._set_attribute_state(self, 'side2', AttributeState.CLEAN)
manager.commit_resource(self.side1)
- manager.commit_resource(self.side2)
+ manager.commit_resource(self.side2)
#--------------------------------------------------------------------------
# Resource lifecycle
#--------------------------------------------------------------------------
+ @inherit_parent
@inline_task
def __initialize__(self):
self.side1 = NonTapBaseNetDevice(node = self.node1,
@@ -94,6 +95,7 @@ class SymVethPair(Resource):
self.side1.remote = self.side2
self.side2.remote = self.side1
+ @inherit_parent
@async_task
async def __get__(self):
manager = self._state.manager
@@ -106,46 +108,48 @@ class SymVethPair(Resource):
await self._commit()
+ @inherit_parent
def __create__(self):
assert self.node1.get_type() == 'lxccontainer'
assert self.node2.get_type() == 'lxccontainer'
-
+
node1_host = self.node1.node
node2_host = self.node2.node
-
+
assert node1_host == node2_host
host = node1_host
-
+
# Sometimes a down interface persists on one side
- delif_side1 = BashTask(self.node1, CMD_DELETE_IF_EXISTS,
+ delif_side1 = BashTask(self.node1, CMD_DELETE_IF_EXISTS,
{'interface': self.side1})
- delif_side2 = BashTask(self.node2, CMD_DELETE_IF_EXISTS,
+ delif_side2 = BashTask(self.node2, CMD_DELETE_IF_EXISTS,
{'interface': self.side2})
-
+
pid_node1 = get_attributes_task(self.node1, ['pid'])
pid_node2 = get_attributes_task(self.node2, ['pid'])
-
+
tmp_side1 = 'tmp-veth-' + ''.join(random.choice(
string.ascii_uppercase + string.digits) for _ in range(5))
tmp_side2 = 'tmp-veth-' + ''.join(random.choice(
string.ascii_uppercase + string.digits) for _ in range(5))
-
- create = BashTask(host, CMD_CREATE,
+
+ create = BashTask(host, CMD_CREATE,
{'side1_device_name': self.side1.device_name,
- 'side2_device_name': self.side2.device_name,
+ 'side2_device_name': self.side2.device_name,
'tmp_side1': tmp_side1, 'tmp_side2': tmp_side2})
-
- up_side1 = BashTask(self.node1, CMD_UP, {'interface': self.side1})
- up_side2 = BashTask(self.node2, CMD_UP, {'interface': self.side2})
-
+
+ up_side1 = BashTask(self.node1, CMD_SET_UP, {'interface': self.side1})
+ up_side2 = BashTask(self.node2, CMD_SET_UP, {'interface': self.side2})
+
@async_task
async def set_state():
await self._commit()
-
+
delif = delif_side1 | delif_side2
up = up_side1 | up_side2
pid = pid_node1 | pid_node2
return ((delif > (pid @ create)) > up) > set_state()
-
+
+ @inherit_parent
def __delete__(self):
raise NotImplementedError