Merge lp:~billy-olsen/maas-deployer/add-virsh-power into lp:~maas-deployers/maas-deployer/next

Proposed by Billy Olsen
Status: Merged
Merged at revision: 25
Proposed branch: lp:~billy-olsen/maas-deployer/add-virsh-power
Merge into: lp:~maas-deployers/maas-deployer/next
Diff against target: 172 lines (+80/-13)
3 files modified
examples/deployment.yaml (+10/-2)
maas_deployer/vmaas/engine.py (+70/-9)
maas_deployer/vmaas/templates/config-maas.sh (+0/-2)
To merge this branch: bzr merge lp:~billy-olsen/maas-deployer/add-virsh-power
Reviewer Review Type Date Requested Status
Edward Hope-Morley Needs Fixing
Review via email: mp+268361@code.launchpad.net
To post a comment you must log in.
14. By Billy Olsen

Rebase to latest from next

Revision history for this message
Edward Hope-Morley (hopem) wrote :

Hey Billy a few points here:

You are creating and installing keys to /home/maas/.ssh but the maas user created on installing has its home path set as follows:

    ubuntu@localhost:~$ echo ~maas
    /var/lib/maas

If i put my keys in /home/maas/.ssh maas is unable to find them whereas if i put them in /var/lib/maas/.ssh everything work fine and dandy.

Few more inline comments.

Revision history for this message
Edward Hope-Morley (hopem) :
review: Needs Fixing
15. By Billy Olsen

Code review feedback and merge with latest in /next

16. By Billy Olsen

Cleanup config-maas.sh to just use whatever the current maas home directory is

17. By Billy Olsen

