~openstack-charmers/charms/trusty/nova-compute/lxd-updates

« back to all changes in this revision

Viewing changes to hooks/nova_compute_utils.py

  • Committer: Chuck Short
  • Date: 2015-07-24 02:24:48 UTC
  • Revision ID: zulcss@ubuntu.com-20150724022448-0j3k6232ojlognes
Refactor LXD and add build from support source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
from base64 import b64decode
6
6
from copy import deepcopy
7
 
from subprocess import check_call, check_output, CalledProcessError
 
7
from subprocess import (
 
8
    PIPE,
 
9
    Popen,
 
10
    check_call,
 
11
    check_output,
 
12
    CalledProcessError
 
13
)
8
14
 
9
15
from charmhelpers.fetch import (
10
16
    apt_update,
123
129
    'nova-compute',
124
130
    'nova-compute-kvm',
125
131
    'nova-compute-lxc',
 
132
    'nova-compute-lxd',
126
133
    'nova-compute-qemu',
127
134
    'nova-compute-uml',
128
135
    'nova-compute-xen',
578
585
    check_call(cmd)
579
586
 
580
587
 
581
 
def configure_lxd(user='nova'):
 
588
def configure_lxd(settings, user='nova'):
582
589
    ''' Configure lxd use for nova user '''
583
 
    if lsb_release()['DISTRIB_CODENAME'].lower() < "vivid":
584
 
        raise Exception("LXD is not supported for Ubuntu "
585
 
                        "versions less than 15.04 (vivid)")
 
590
    if not git_install_requested():
 
591
        if lsb_release()['DISTRIB_CODENAME'].lower() < "vivid":
 
592
            raise Exception("LXD is not supported for Ubuntu "
 
593
                            "versions less than 15.04 (vivid)")
586
594
 
587
595
    configure_subuid(user='nova')
588
 
    configure_lxd_daemon(user='nova')
 
596
    configure_lxd_daemon(settings, user='nova')
 
597
    configure_lxd_host(settings, user='nova')
589
598
 
590
599
    service_restart('nova-compute')
591
600
 
592
601
 
593
 
def configure_lxd_daemon(user):
 
602
def configure_lxd_daemon(settings, user):
594
603
    add_user_to_group(user, 'lxd')
595
604
    service_restart('lxd')
596
605
    # NOTE(jamespage): Call list function to initialize cert
603
612
    check_call(cmd)
604
613
 
605
614
 
 
615
@retry_on_exception(5, base_delay=2, exc_type=CalledProcessError)
 
616
def configure_lxd_host(settings, user):
 
617
    cmd = ['sudo', '-u', user, 'lxc', 'config', 'set',
 
618
           'core.trust_password', settings['lxd_password']]
 
619
    check_call(cmd)
 
620
 
 
621
    p = Popen(['sudo', '-u', user, 'lxc', 'remote', 'add',
 
622
               settings['lxd_hostname'], '%s:8443' % settings['lxd_address'],
 
623
               '--accept-certificate'], stdin=PIPE)
 
624
    p.communicate(input='%s\n' % settings['lxd_password'])
 
625
 
 
626
 
606
627
def configure_subuid(user):
607
628
    cmd = ['usermod', '-v', '100000-200000', '-w', '100000-200000', user]
608
629
    check_call(cmd)