mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
New plugin: ntp
This commit is contained in:
parent
4ca99a8bb2
commit
afffdf680d
3 changed files with 69 additions and 0 deletions
11
plugins/ntp/__init__.py
Normal file
11
plugins/ntp/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
def validate_manifest(data, validator, error):
|
||||
import os.path
|
||||
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.json'))
|
||||
validator(data, schema_path)
|
||||
|
||||
|
||||
def resolve_tasks(taskset, manifest):
|
||||
import tasks
|
||||
taskset.add(tasks.AddNtpPackage)
|
||||
if manifest.plugins['ntp'].get('servers', False):
|
||||
taskset.add(tasks.SetNtpServers)
|
24
plugins/ntp/manifest-schema.json
Normal file
24
plugins/ntp/manifest-schema.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "NTP plugin manifest",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"plugins": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ntp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"servers": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"minItems": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["ntp"]
|
||||
}
|
||||
},
|
||||
"required": ["plugins"]
|
||||
}
|
34
plugins/ntp/tasks.py
Normal file
34
plugins/ntp/tasks.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
from common.tasks import packages
|
||||
|
||||
|
||||
class AddNtpPackage(Task):
|
||||
description = 'Adding NTP Package'
|
||||
phase = phases.package_installation
|
||||
successors = [packages.InstallPackages]
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
info.packages.add('ntp')
|
||||
|
||||
|
||||
class SetNtpServers(Task):
|
||||
description = 'Setting NTP servers'
|
||||
phase = phases.system_modification
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
import fileinput
|
||||
import os
|
||||
import re
|
||||
ntp_path = os.path.join(info.root, 'etc/ntp.conf')
|
||||
servers = info.manifest.plugins['ntp']['servers']
|
||||
debian_ntp_server = re.compile('.*[0-9]\.debian\.pool\.ntp\.org.*')
|
||||
for line in fileinput.input(files=ntp_path, inplace=True):
|
||||
# Will write all the specified servers on the first match, then supress all other default servers
|
||||
if re.match(debian_ntp_server, line):
|
||||
while servers:
|
||||
print 'server {server_address} iburst'.format(server_address=servers.pop(0))
|
||||
else:
|
||||
print line,
|
Loading…
Add table
Reference in a new issue