def lto_db_media_id_exists(domain, id, config):
    media_id_exists_for_domain_qry = 'exists(/tape/tar/'+domain+'[@id="'+id+'"])'
    xquery_result = ltoUtil.exec_url_xquery(config, ltoUtil.get_lto_url(config)+'/data', media_id_exists_for_domain_qry)
    if ltoUtil.get_parsed_xquery_value(xquery_result) == ['true']:
        return True
    else:
        return False
def get_item_vectors(config, items, domain):
    bs = int(ltoUtil.get_blocksize(config))
    ids = string.join(items, ',')
    params = urllib.urlencode({'domain':domain, 'ids':ids})
    conn = httplib.HTTPConnection(ltoUtil.get_host_port(config))
    try:
        conn.request('POST', ltoUtil.get_lto_url(config)+'/xquery/get-file-lto-vector.xql?'+params, None, {})
        response = conn.getresponse()
        data = response.read()
        if '<exception>' in data:
            print ltoUtil.get_xquery_exception_msg(data)
            print ltoUtil.get_script_name()+' script terminated.'
            sys.exit(2)
    except httplib.HTTPException, e:
        print 'Unable to connect to database'
예제 #3
0
def db_import_tape_xml(config, tape_xml_doc):
    tape_xml = str(tape_xml_doc.toxml())
    print '\nImporting tape index to database:\n'
    username = raw_input('username: '******'password: '******'%s:%s' % (username, password)))
    authheader =  "Basic %s" % base64string
    headers = {"Authorization": authheader, "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    params = urllib.urlencode({'tapeXML': tape_xml})
    conn = httplib.HTTPConnection(ltoUtil.get_host_port(config))
    try:
        conn.request('POST', ltoUtil.get_lto_url(config)+'/xquery/import-tape-element.xql', params, headers)
        response = conn.getresponse()
        data = response.read()
        if '<exception>' in data:
            print ltoUtil.get_xquery_exception_msg(data)
            print 'Unable to update database.'
            print ltoUtil.get_script_name()+' script terminated.'
            sys.exit(2)
        elif 'HTTP ERROR: 404' in data:
            print '\nHTTP ERROR: 404'
            print data[data.find('<title>')+7:data.find('</title>')]
            print ltoUtil.get_script_name()+' script terminated.'
            sys.exit(2)
        elif response.status == 401 and response.reason == 'Unauthorized':
            print 'Authentication Failed.'
            print ltoUtil.get_script_name()+' script terminated.'
            sys.exit(2)
        else:
            print '\nDatabase updated (tape id: '+data+').'
    except httplib.HTTPException, e:
        print e.msg
        print 'Unable to connect to database'
        print ltoUtil.get_script_name()+' script terminated.'
        conn.close()
        sys.exit(2)