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
1diff --git a/config.yaml b/config.yaml
2index 8db0ec4..0548271 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -2,7 +2,7 @@ options:
6 lxd-group:
7 type: string
8 default: "bootstack-squad"
9- description: user group that should have members added to local lxd group
10+ description: user group that should have members added to local lxd group (additional groups can be added with comma separation)
11 use-zfs:
12 type: boolean
13 default: false
14diff --git a/files/lxd-profile-dir.yaml b/files/lxd-profile-dir.yaml
15new file mode 100644
16index 0000000..fb1f463
17--- /dev/null
18+++ b/files/lxd-profile-dir.yaml
19@@ -0,0 +1,32 @@
20+name: juju-default
21+config:
22+ boot.autostart: "false"
23+ security.nesting: "true"
24+ security.privileged: "true"
25+ linux.kernel_modules: openvswitch,nbd,ip_tables,ip6_tables
26+devices:
27+ eth0:
28+ mtu: "9000"
29+ name: eth0
30+ nictype: bridged
31+ parent: lxdbr0
32+ type: nic
33+ eth1:
34+ mtu: "9000"
35+ name: eth1
36+ nictype: bridged
37+ parent: lxdbr0
38+ type: nic
39+ kvm:
40+ path: /dev/kvm
41+ type: unix-char
42+ mem:
43+ path: /dev/mem
44+ type: unix-char
45+ root:
46+ path: /
47+ type: disk
48+ pool: default
49+ tun:
50+ path: /dev/net/tun
51+ type: unix-char
52diff --git a/files/lxd-profile.yaml b/files/lxd-profile-zfs.yaml
53similarity index 100%
54rename from files/lxd-profile.yaml
55rename to files/lxd-profile-zfs.yaml
56diff --git a/metadata.yaml b/metadata.yaml
57index 7791876..d408c34 100644
58--- a/metadata.yaml
59+++ b/metadata.yaml
60@@ -6,6 +6,7 @@ description: |
61 on a juju managed node that will run openstack-on-lxd bundle from james-page.
62 series:
63 - xenial
64+ - bionic
65 tags:
66 - juju
67 - lxd
68diff --git a/reactive/juju_lxd.py b/reactive/juju_lxd.py
69index c6c83ff..c8a1cca 100644
70--- a/reactive/juju_lxd.py
71+++ b/reactive/juju_lxd.py
72@@ -50,21 +50,21 @@ def status_set(state, message):
73 @when_not('juju-lxd.configured')
74 def juju_lxd_configure():
75 config = hookenv.config()
76- src_group = config.get('lxd-group')
77+ src_groups = config.get('lxd-group').split(',')
78 dst_group = 'lxd'
79
80 if group_exists(dst_group):
81 try:
82- sync_groups(src=src_group, dst='lxd')
83+ sync_groups(src_groups=src_groups, dst='lxd')
84 except KeyError:
85 status_set('blocked',
86- 'lxd-group "{0}" does not exist'.format(src_group))
87+ 'lxd-group "{0}" does not exist'.format(src_groups))
88 finally:
89 data_changed('juju-lxd.config', config)
90 set_state('juju-lxd.configured')
91 status_set('active', 'Ready')
92 else:
93- status_set('blocked', 'group "{0}" does not exist'.format(dst_group))
94+ status_set('blocked', 'LXD group "{0}" does not exist'.format(dst_group))
95
96
97 @when('juju-lxd.configured')
98@@ -95,7 +95,7 @@ def lxd_init():
99 subprocess.call(['lxc', 'network', 'delete', 'lxdbr0'])
100 subprocess.call(['lxc', 'network', 'create', 'lxdbr0',
101 'ipv4.address=10.0.8.1/24', 'ipv6.address=none',
102- 'ipv4.nat=true'])
103+ 'ipv4.nat=true', 'ipv4.dhcp.ranges=10.0.8.2-10.0.8.200'])
104 subprocess.call(['lxc', 'network', 'attach-profile', 'lxdbr0', 'default',
105 'eth0'])
106 subprocess.call(['lxc', 'profile', 'device', 'set', 'default', 'eth0',
107@@ -106,7 +106,11 @@ def lxd_init():
108 except:
109 pass
110
111- with open('files/lxd-profile.yaml', 'r') as profileyaml:
112+ if use_zfs:
113+ default_profile_yaml = 'files/lxd-profile-zfs.yaml'
114+ else:
115+ default_profile_yaml = 'files/lxd-profile-dir.yaml'
116+ with open(default_profile_yaml, 'r') as profileyaml:
117 try:
118 subprocess.check_output(['lxc', 'profile', 'edit', 'juju-default'],
119 stdin=profileyaml)
120@@ -124,13 +128,16 @@ def git_repo():
121 pass
122
123
124-def sync_groups(src, dst):
125+def sync_groups(src_groups, dst):
126 ''' Makes the dst group contain the same users as the src group.
127 If src is empty, the dst group will be emptied too'''
128 # Will raise KeyError if src is empty or non-existent
129- if src in [None, '']:
130- users = ''
131- else:
132- users = ','.join(grp.getgrnam(src).gr_mem)
133+ members = []
134+ for group in src_groups:
135+ if group not in [None, '']:
136+ members.extend(grp.getgrnam(group).gr_mem)
137+ # using set to create unique list of members
138+ users = ','.join(list(set(members)))
139 status_set("maintenance", "configuring users in lxd group")
140 subprocess.call(['gpasswd', '-M', users, dst])
141+

Subscribers

People subscribed via source and target branches

to all changes: