misc: use logging library
This commit is contained in:
parent
723e39ad4d
commit
69188d60a6
|
@ -6,4 +6,8 @@ container creations, support various network configurations, uses apt-cacher-ng
|
|||
if available, and more (note: for zone network setup, please systemctl enable
|
||||
systemd-networkd)"""
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__version__ = 0.6
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import dspawn
|
||||
from dspawn.container import Machine
|
||||
import argparse
|
||||
import dspawn
|
||||
from dspawn import logger
|
||||
from dspawn.container import Machine
|
||||
|
||||
|
||||
machinectl_actions = ['list', 'list-images', 'start', 'stop', 'show',
|
||||
|
@ -40,7 +41,7 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
if args.address and args.mode == 'private':
|
||||
print('Notice: auto-selecting zone network mode, required with static address')
|
||||
logger.info('Notice: auto-selecting zone network mode, required with static address')
|
||||
args.mode = 'zone'
|
||||
|
||||
if args.action == 'create' or args.action == 'config':
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import glob
|
||||
import apt
|
||||
from dspawn import logger
|
||||
from dspawn.netconf import MachineConfig
|
||||
|
||||
|
||||
|
@ -80,7 +81,7 @@ class Machine(object):
|
|||
|
||||
def create(self):
|
||||
if self.exist():
|
||||
print('container "%s" already exists' % self.name)
|
||||
logger.warning('container "%s" already exists' % self.name)
|
||||
self.start()
|
||||
return
|
||||
|
||||
|
@ -88,7 +89,7 @@ class Machine(object):
|
|||
if not model.exist():
|
||||
model._create()
|
||||
|
||||
print('copying base model %s to %s' % (model.path, self.path))
|
||||
logger.debug('copying base model %s to %s' % (model.path, self.path))
|
||||
# shutil.copytree(model.path, self.path, symlinks=True)
|
||||
os.system('cp -r %s %s' % (model.path, self.path))
|
||||
self.copy_keys()
|
||||
|
@ -97,10 +98,10 @@ class Machine(object):
|
|||
self.start()
|
||||
|
||||
def _create(self):
|
||||
print('creating base model %s' % self.path)
|
||||
logger.info('creating base model %s' % self.path)
|
||||
if use_aptcacherng():
|
||||
env = 'http_proxy=http://localhost:3142 '
|
||||
print('Found apt-cacher-ng process, using it (%s)' % env)
|
||||
logger.info('Found apt-cacher-ng process, using it (%s)' % env)
|
||||
else:
|
||||
env = ''
|
||||
bootstrap = '%sdebootstrap %s %s %s' % (
|
||||
|
@ -111,7 +112,7 @@ class Machine(object):
|
|||
os.system('rm -r %s/var/lib/apt/lists/*' % self.path)
|
||||
|
||||
def chroot(self, command):
|
||||
print('in chroot: %s' % command)
|
||||
logger.debug('in chroot: %s' % command)
|
||||
cmd = "chroot %s /bin/bash -c '%s'" % (self.path, command)
|
||||
os.system(cmd)
|
||||
|
||||
|
|
Loading…
Reference in New Issue