cli: add -e/--enable for enabling service at boot
This commit is contained in:
parent
e77b8f35ae
commit
f3e9d02fbc
|
@ -41,6 +41,9 @@ def main():
|
|||
parser.add_argument('-p', '--privateoff',
|
||||
action='store_true',
|
||||
help='turn off PrivateUsers mapping'),
|
||||
parser.add_argument('-e', '--enable',
|
||||
action='store_true',
|
||||
help='enable service (append it to machines.target.wants)'),
|
||||
parser.add_argument('--version', action='version',
|
||||
version='%(prog)s ' + str(dspawn.__version__))
|
||||
parser.add_argument('-v', '--verbose',
|
||||
|
|
|
@ -41,7 +41,7 @@ def use_aptcacherng():
|
|||
class Machine(object):
|
||||
def __init__(self, name, release='stable', mode='private', address=None,
|
||||
proxy=False, macaddress=None, privateoff=False, bind=None,
|
||||
**kwargs):
|
||||
enable=False, **kwargs):
|
||||
|
||||
if isinstance(name, list):
|
||||
self.name = name[0]
|
||||
|
@ -58,6 +58,7 @@ class Machine(object):
|
|||
self.macaddress = macaddress
|
||||
self.proxy = proxy
|
||||
self.mode = mode
|
||||
self.enable = enable
|
||||
self.privateoff = privateoff
|
||||
self.modelpath = ".%s-%s" % (release, defaults['arch'])
|
||||
self.config_file = '/etc/systemd/nspawn/%s.nspawn' % self.name
|
||||
|
@ -81,6 +82,8 @@ class Machine(object):
|
|||
|
||||
def config(self):
|
||||
self.configuration.realize()
|
||||
if self.enable:
|
||||
os.system('systemctl enable systemd-nspawn@$%s.service' % self.name)
|
||||
|
||||
def start(self):
|
||||
os.system('machinectl start %s' % self.name)
|
||||
|
|
Loading…
Reference in New Issue