Merge ~afreiberger/charm-juju-lxd:init_with_dir_storage into charm-juju-lxd:master

Proposed by Drew Freiberger
Status: Merged
Approved by: Paul Goins
Approved revision: e7e37402e4f66bae0a1070ee9ff8e0db22fded33
Merged at revision: e7e37402e4f66bae0a1070ee9ff8e0db22fded33
Proposed branch: ~afreiberger/charm-juju-lxd:init_with_dir_storage
Merge into: charm-juju-lxd:master
Diff against target: 141 lines (+52/-12)
4 files modified
config.yaml (+1/-1)
files/lxd-profile-dir.yaml (+32/-0)
metadata.yaml (+1/-0)
reactive/juju_lxd.py (+18/-11)
Reviewer Review Type Date Requested Status
Paul Goins Approve
Drew Freiberger (community) Needs Resubmitting
Review via email: mp+369833@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alvaro Uria (aluria) wrote :

Please see comment inline. Other than that, +1

Revision history for this message
Drew Freiberger (afreiberger) wrote :

The condition is trapped higher up, and I'd rather not spend too much time reworking this to set status per group when most situations only support the one group ATM.

review: Needs Resubmitting
Revision history for this message
Drew Freiberger (afreiberger) wrote :

This branch is in-use on charmlab and is ready to merge with master.

