ovirtclient.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ovirt-desktop-client 作者: nkovacne 项目源码 文件源码
def store_vv_file(self, vmid, ticket):
        """
            Description: Connecting to the machine involves two steps, the second one is obtaining a 'vv' file with the
                         connection parameters, which we can later pipe to virt-viewer and the connection will be opened.
            Arguments: 1. vmid: The VM UUID in oVirt-format.
                       2. ticket: The ticket obtained in the first step (method get_viewer_ticket)
            Returns: The temporary filename with all the parameters to connect to the machine (piped to virt-viewer)
        """

        global conf

        if not ticket:
            return False

        req = urllib2.Request('%s/%s/%s/%s/%s' % (conf.CONFIG['ovirturl'], 'vms', vmid, 'graphicsconsoles', ticket))
        base64str = encodestring('%s:%s' % (conf.USERNAME + '@' + conf.CONFIG['ovirtdomain'], conf.PASSWORD)).replace('\n', '')
        req.add_header('Authorization', 'Basic ' + base64str)
        req.add_header('Content-Type', 'application/xml')
        req.add_header('Accept', 'application/x-virt-viewer')
        req.add_header('filter', 'true')

        unverified_ctxt = SSLContext(PROTOCOL_TLSv1)
        try:
            contents = urllib2.urlopen(req, context=unverified_ctxt).read()
            if conf.CONFIG['fullscreen'] == '1':
               contents = contents.replace('fullscreen=0', 'fullscreen=1')
            filename = '/tmp/viewer-' + str(randint(10000, 99999))
            f = open(filename, 'w')
            f.write(contents)
            f.close()

            return filename
        except urllib2.HTTPError, em:
            QMessageBox.critical(None, _('apptitle') + ': ' + _('error'), _('unexpected_request_error') + '(' + str(em.code) + '): ' + em.reason + '. ' + _('check_vm_config_updated'))
            return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号