~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/powervm/common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman, Yolanda Robla, James Page
  • Date: 2013-01-11 13:06:56 UTC
  • mfrom: (1.1.67)
  • Revision ID: package-import@ubuntu.com-20130111130656-7n7fkevy03stm3mv
Tags: 2013.1~g2-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/ubuntu-show-tests.patch: Dropped no longer needed.
* debian/nova-xcp-plugins.install: Fix xcp-plugins empty packages
* debian/control: Drop python-nose in favor or testrepository
* debian/control: Add python-coverage as a build dep.
* debian/rules, debian/control: Run pep8 tests.
* debian/*.init: Remove they are not needed and take up space
* debian/control, debian/nova-cells.{install, logrotate, upstart}: Add
  cells support.
* debian/patches/fix-ubuntu-tests.patch: temporarily disable failing tests.
* debian/control, debian/nova-baremetal.{install, logrotate, upstart}: Add
  nova baremetal support.
* debian/control: Remove python-support.

[ Adam Gandelman ]
* debian/*.manpages: Install Sphinx-generated manpages instead of
  our own.
* debian/nova-compute-*.conf: Specify the newly required compute_driver
  flag in addition to libvirt_type.
* debian/control:  Specify required python-webob and python-stevedore
  versions.

[ Yolanda Robla ]
* debian/*.upstart: Use start-stop-daemon instead of su for chuid
  (LP: #1086833).
* debian/rules: Remove override of dh_installinit for discriminating
  between Debian and Ubuntu.
* debian/nova-common.docs: Installing changelogs from rules
* debian/rules: Replacing perms in /etc/nova/logging.conf for 0644
* debian/control: adduser dependency on nova-compute.
* debian/control: added section oldlibs and priority extra on
  nova-ajax-console-proxy.
* debian/nova-xvpvncproxy.postrm: removing because of duplicates.

[ James Page ]
* d/control: Add ~ to python-sqlalchemy-ext versioned dependencies to
  make backporting easier.
* d/control: Updated nova-volume description and depdendencies to
  mark it as a transitional package, moved to oldlibs/extra.
* d/p/fix-libvirt-tests.patch: Dropped; accepted upstream.
* d/control: Added python-stevedore to BD's.
* d/*.postrm: Dropped postrm's that just run update-rc.d; this is not
  required when deploying upstart configurations only.
* d/nova-scheduler.manpages: Add man page for nova-rpc-zmq-receiver.
* d/rules: Install upstream changelog with a policy compliant name.
* d/control: Mark nova-compute-xcp as virtual package.
* d/control: nova-api-os-volume; Depend on cinder-api and mark as
  transitional package.
* d/nova-api-os-volume.lintian-overrides: Dropped - no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
2
 
3
 
# Copyright 2012 IBM Corp.
 
3
# Copyright 2012 IBM
4
4
#
5
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
6
#    not use this file except in compliance with the License. You may obtain
14
14
#    License for the specific language governing permissions and limitations
15
15
#    under the License.
16
16
 
17
 
import contextlib
18
17
import ftplib
19
18
import os
20
 
import uuid
21
19
 
22
20
import paramiko
23
21
 
24
22
from nova import exception as nova_exception
25
23
from nova.openstack.common import log as logging
26
 
from nova import utils
27
24
from nova.virt.powervm import exception
28
25
 
29
26
LOG = logging.getLogger(__name__)
31
28
 
32
29
class Connection(object):
33
30
 
34
 
    def __init__(self, host, username, password, port=22, keyfile=None):
 
31
    def __init__(self, host, username, password, port=22):
35
32
        self.host = host
36
33
        self.username = username
37
34
        self.password = password
38
35
        self.port = port
39
 
        self.keyfile = keyfile
40
36
 
41
37
 
42
38
def ssh_connect(connection):
52
48
        ssh.connect(connection.host,
53
49
                    username=connection.username,
54
50
                    password=connection.password,
55
 
                    port=connection.port,
56
 
                    key_filename=connection.keyfile)
 
51
                    port=connection.port)
57
52
        return ssh
58
53
    except Exception:
59
54
        LOG.exception(_('Connection error connecting PowerVM manager'))
90
85
            raise nova_exception.ProcessExecutionError(exit_code=exit_status,
91
86
                                                       stdout=stdout,
92
87
                                                       stderr=stderr,
93
 
                                                       cmd=''.join(cmd))
 
88
                                                       cmd=' '.join(cmd))
94
89
 
95
90
    return (stdout, stderr)
96
91
 
159
154
 
160
155
    final_path = path_one + '/' + path_two
161
156
    return final_path
162
 
 
163
 
 
164
 
@contextlib.contextmanager
165
 
def vios_to_vios_auth(source, dest, conn_info):
166
 
    """Context allowing for SSH between VIOS partitions
167
 
 
168
 
    This context will build an SSH key on the source host, put the key
169
 
    into the authorized_keys on the destination host, and make the
170
 
    private key file name available within the context.
171
 
    The key files and key inserted into authorized_keys will be
172
 
    removed when the context exits.
173
 
 
174
 
    :param source: source IP or DNS name
175
 
    :param dest: destination IP or DNS name
176
 
    :param conn_info: dictionary object with SSH connection
177
 
                      information for both hosts
178
 
    """
179
 
    KEY_BASE_NAME = "os-%s" % uuid.uuid4().hex
180
 
    keypair_uuid = uuid.uuid4()
181
 
    src_conn_obj = ssh_connect(conn_info)
182
 
 
183
 
    dest_conn_info = Connection(dest, conn_info.username,
184
 
                                       conn_info.password)
185
 
    dest_conn_obj = ssh_connect(dest_conn_info)
186
 
 
187
 
    def run_command(conn_obj, cmd):
188
 
        stdout, stderr = utils.ssh_execute(conn_obj, cmd)
189
 
        return stdout.strip().splitlines()
190
 
 
191
 
    def build_keypair_on_source():
192
 
        mkkey = ('ssh-keygen -f %s -N "" -C %s' %
193
 
                    (KEY_BASE_NAME, keypair_uuid.hex))
194
 
        ssh_command_as_root(src_conn_obj, mkkey)
195
 
 
196
 
        chown_key = ('chown %s %s*' % (conn_info.username, KEY_BASE_NAME))
197
 
        ssh_command_as_root(src_conn_obj, chown_key)
198
 
 
199
 
        cat_key = ('cat %s.pub' % KEY_BASE_NAME)
200
 
        pubkey = run_command(src_conn_obj, cat_key)
201
 
 
202
 
        return pubkey[0]
203
 
 
204
 
    def cleanup_key_on_source():
205
 
        rmkey = 'rm %s*' % KEY_BASE_NAME
206
 
        run_command(src_conn_obj, rmkey)
207
 
 
208
 
    def insert_into_authorized_keys(public_key):
209
 
        echo_key = 'echo "%s" >> .ssh/authorized_keys' % public_key
210
 
        ssh_command_as_root(dest_conn_obj, echo_key)
211
 
 
212
 
    def remove_from_authorized_keys():
213
 
        rmkey = ('sed /%s/d .ssh/authorized_keys > .ssh/authorized_keys' %
214
 
                 keypair_uuid.hex)
215
 
        ssh_command_as_root(dest_conn_obj, rmkey)
216
 
 
217
 
    public_key = build_keypair_on_source()
218
 
    insert_into_authorized_keys(public_key)
219
 
 
220
 
    try:
221
 
        yield KEY_BASE_NAME
222
 
    finally:
223
 
        remove_from_authorized_keys()
224
 
        cleanup_key_on_source()