Merge with /next one more time

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/deployment.yaml'
2--- examples/deployment.yaml 2015-08-20 04:57:32 +0000
3+++ examples/deployment.yaml 2015-08-25 20:14:09 +0000
4@@ -21,6 +21,16 @@
5 # Apt http proxy setting(s)
6 apt_http_proxy:
7
8+ # Virsh power settings
9+ # Specifies the uri and keys to use for virsh power control of the
10+ # juju virtual machine. If the uri is omitted, the value for the
11+ # --remote is used. If no power settings are desired, then do not
12+ # supply the virsh block.
13+ #virsh:
14+ # rsa_priv_key: /path/to/id_rsa
15+ # rsa_pub_key: /path/to/id_rsa.pub
16+ # uri: qemu+ssh://user@10.0.3.1/system
17+
18 # Defines the IP Address that the configuration script will use to
19 # to access the MAAS controller via SSH.
20 ip_address: 192.168.122.2
21@@ -33,8 +43,6 @@
22 main_archive: http://archive.ubuntu.com/ubuntu
23 upstream_dns: 192.168.122.1
24 maas_name: automaas
25- # kernel_opts: "console=tty0 console=ttyS1,115200n8"
26- # ntp_server: ntp.ubuntu.com
27
28 # This section is used to define the networking parameters for when
29 # the node first comes up. It is fed into the meta-data cloud-init
30
31=== modified file 'maas_deployer/vmaas/engine.py'
32--- maas_deployer/vmaas/engine.py 2015-08-21 17:12:13 +0000
33+++ maas_deployer/vmaas/engine.py 2015-08-25 20:14:09 +0000
34@@ -47,38 +47,53 @@
35 config = self.config.get(target)
36 juju_config = config.get('juju-bootstrap')
37 juju_domain = self.deploy_juju_bootstrap(juju_config)
38+ maas_config = config.get('maas')
39
40 # Insert juju node information into the maas nodes list.
41 # This allows us to define it in maas.
42- juju_node = self._get_juju_node_params(juju_domain)
43+ juju_node = self._get_juju_node_params(juju_domain, maas_config)
44
45- maas_config = config.get('maas')
46 nodes = maas_config.get('nodes', [])
47- if nodes:
48- nodes.append(juju_node)
49+ if not nodes:
50+ log.warning("No MAAS cluster nodes provided")
51 maas_config['nodes'] = nodes
52- else:
53- log.warning("No MAAS cluster nodes provided")
54+
55+ nodes.append(juju_node)
56
57 self.deploy_maas_node(maas_config)
58
59 self.wait_for_maas_installation(maas_config)
60+ self.configure_maas_virsh_control(maas_config)
61 self.api_key = self._get_api_key(maas_config)
62 self.wait_for_import_boot_images(maas_config)
63
64 self.configure_maas(maas_config)
65
66- def _get_juju_node_params(self, juju_domain):
67+ def _get_juju_node_params(self, juju_domain, maas_config):
68 """
69 Determines the mac address of the juju machine specified.
70+
71+ :param juju_domain: the juju bootstrap image domain
72+ :param include_power: a boolean value of whether to include
73+ power parameters or not for virsh power
74+ control.
75 """
76 node = {
77 'name': juju_domain.name,
78 'architecture': 'amd64/generic',
79 'mac_addresses': [x for x in juju_domain.mac_addresses],
80- 'tags': 'bootstrap',
81+ 'tags': 'bootstrap'
82 }
83
84+ virsh_info = maas_config.get('virsh')
85+ if virsh_info:
86+ uri = virsh_info.get('uri', util.CONF.remote)
87+ node.update({
88+ 'power_type': 'virsh',
89+ 'power_parameters_power_address': uri,
90+ 'power_parameters_power_id': juju_domain.name,
91+ })
92+
93 return node
94
95 def deploy_juju_bootstrap(self, params):
96@@ -222,6 +237,51 @@
97
98 return self.api_key
99
100+ def configure_maas_virsh_control(self, maas_config):
101+ """Configure the virsh control SSH keys"""
102+ virsh_info = maas_config.get('virsh')
103+ if not virsh_info:
104+ log.debug('No virsh specified in maas_config.')
105+ return
106+
107+ KEY_TO_FILE_MAP = {
108+ 'rsa_priv_key': 'id_rsa',
109+ 'rsa_pub_key': 'id_rsa.pub',
110+ 'dsa_priv_key': 'id_dsa',
111+ 'dsa_pub_key': 'id_dsa.pub',
112+ }
113+
114+ # First, make the remote directory.
115+ remote_cmd = ['mkdir', 'virsh-keys']
116+ cmd = self.get_ssh_cmd(maas_config['user'], self.ip_addr,
117+ remote_cmd=remote_cmd)
118+ util.execc(cmd)
119+
120+ for key, value in virsh_info.iteritems():
121+ # not a key of interest
122+ if not key.endswith('_key'):
123+ continue
124+
125+ try:
126+ dest_file = 'virsh-keys/%s' % KEY_TO_FILE_MAP[key]
127+ cmd = self.get_scp_cmd(maas_config['user'], self.ip_addr,
128+ os.path.expanduser(value), dest_file)
129+ util.execc(cmd)
130+ except:
131+ log.error("Error reading from %s file" % value)
132+
133+ # Now move them over to the maas user.
134+ script = """
135+ maas_home=$(echo ~maas)
136+ sudo mkdir -p $maas_home/.ssh
137+ sudo mv ~/virsh-keys/* $maas_home/.ssh
138+ sudo chown -R maas:maas $maas_home/.ssh
139+ sudo chmod 700 $maas_home/.ssh
140+ sudo find $maas_home/.ssh -name id* | xargs sudo chmod 600
141+ rmdir ~/virsh-keys
142+ """
143+ util.exec_script_remote(maas_config['user'], self.ip_addr, script)
144+
145 def wait_for_import_boot_images(self, maas_config):
146 """Polls the import boot image status."""
147 log.debug("Importing boot images...")
148@@ -404,8 +464,9 @@
149 util.exec_script_remote(maas_config['user'], self.ip_addr, script)
150
151 # Start juju domain
152+ virsh_info = maas_config.get('virsh')
153 juju_node = self._get_juju_nodename(nodes)
154- if juju_node is not None:
155+ if juju_node is not None and not virsh_info:
156 util.virsh(['start', juju_node])
157
158 self._wait_for_nodes_to_commission(client)
159
160=== modified file 'maas_deployer/vmaas/templates/config-maas.sh'
161--- maas_deployer/vmaas/templates/config-maas.sh 2015-08-19 13:58:28 +0000
162+++ maas_deployer/vmaas/templates/config-maas.sh 2015-08-25 20:14:09 +0000
163@@ -62,9 +62,7 @@
164 # Create a juju user
165 sudo adduser --disabled-password --gecos "Juju,,," juju
166
167-
168 # Kick off the boot-resources import
169 echo "Starting the import of boot resources"
170 maas maas boot-resources import
171
172-

Subscribers

People subscribed via source and target branches