review: Needs Resubmitting
Revision history for this message
Paul Goins (vultaire) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/config.yaml b/config.yaml
index 8db0ec4..0548271 100644
--- a/config.yaml
+++ b/config.yaml
@@ -2,7 +2,7 @@ options:
2 lxd-group:2 lxd-group:
3 type: string3 type: string
4 default: "bootstack-squad"4 default: "bootstack-squad"
5 description: user group that should have members added to local lxd group5 description: user group that should have members added to local lxd group (additional groups can be added with comma separation)
6 use-zfs:6 use-zfs:
7 type: boolean7 type: boolean
8 default: false8 default: false
diff --git a/files/lxd-profile-dir.yaml b/files/lxd-profile-dir.yaml
9new file mode 1006449new file mode 100644
index 0000000..fb1f463
--- /dev/null
+++ b/files/lxd-profile-dir.yaml
@@ -0,0 +1,32 @@
1name: juju-default
2config:
3 boot.autostart: "false"
4 security.nesting: "true"
5 security.privileged: "true"
6 linux.kernel_modules: openvswitch,nbd,ip_tables,ip6_tables
7devices:
8 eth0:
9 mtu: "9000"
10 name: eth0
11 nictype: bridged
12 parent: lxdbr0
13 type: nic
14 eth1:
15 mtu: "9000"
16 name: eth1
17 nictype: bridged
18 parent: lxdbr0
19 type: nic
20 kvm:
21 path: /dev/kvm
22 type: unix-char
23 mem:
24 path: /dev/mem
25 type: unix-char
26 root:
27 path: /
28 type: disk
29 pool: default
30 tun:
31 path: /dev/net/tun
32 type: unix-char
diff --git a/files/lxd-profile.yaml b/files/lxd-profile-zfs.yaml
0similarity index 100%33similarity index 100%
1rename from files/lxd-profile.yaml34rename from files/lxd-profile.yaml
2rename to files/lxd-profile-zfs.yaml35rename to files/lxd-profile-zfs.yaml
diff --git a/metadata.yaml b/metadata.yaml
index 7791876..d408c34 100644
--- a/metadata.yaml
+++ b/metadata.yaml
@@ -6,6 +6,7 @@ description: |
6 on a juju managed node that will run openstack-on-lxd bundle from james-page.6 on a juju managed node that will run openstack-on-lxd bundle from james-page.
7series:7series:
8 - xenial8 - xenial
9 - bionic
9tags:10tags:
10 - juju11 - juju
11 - lxd12 - lxd
diff --git a/reactive/juju_lxd.py b/reactive/juju_lxd.py
index c6c83ff..c8a1cca 100644
--- a/reactive/juju_lxd.py
+++ b/reactive/juju_lxd.py
@@ -50,21 +50,21 @@ def status_set(state, message):
50@when_not('juju-lxd.configured')50@when_not('juju-lxd.configured')
51def juju_lxd_configure():51def juju_lxd_configure():
52 config = hookenv.config()52 config = hookenv.config()
53 src_group = config.get('lxd-group')53 src_groups = config.get('lxd-group').split(',')
54 dst_group = 'lxd'54 dst_group = 'lxd'
5555
56 if group_exists(dst_group):56 if group_exists(dst_group):
57 try:57 try:
58 sync_groups(src=src_group, dst='lxd')58 sync_groups(src_groups=src_groups, dst='lxd')
59 except KeyError:59 except KeyError:
60 status_set('blocked',60 status_set('blocked',
61 'lxd-group "{0}" does not exist'.format(src_group))61 'lxd-group "{0}" does not exist'.format(src_groups))
62 finally:62 finally:
63 data_changed('juju-lxd.config', config)63 data_changed('juju-lxd.config', config)
64 set_state('juju-lxd.configured')64 set_state('juju-lxd.configured')
65 status_set('active', 'Ready')65 status_set('active', 'Ready')
66 else:66 else:
67 status_set('blocked', 'group "{0}" does not exist'.format(dst_group))67 status_set('blocked', 'LXD group "{0}" does not exist'.format(dst_group))
6868
6969
70@when('juju-lxd.configured')70@when('juju-lxd.configured')
@@ -95,7 +95,7 @@ def lxd_init():
95 subprocess.call(['lxc', 'network', 'delete', 'lxdbr0'])95 subprocess.call(['lxc', 'network', 'delete', 'lxdbr0'])
96 subprocess.call(['lxc', 'network', 'create', 'lxdbr0',96 subprocess.call(['lxc', 'network', 'create', 'lxdbr0',
97 'ipv4.address=10.0.8.1/24', 'ipv6.address=none',97 'ipv4.address=10.0.8.1/24', 'ipv6.address=none',
98 'ipv4.nat=true'])98 'ipv4.nat=true', 'ipv4.dhcp.ranges=10.0.8.2-10.0.8.200'])
99 subprocess.call(['lxc', 'network', 'attach-profile', 'lxdbr0', 'default',99 subprocess.call(['lxc', 'network', 'attach-profile', 'lxdbr0', 'default',
100 'eth0'])100 'eth0'])
101 subprocess.call(['lxc', 'profile', 'device', 'set', 'default', 'eth0',101 subprocess.call(['lxc', 'profile', 'device', 'set', 'default', 'eth0',
@@ -106,7 +106,11 @@ def lxd_init():
106 except:106 except:
107 pass107 pass
108108
109 with open('files/lxd-profile.yaml', 'r') as profileyaml:109 if use_zfs:
110 default_profile_yaml = 'files/lxd-profile-zfs.yaml'
111 else:
112 default_profile_yaml = 'files/lxd-profile-dir.yaml'
113 with open(default_profile_yaml, 'r') as profileyaml:
110 try:114 try:
111 subprocess.check_output(['lxc', 'profile', 'edit', 'juju-default'],115 subprocess.check_output(['lxc', 'profile', 'edit', 'juju-default'],
112 stdin=profileyaml)116 stdin=profileyaml)
@@ -124,13 +128,16 @@ def git_repo():
124 pass128 pass
125129
126130
127def sync_groups(src, dst):131def sync_groups(src_groups, dst):
128 ''' Makes the dst group contain the same users as the src group.132 ''' Makes the dst group contain the same users as the src group.
129 If src is empty, the dst group will be emptied too'''133 If src is empty, the dst group will be emptied too'''
130 # Will raise KeyError if src is empty or non-existent134 # Will raise KeyError if src is empty or non-existent
131 if src in [None, '']:135 members = []
132 users = ''136 for group in src_groups:
133 else:137 if group not in [None, '']:
134 users = ','.join(grp.getgrnam(src).gr_mem)138 members.extend(grp.getgrnam(group).gr_mem)
139 # using set to create unique list of members
140 users = ','.join(list(set(members)))
135 status_set("maintenance", "configuring users in lxd group")141 status_set("maintenance", "configuring users in lxd group")
136 subprocess.call(['gpasswd', '-M', users, dst])142 subprocess.call(['gpasswd', '-M', users, dst])
143

Subscribers

People subscribed via source and target branches

to all changes: