def image_export(cls, source_path, dest_url, **kwargs):
        """Export the specific image to remote host or local file system """
        dest_path = urlparse.urlparse(dest_url).path
        if kwargs['remote_host']:
            target_path = ':'.join([kwargs['remote_host'], dest_path])
            command = ' '.join(['/usr/bin/scp',
                                "-P", CONF.zvm.remotehost_sshd_port,
                                "-o StrictHostKeyChecking=no",
                                '-r ', source_path, target_path])
            (rc, output) = zvmutils.execute(command)
            if rc:
                msg = ("Error happened when copying image file to remote "
                       "host with reason: %s" % output)
                LOG.error(msg)
                raise exception.SDKImageOperationError(rs=21, msg=output)
        else:
            # Copy to local file system
            LOG.debug("Remote_host not specified, will copy to local server")
            try:
                shutil.copyfile(source_path, dest_path)
            except Exception as err:
                msg = ("Export image from %(src)s to local file system"
                       " %(dest)s failed: %(err)s" %
                       {'src': source_path,
                        'dest': dest_path,
                        'err': six.text_type(err)})
                LOG.error(msg)
                raise exception.SDKImageOperationError(rs=22,
                                                       err=six.text_type(err))
def image_export ( cls , source_path , dest_url , ** kwargs ) : dest_path = urlparse . urlparse ( dest_url ) . path if kwargs [ 'remote_host' ] : target_path = ':' . join ( [ kwargs [ 'remote_host' ] , dest_path ] ) command = ' ' . join ( [ '/usr/bin/scp' , "-P" , CONF . zvm . remotehost_sshd_port , "-o StrictHostKeyChecking=no" , '-r ' , source_path , target_path ] ) ( rc , output ) = zvmutils . execute ( command ) if rc : msg = ( "Error happened when copying image file to remote " "host with reason: %s" % output ) LOG . error ( msg ) raise exception . SDKImageOperationError ( rs = 21 , msg = output ) else : LOG . debug ( "Remote_host not specified, will copy to local server" ) try : shutil . copyfile ( source_path , dest_path ) except Exception as err : msg = ( "Export image from %(src)s to local file system" " %(dest)s failed: %(err)s" % { 'src' : source_path , 'dest' : dest_path , 'err' : six . text_type ( err ) } ) LOG . error ( msg ) raise exception . SDKImageOperationError ( rs = 22 , err = six . text_type ( err ) )
Export the specific image to remote host or local file system