# If the flow is a subscription, we need to associate it to the list
query = packet.to_query()
if query.action == ACTION_SUBSCRIBE:
- print('adding subscription', query.to_dict())
# XXX we currently don't merge subscriptions, and assume a single
# next hop interface
s = Subscription(packet, [ingress_interface], [interface])
# Automatic instanciation
#
# Used for instance in route.node.routing_table.routes
+ # XXX We can only auto_instanciate local attributes, otherwise we
+ # get issues with asyncio loop not present in thread
if attribute.requirements:
log.warning('Ignored requirements {}'.format(
attribute.requirements))
value = self.get_default(attribute)
self.set(attribute.name, value)
else:
- log.info("Fetching remote value for {}.{}".format(self,attribute.name))
+ # printing self might do an infinite loop here !
+ log.info("Fetching remote value for {}.{}".format(self.get_uuid(), attribute.name))
task = getattr(self, "_get_{}".format(attribute.name))()
#XXX This is ugly but it prevents the LxdNotFound exception
while True:
import traceback; traceback.print_tb(e.__traceback__)
log.error("Failed to retrieve remote value for {} on {}".format(attribute.name, self))
import os; os._exit(1)
- value = rv[attribute.name]
+ value = rv[attribute.name] if isinstance(rv, dict) else rv
vars(self)[attribute.name] = value
if unref and isinstance(value, UUID):
def _trigger_state_change(self, resource, fut):
try:
+
ret = fut.result()
resource._state.change_success = True
resource._state.change_value = ret
# Update state based on task results
if pending_state == ResourceState.PENDING_DEPS:
- # XXX NO CHANGE SUCCESS TEST ??
- new_state = ResourceState.DEPS_OK
+ if resource._state.change_success == True:
+ self.log(resource, 'DEPS done.')
+ new_state = ResourceState.DEPS_OK
+ else:
+ e = resource._state.change_value
+ log.error('Cannot wait resource dependencies {} : {}'.format(
+ resource.get_uuid(), e))
+ new_state = ResourceState.ERROR
elif pending_state == ResourceState.PENDING_INIT:
if resource._state.change_success == True:
return hash(str(self))
def __iter__(self):
- for i in range(self.first_prefix_address(), self.last_prefix_address()+1):
- yield self.ntoa(i)
+ return self.get_iterator()
#Iterates by steps of prefix_size, e.g., on all available /31 in a /24
def get_iterator(self, prefix_size=None):
Implements a SSL certificate.
"""
- node = Attribute(Node,
+ node = Attribute(Node,
description = 'Node on which the certificate is created',
mandatory = True,
multiplicity = Multiplicity.ManyToOne)
cert = Attribute(String, description = 'Certificate path',
- mandatory = True)
+ mandatory = True)
key = Attribute(String, description = 'Key path',
mandatory = True)
return self._cert_file.__get__() | self._key_file.__get__()
def __create__(self):
- return BashTask(None, CMD_CREATE, {'self': self})
-
+ return BashTask(self.node, CMD_CREATE, {'self': self})
+
def __delete__(self):
return self._cert_file.__delete__() | self._key_file.__delete__()
# parse_ip_addr inspired from:
# From: https://github.com/ohmu/poni/blob/master/poni/cloud_libvirt.py
-LXD_FIX = lambda cmd: 'sleep 1 && {}'.format(cmd)
-
MAX_DEVICE_NAME_SIZE = 15
IPV4=4
log = logging.getLogger(__name__)
-CMD_GET = LXD_FIX('ip link show {netdevice.device_name}')
+CMD_GET = 'ip link show {netdevice.device_name}'
CMD_CREATE = 'ip link add name {netdevice.device_name} ' \
'type {netdevice.netdevice_type}'
CMD_CREATE_PARENT = 'ip link add name {netdevice.device_name} ' \
ret.append(parse_lscpu_line(line))
return ret
-#------------------------------------------------------------------------------
+#------------------------------------------------------------------------------
class NumaManager(Resource):
"""
multiplicity = Multiplicity.OneToOne,
reverse_auto = True,
reverse_name = 'numa_mgr')
- numa_repartitor = Attribute(CycleType,
+ numa_repartitor = Attribute(CycleType,
description = 'Tool to separate cores/CPUs/sockets',
- multiplicity = Multiplicity.OneToMany,
+ multiplicity = Multiplicity.OneToMany,
ro = True)
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Resource lifecycle
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
__create__ = None
__delete__ = None
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Constructor and Accessors
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_numa_node = 0
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
# Attributes
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
def _get_numa_repartitor(self):
return BashTask(self.node, CMD_LSCPU, parse=parse_lscpu_rv)
- #--------------------------------------------------------------------------
- # Public API
- #--------------------------------------------------------------------------
+ #--------------------------------------------------------------------------
+ # Public API
+ #--------------------------------------------------------------------------
def get_numa_core(self, numa_node=None):
if numa_node is None:
'''
# We need to double { } we want to preserve
-CMD_PKG_TEST='dpkg -s {self.package_name}'
+CMD_PKG_TEST='dpkg -s {self.package_name} | grep "Status:.* install "'
CMD_PKG_INSTALL='''
# Installing package {package_name}
container = self._get_container_description()
log.debug('Container description: {}'.format(container))
client = self.node.lxd_hypervisor.client
+
self._container = client.containers.create(container, wait=True)
def _get_container_description(self):
DEFAULT_KEY_PATH = os.path.expanduser(os.path.join(
'~', '.vicn', 'lxd_client_cert', 'client_key.pem'))
-# FIXME hardcoded password for LXD server
LXD_TRUST_PWD_DEFAULT = 'vicn'
LXD_STORAGE_SIZE_DEFAULT = 100 # GB
owner = self)
lxd_cert_install = LxdInstallCert(certificate = lxd_local_cert,
owner = self)
+ # XXX BUG network has to exist before profile, although as an attribute it
+ # will be setup after
lxd_vicn_profile = LxdProfile(name=LXD_PROFILE_NAME_DEFAULT,
node=self.node,
description='vICN profile',
lxc profile device add {profile.name} {profile.iface_name} nic name={profile.iface_name} nictype=bridged parent={profile.network}
lxc profile unset {profile.name} environment.http_proxy
lxc profile unset {profile.name} user.network_mode
+# Temp fix for VPP
+lxc profile create vpp
'''
CMD_LXD_PROFILE_GET = 'lxc profile list | grep {profile.name}'
from vicn.core.task import BashTask, task, inline_task
from vicn.resource.lxd.lxc_container import LxcContainer
from vicn.resource.node import Node
+from vicn.resource.linux.application import LinuxApplication
from vicn.resource.linux.file import TextFile
from vicn.resource.vpp.dpdk_device import DpdkDevice
from vicn.resource.vpp.scripts import FN_VPP_DPDK_SCRIPT
from vicn.resource.vpp.vpp_commands import CMD_VPP_DISABLE, CMD_VPP_STOP
from vicn.resource.vpp.vpp_commands import CMD_VPP_START
from vicn.resource.vpp.vpp_commands import CMD_VPP_ENABLE_PLUGIN
+from vicn.resource.vpp.vpp_host import VPPHost
#------------------------------------------------------------------------------
# VPP forwarder
CMD_GET = 'killall -0 vpp_main'
CMD_DISABLE_IP_FORWARD = 'sysctl -w net.ipv4.ip_forward=0'
-class VPP(Resource):
+class VPP(LinuxApplication):
"""
Todo:
- make VPP an application with package install
start and stop commands
"""
- #__package_names__ = ['vpp', 'vpp-dbg', 'vpp-dpdk-dev']
+ __package_names__ = ['vpp', 'vpp-dbg', 'vpp-dpdk-dev']
plugins = Attribute(String,
multiplicity = Multiplicity.OneToMany)