aboutsummaryrefslogtreecommitdiffstats
path: root/vicn/resource/linux
diff options
context:
space:
mode:
authorMarcel Enguehard <mengueha+fdio@cisco.com>2017-05-23 10:50:17 +0200
committerMarcel Enguehard <mengueha+fdio@cisco.com>2017-05-23 08:57:12 +0000
commitbe0b435d307173598c30fcacc421b17112137099 (patch)
treeed8aae7eef796eb7381d21937b095a036733789a /vicn/resource/linux
parent895a6328d6e64948ed213e8fbbb3ab15aca0df43 (diff)
Introduced groups + lxd profiles + diverted control network handling to lxd + misc bug fixes
Change-Id: Iae26bc2994ac9704dde7dfa8fbe4be1b74cf9e6f Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
Diffstat (limited to 'vicn/resource/linux')
-rw-r--r--vicn/resource/linux/application.py1
-rw-r--r--vicn/resource/linux/bridge.py2
-rw-r--r--vicn/resource/linux/dnsmasq.py10
-rw-r--r--vicn/resource/linux/net_device.py16
-rw-r--r--vicn/resource/linux/package_manager.py55
-rw-r--r--vicn/resource/linux/repository.py7
6 files changed, 48 insertions, 43 deletions
diff --git a/vicn/resource/linux/application.py b/vicn/resource/linux/application.py
index d2b5139e..ed135da6 100644
--- a/vicn/resource/linux/application.py
+++ b/vicn/resource/linux/application.py
@@ -21,7 +21,6 @@ from vicn.core.resource import Resource, EmptyResource
from vicn.resource.application import Application
from vicn.resource.linux.package_manager import Packages
-
class LinuxApplication(Application):
"""
Resource: Linux Application
diff --git a/vicn/resource/linux/bridge.py b/vicn/resource/linux/bridge.py
index 882f0226..7b5ceed7 100644
--- a/vicn/resource/linux/bridge.py
+++ b/vicn/resource/linux/bridge.py
@@ -46,7 +46,7 @@ class Bridge(Channel, BaseNetDevice):
Requirement('bridge_manager')
])
device_name = Attribute(
- default = DEFAULT_BRIDGE_NAME,
+ default = lambda self: self._state.manager.get('bridge_name'),
mandatory = False)
#--------------------------------------------------------------------------
diff --git a/vicn/resource/linux/dnsmasq.py b/vicn/resource/linux/dnsmasq.py
index e18f750f..b5aa8053 100644
--- a/vicn/resource/linux/dnsmasq.py
+++ b/vicn/resource/linux/dnsmasq.py
@@ -42,7 +42,6 @@ TPL_CONF='''
interface=$interface
dhcp-range=$dhcp_range
-dhcp-host=00:0e:c6:81:79:01,192.168.128.200,12h
#server=$server
$flags
@@ -60,12 +59,12 @@ class DnsMasq(Service, DnsServer):
__package_names__ = ['dnsmasq']
__service_name__ = 'dnsmasq'
- interface = Attribute(Interface,
+ interface = Attribute(Interface,
description = 'Interface on which to listen')
lease_interval = Attribute(String,
default = '12h')
server = Attribute(String)
- dhcp_authoritative = Attribute(Bool,
+ dhcp_authoritative = Attribute(Bool,
description = 'Flag: DHCP authoritative',
default = True)
log_queries = Attribute(Bool, description = 'Flag: log DNS queries',
@@ -80,10 +79,7 @@ class DnsMasq(Service, DnsServer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.interface:
- if self.node.bridge:
- self.interface = self.node.bridge
- else:
- self.interface = self.node.host_interface
+ raise Exception("Cannot initialize bridge without interface")
def __subresources__(self):
# Overwrite configuration file
diff --git a/vicn/resource/linux/net_device.py b/vicn/resource/linux/net_device.py
index 1ce7e4d5..e40256ea 100644
--- a/vicn/resource/linux/net_device.py
+++ b/vicn/resource/linux/net_device.py
@@ -22,14 +22,14 @@ import math
import random
import string
-from netmodel.model.type import Integer, String, Bool
-from vicn.core.address_mgr import AddressManager
-from vicn.core.attribute import Attribute
-from vicn.core.exception import ResourceNotFound
-from vicn.core.resource import BaseResource
-from vicn.core.task import BashTask, task, EmptyTask
-from vicn.resource.application import Application
-from vicn.resource.interface import Interface
+from netmodel.model.type import Integer, String, Bool
+from vicn.core.address_mgr import AddressManager
+from vicn.core.attribute import Attribute
+from vicn.core.exception import ResourceNotFound
+from vicn.core.resource import BaseResource
+from vicn.core.task import BashTask, task, EmptyTask
+from vicn.resource.linux.application import LinuxApplication as Application
+from vicn.resource.interface import Interface
# parse_ip_addr inspired from:
# From: https://github.com/ohmu/poni/blob/master/poni/cloud_libvirt.py
diff --git a/vicn/resource/linux/package_manager.py b/vicn/resource/linux/package_manager.py
index 86b7057a..eaf83e17 100644
--- a/vicn/resource/linux/package_manager.py
+++ b/vicn/resource/linux/package_manager.py
@@ -19,7 +19,7 @@
import asyncio
import logging
-from netmodel.model.type import String
+from netmodel.model.type import String, Bool
from vicn.core.attribute import Attribute, Multiplicity
from vicn.core.exception import ResourceNotFound
from vicn.core.requirement import Requirement
@@ -63,7 +63,7 @@ class PackageManager(Resource):
Resource: PackageManager
APT package management wrapper.
-
+
Todo:
- We assume a package manager is always installed on every machine.
- Currently, we limit ourselves to debian/ubuntu, and voluntarily don't
@@ -79,6 +79,9 @@ class PackageManager(Resource):
reverse_auto = True,
mandatory = True,
multiplicity = Multiplicity.OneToOne)
+ trusted = Attribute(Bool,
+ description="Force repository trust",
+ default=False)
#--------------------------------------------------------------------------
# Constructor and Accessors
@@ -94,34 +97,28 @@ class PackageManager(Resource):
#--------------------------------------------------------------------------
def __after__(self):
- if self.node.__class__.__name__ == 'Physical':
- # UGLY : This blocking code is currently needed
- task = self.node.host_interface._get_ip4_address()
- ip_dict = task.execute_blocking()
- self.node.host_interface.ip4_address = ip_dict['ip4_address']
- return ('Repository',)
- else:
- return ('Repository', 'CentralIP', 'RoutingTable')
+ return ('Repository',)
@inline_task
def __get__(self):
raise ResourceNotFound
- def __create__(self):
+ #---------------------------------------------------------------------------
+ # Methods
+ #---------------------------------------------------------------------------
+
+ def __method_setup_repositories__(self):
repos = EmptyTask()
for repository in self._state.manager.by_type_str('Repository'):
deb_source = self._get_deb_source(repository)
path = self._get_path(repository)
- repo = BashTask(self.node, CMD_SETUP_REPO,
+ # XXX There is no need to setup a repo if there is no package to install
+ repo = BashTask(self.node, CMD_SETUP_REPO,
{'deb_source': deb_source, 'path': path})
repos = repos | repo
- return repos
+ return repos
- #---------------------------------------------------------------------------
- # Methods
- #---------------------------------------------------------------------------
-
def __method_update__(self):
kill = BashTask(self.node, CMD_APT_GET_KILL, {'node': self.node.name},
lock = self.apt_lock)
@@ -139,13 +136,12 @@ class PackageManager(Resource):
else:
update = EmptyTask()
- return (kill > dpkg_configure_a) > update
+ return (self.__method_setup_repositories__() > (kill > dpkg_configure_a)) > update
def __method_install__(self, package_name):
- update = self.__method_update__()
install = BashTask(self.node, CMD_PKG_INSTALL, {'package_name':
package_name}, lock = self.apt_lock)
- return update > install
+ return self.__method_update__() > install
#---------------------------------------------------------------------------
# Internal methods
@@ -158,10 +154,20 @@ class PackageManager(Resource):
return '/etc/apt/sources.list.d/{}.list'.format(repository.repo_name)
def _get_deb_source(self, repository):
- path = repository.node.host_interface.ip4_address + '/'
+ protocol = 'https' if repository.ssl else 'http'
+ path = repository.node.hostname + '/'
if repository.directory:
path += repository.directory + '/'
- return 'deb http://{} {}/'.format(path, self.node.dist)
+ trusted = '[trusted=yes] ' if self.trusted else ''
+ if repository.sections:
+ sections = ' {}'.format(' '.join(repository.sections))
+ else:
+ sections = ''
+ if '$DISTRIBUTION' in path:
+ path = path.replace('$DISTRIBUTION', self.node.dist)
+ return 'deb {}{}://{} ./{}'.format(trusted, protocol, path, sections)
+ else:
+ return 'deb {}{}://{} {}{}'.format(trusted, protocol, path, self.node.dist, sections)
#------------------------------------------------------------------------------
@@ -173,7 +179,7 @@ class Package(Resource):
"""
package_name = Attribute(String, mandatory = True)
- node = Attribute(Node,
+ node = Attribute(Node,
mandatory = True,
requirements=[
Requirement('package_manager')
@@ -208,7 +214,7 @@ class Packages(Resource):
since package_names are static for a resource, this is not a problem here.
"""
names = Attribute(String, multiplicity = Multiplicity.OneToMany)
- node = Attribute(Node,
+ node = Attribute(Node,
mandatory = True,
requirements=[
Requirement('package_manager')
@@ -229,4 +235,3 @@ class Packages(Resource):
return Resource.__concurrent__(*packages)
else:
return None
-
diff --git a/vicn/resource/linux/repository.py b/vicn/resource/linux/repository.py
index f3e70565..cd740d38 100644
--- a/vicn/resource/linux/repository.py
+++ b/vicn/resource/linux/repository.py
@@ -16,7 +16,7 @@
# limitations under the License.
#
-from netmodel.model.type import String
+from netmodel.model.type import String, Bool
from vicn.core.attribute import Attribute, Multiplicity
from vicn.resource.application import Application
@@ -35,7 +35,12 @@ class Repository(Application):
default = 'vicn')
directory = Attribute(String, description = 'Directory holding packages',
default = '')
+ sections = Attribute(String, description = 'Sections',
+ multiplicity = Multiplicity.OneToMany,
+ default = [])
distributions = Attribute(String,
description = 'List of distributions served by this repository',
multiplicity = Multiplicity.ManyToMany,
default = ['sid', 'trusty', 'xenial'])
+ ssl = Attribute(Bool, description = 'Use SSL (https) for repository',
+ default = True)