~ubuntu-branches/ubuntu/saucy/nova/saucy-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
  • Date: 2013-02-22 09:27:29 UTC
  • mfrom: (1.1.68)
  • Revision ID: package-import@ubuntu.com-20130222092729-nn3gt8rf97uvts77
Tags: 2013.1.g3-0ubuntu1
[ Chuck Short ]
* New usptream release. 
* debian/patches/debian/patches/fix-ubuntu-tests.patch: Refreshed.
* debian/nova-baremetal.logrotate: Fix logfile path.
* debian/control, debian/nova-spiceproxy.{install, logrotate, upstart}:
  Add spice html5 proxy support.
* debian/nova-novncproxy.upstart: Start on runlevel [2345]
* debian/rules: Call testr directly since run_tests.sh -N gives weird return
  value when tests pass.
* debian/pyddist-overrides: Add websockify.
* debian/nova-common.postinst: Removed config file conversion, since
  the option is no longer available. (LP: #1110567)
* debian/control: Add python-pyasn1 as a dependency.
* debian/control: Add python-oslo-config as a dependency.
* debian/control: Suggest sysfsutils, sg3-utils, multipath-tools for fibre
  channel support.

[ Adam Gandelman ]
* debian/control: Fix typo (websocikfy -> websockify).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    License for the specific language governing permissions and limitations
15
15
#    under the License.
16
16
 
 
17
import contextlib
17
18
import ftplib
18
19
import os
 
20
import uuid
19
21
 
20
22
import paramiko
21
23
 
22
24
from nova import exception as nova_exception
23
25
from nova.openstack.common import log as logging
 
26
from nova import utils
24
27
from nova.virt.powervm import exception
25
28
 
26
29
LOG = logging.getLogger(__name__)
85
88
            raise nova_exception.ProcessExecutionError(exit_code=exit_status,
86
89
                                                       stdout=stdout,
87
90
                                                       stderr=stderr,
88
 
                                                       cmd=' '.join(cmd))
 
91
                                                       cmd=''.join(cmd))
89
92
 
90
93
    return (stdout, stderr)
91
94
 
154
157
 
155
158
    final_path = path_one + '/' + path_two
156
159
    return final_path
 
160
 
 
161
 
 
162
@contextlib.contextmanager
 
163
def vios_to_vios_auth(source, dest, conn_info):
 
164
    """Context allowing for SSH between VIOS partitions
 
165
 
 
166
    This context will build an SSH key on the source host, put the key
 
167
    into the authorized_keys on the destination host, and make the
 
168
    private key file name available within the context.
 
169
    The key files and key inserted into authorized_keys will be
 
170
    removed when the context exits.
 
171
 
 
172
    :param source: source IP or DNS name
 
173
    :param dest: destination IP or DNS name
 
174
    :param conn_info: dictionary object with SSH connection
 
175
                      information for both hosts
 
176
    """
 
177
    KEY_BASE_NAME = "os-%s" % uuid.uuid4().hex
 
178
    keypair_uuid = uuid.uuid4()
 
179
    src_conn_obj = ssh_connect(conn_info)
 
180
 
 
181
    dest_conn_info = Connection(dest, conn_info.username,
 
182
                                       conn_info.password)
 
183
    dest_conn_obj = ssh_connect(dest_conn_info)
 
184
 
 
185
    def run_command(conn_obj, cmd):
 
186
        stdout, stderr = utils.ssh_execute(conn_obj, cmd)
 
187
        return stdout.strip().splitlines()
 
188
 
 
189
    def build_keypair_on_source():
 
190
        mkkey = ('ssh-keygen -f %s -N "" -C %s' %
 
191
                    (KEY_BASE_NAME, keypair_uuid.hex))
 
192
        ssh_command_as_root(src_conn_obj, mkkey)
 
193
 
 
194
        chown_key = ('chown %s %s*' % (conn_info.username, KEY_BASE_NAME))
 
195
        ssh_command_as_root(src_conn_obj, chown_key)
 
196
 
 
197
        cat_key = ('cat %s.pub' % KEY_BASE_NAME)
 
198
        pubkey = run_command(src_conn_obj, cat_key)
 
199
 
 
200
        return pubkey[0]
 
201
 
 
202
    def cleanup_key_on_source():
 
203
        rmkey = 'rm %s*' % KEY_BASE_NAME
 
204
        run_command(src_conn_obj, rmkey)
 
205
 
 
206
    def insert_into_authorized_keys(public_key):
 
207
        echo_key = 'echo "%s" >> .ssh/authorized_keys' % public_key
 
208
        ssh_command_as_root(dest_conn_obj, echo_key)
 
209
 
 
210
    def remove_from_authorized_keys():
 
211
        rmkey = ('sed /%s/d .ssh/authorized_keys > .ssh/authorized_keys' %
 
212
                 keypair_uuid.hex)
 
213
        ssh_command_as_root(dest_conn_obj, rmkey)
 
214
 
 
215
    public_key = build_keypair_on_source()
 
216
    insert_into_authorized_keys(public_key)
 
217
 
 
218
    try:
 
219
        yield KEY_BASE_NAME
 
220
    finally:
 
221
        remove_from_authorized_keys()
 
222
        cleanup_key_on_source()