4
4
from base64 import b64decode
5
5
from copy import deepcopy
6
from subprocess import check_call
6
from subprocess import check_call, check_output
8
8
from charmhelpers.core.hookenv import (
39
39
'services': ['libvirt-bin'],
42
'/etc/libvirt/libvirtd.conf': {
43
'services': ['libvirt-bin'],
44
'contexts': [NovaComputeLibvirtContext()],
42
46
'/etc/default/libvirt-bin': {
43
47
'services': ['libvirt-bin'],
44
48
'contexts': [NovaComputeLibvirtContext()],
236
def initialize_ssh_keys():
243
def initialize_ssh_keys(user='root'):
244
home_dir = pwd.getpwnam(user).pw_dir
245
ssh_dir = os.path.join(home_dir, '.ssh')
246
if not os.path.isdir(ssh_dir):
249
priv_key = os.path.join(ssh_dir, 'id_rsa')
250
if not os.path.isfile(priv_key):
251
log('Generating new ssh key for user %s.' % user)
252
cmd = ['ssh-keygen', '-q', '-N', '', '-t', 'rsa', '-b', '2048',
256
pub_key = '%s.pub' % priv_key
257
if not os.path.isfile(pub_key):
258
log('Generating missing ssh public key @ %s.' % pub_key)
259
cmd = ['ssh-keygen', '-y', '-f', priv_key]
260
p = check_output(cmd).strip()
261
with open(pub_key, 'wb') as out:
263
check_output(['chown', '-R', user, ssh_dir])
240
266
def import_authorized_keys(user='root'):
244
270
# XXX: Should this be managed via templates + contexts?
245
271
hosts = relation_get('known_hosts')
246
272
auth_keys = relation_get('authorized_keys')
247
if None in [hosts, auth_keys]:
273
# XXX: Need to fix charm-helpers to return None for empty settings,
275
if not hosts or not auth_keys:
250
278
dest = os.path.join(pwd.getpwnam(user).pw_dir, '.ssh')
251
279
log('Saving new known_hosts and authorized_keys file to: %s.' % dest)
253
with open(os.path.join(dest, 'authorized_keys')) as _keys:
281
with open(os.path.join(dest, 'authorized_keys'), 'wb') as _keys:
254
282
_keys.write(b64decode(auth_keys))
255
with open(os.path.join(dest, 'known_hosts')) as _hosts:
283
with open(os.path.join(dest, 'known_hosts'), 'wb') as _hosts:
256
284
_hosts.write(b64decode(hosts))
258
287
def configure_live_migration(configs=None):
260
289
Ensure libvirt live migration is properly configured or disabled,