Drop trust password, add peer relation for lxd migration support
This commit is contained in:
parent
e89cad554c
commit
0c33004846
|
@ -6,10 +6,6 @@ options:
|
||||||
Repository from which to install LXD. May be one of the following:
|
Repository from which to install LXD. May be one of the following:
|
||||||
distro (default), ppa:somecustom/ppa, a deb url sources entry,
|
distro (default), ppa:somecustom/ppa, a deb url sources entry,
|
||||||
or a supported release pocket
|
or a supported release pocket
|
||||||
trust-password:
|
|
||||||
type: string
|
|
||||||
default: password
|
|
||||||
description: Password to set for the LXD server.
|
|
||||||
block-device:
|
block-device:
|
||||||
type: string
|
type: string
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -10,6 +10,7 @@ from charmhelpers.core.hookenv import (
|
||||||
log,
|
log,
|
||||||
unit_get,
|
unit_get,
|
||||||
relation_set,
|
relation_set,
|
||||||
|
relation_get,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
|
@ -22,6 +23,8 @@ from lxd_utils import (
|
||||||
install_lxd_source,
|
install_lxd_source,
|
||||||
configure_lxd_source,
|
configure_lxd_source,
|
||||||
configure_lxd_block,
|
configure_lxd_block,
|
||||||
|
lxd_trust_password,
|
||||||
|
configure_lxd_remote,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
|
@ -54,16 +57,28 @@ def config_changed():
|
||||||
configure_lxd_block()
|
configure_lxd_block()
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('lxd-relation-joined')
|
@hooks.hook('lxd-relation-joined',
|
||||||
def relation_joined(rid=None):
|
'lxd-migration-relation-joined')
|
||||||
|
def lxd_relation_joined(rid=None):
|
||||||
settings = {}
|
settings = {}
|
||||||
settings['lxd_password'] = config('trust-password')
|
settings['lxd_password'] = lxd_trust_password()
|
||||||
settings['lxd_hostname'] = unit_get('private-address')
|
settings['lxd_hostname'] = gethostname()
|
||||||
settings['lxd_address'] = gethostname()
|
settings['lxd_address'] = unit_get('private-address')
|
||||||
relation_set(relation_id=rid,
|
relation_set(relation_id=rid,
|
||||||
relation_settings=settings)
|
relation_settings=settings)
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('lxd-migration-relation-changed')
|
||||||
|
def lxd_migration_relation_changed():
|
||||||
|
settings = {
|
||||||
|
'password': relation_get('lxd_password'),
|
||||||
|
'hostname': relation_get('lxd_hostname'),
|
||||||
|
'address': relation_get('lxd_address'),
|
||||||
|
}
|
||||||
|
if all(settings):
|
||||||
|
configure_lxd_remote(settings)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
hooks.execute(sys.argv)
|
hooks.execute(sys.argv)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import glob
|
||||||
import pwd
|
import pwd
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from subprocess import call, check_call
|
from subprocess import call, check_call, check_output
|
||||||
|
|
||||||
from charmhelpers.core.templating import render
|
from charmhelpers.core.templating import render
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
|
@ -10,6 +10,7 @@ from charmhelpers.core.hookenv import (
|
||||||
config,
|
config,
|
||||||
ERROR,
|
ERROR,
|
||||||
)
|
)
|
||||||
|
from charmhelpers.core.unitdata import kv
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
add_group,
|
add_group,
|
||||||
add_user_to_group,
|
add_user_to_group,
|
||||||
|
@ -17,6 +18,7 @@ from charmhelpers.core.host import (
|
||||||
mount,
|
mount,
|
||||||
service_stop,
|
service_stop,
|
||||||
service_start,
|
service_start,
|
||||||
|
pwgen,
|
||||||
)
|
)
|
||||||
from charmhelpers.contrib.storage.linux.utils import (
|
from charmhelpers.contrib.storage.linux.utils import (
|
||||||
is_block_device,
|
is_block_device,
|
||||||
|
@ -54,6 +56,7 @@ LXD_SOURCE_PACKAGES = [
|
||||||
|
|
||||||
LXD_GIT = 'github.com/lxc/lxd'
|
LXD_GIT = 'github.com/lxc/lxd'
|
||||||
DEFAULT_LOOPBACK_SIZE = '10G'
|
DEFAULT_LOOPBACK_SIZE = '10G'
|
||||||
|
PW_LENGTH = 16
|
||||||
|
|
||||||
|
|
||||||
def install_lxd():
|
def install_lxd():
|
||||||
|
@ -194,3 +197,26 @@ def determine_packages():
|
||||||
|
|
||||||
def filesystem_mounted(fs):
|
def filesystem_mounted(fs):
|
||||||
return call(['grep', '-wqs', fs, '/proc/mounts']) == 0
|
return call(['grep', '-wqs', fs, '/proc/mounts']) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def lxd_trust_password():
|
||||||
|
db = kv()
|
||||||
|
if not db.get('lxd-password'):
|
||||||
|
db.set('lxd-password', pwgen(PW_LENGTH))
|
||||||
|
return db.get('lxd-password')
|
||||||
|
|
||||||
|
|
||||||
|
def configure_lxd_remote(settings):
|
||||||
|
cmd = ['lxc', 'remote', 'list']
|
||||||
|
output = check_output(cmd)
|
||||||
|
if settings['hostname'] not in output:
|
||||||
|
cmd = ['lxc', 'remote', 'add',
|
||||||
|
settings['hostname'],
|
||||||
|
settings['address'],
|
||||||
|
'--accept-certificate',
|
||||||
|
'--password={}'.format(settings['password'])]
|
||||||
|
else:
|
||||||
|
cmd = ['lxc', 'remote', 'set-url',
|
||||||
|
settings['hostname'],
|
||||||
|
settings['address']]
|
||||||
|
check_call(cmd)
|
||||||
|
|
|
@ -7,6 +7,9 @@ tags:
|
||||||
- misc
|
- misc
|
||||||
- openstack
|
- openstack
|
||||||
subordinate: true
|
subordinate: true
|
||||||
|
peer:
|
||||||
|
lxd-migration:
|
||||||
|
interface: lxd-migration
|
||||||
provides:
|
provides:
|
||||||
lxd:
|
lxd:
|
||||||
interface: containers
|
interface: containers
|
||||||
|
|
Loading…
Reference in New Issue