Ejemplo n.º 1
0
def create_bucket(name: str, memory: int, admin: Admin) -> int:
    try:
        admin.bucket_create(name, ram_quota=memory)
    except HTTPError as err:
        v = err.__dict__['all_results'][None]
        if v.value['errors'] and 'name' in v.value[
                'errors'] and 'already exists' in v.value['errors']['name']:
            print('%s bucket already exists, not creating.' % name)
        else:
            print(err)
        return 1
    return 0
def ensure_create_bucket(username: str,
                         password: str,
                         bucket_name: str,
                         host="couchbase",
                         port="8091"):
    adm = Admin(username, password, host=host, port=port)
    try:
        adm.bucket_create(bucket_name, bucket_type="couchbase")
        return True
    except HTTPError as e:
        if (e.objextra.value["errors"]["name"] ==
                "Bucket with given name already exists"):
            return True
Ejemplo n.º 3
0
from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
from couchbase.admin import Admin  # the admin class gives me the power to create/delete buckets
from couchbase.n1ql import N1QLQuery

cluster = Cluster('couchbase://*****:*****@couchbase.com',
        'interests': ['Holy Grail', 'African Swallows']
    })
# OperationResult<RC=0x0, Key=u'u:king_arthur', CAS=0xb1da029b0000>

cb.get('u:king_arthur').value
# {u'interests': [u'Holy Grail', u'African Swallows'], u'name': u'Arthur', u'email': u'*****@*****.**'}

## The CREATE PRIMARY INDEX step is only needed the first time you run this script
cb.n1ql_query('CREATE PRIMARY INDEX ON `swallows-sample`').execute()
row_iter = cb.n1ql_query(N1QLQuery('SELECT name FROM `swallows-sample` WHERE ' +\
'$1 IN interests', 'African Swallows'))
for row in row_iter:
Ejemplo n.º 4
0
from couchbase.admin import Admin
from couchbase.cluster import Cluster
from couchbase.bucket import Bucket
from couchbase.exceptions import CouchbaseTransientError, HTTPError, KeyExistsError, NotFoundError
import couchbase.subdocument as SD
from couchbase.n1ql import N1QLQuery

# Delete any pre-existing buckets.  Create new.
cb_adm = Admin(testenv['couchdb_username'],
               testenv['couchdb_password'],
               host=testenv['couchdb_host'],
               port=8091)

# Make sure a test bucket exists
try:
    cb_adm.bucket_create('travel-sample')
    cb_adm.wait_ready('travel-sample', timeout=30)
except HTTPError:
    pass


@pytest.mark.skipif("COUCHBASE_TEST" not in os.environ, reason="")
class TestStandardCouchDB(unittest.TestCase):
    def setup_class(self):
        """ Clear all spans before a test run """
        self.recorder = tracer.recorder
        self.cluster = Cluster('couchbase://%s' % testenv['couchdb_host'])
        self.bucket = Bucket('couchbase://%s/travel-sample' %
                             testenv['couchdb_host'],
                             username=testenv['couchdb_username'],
                             password=testenv['couchdb_password'])
#!/usr/bin/env python

from couchbase.admin import Admin
from couchbase.bucket import Bucket

adm = Admin('Administrator', '123456', host='localhost', port=8091)
adm.bucket_create('new-bucket',
                  bucket_type='couchbase',
                  bucket_password='******')

# Wait for bucket to become ready
adm.wait_ready('new-bucket', timeout=30)

bucket = Bucket('couchbase://localhost/new-bucket', password='******')
bucket.upsert('foo', 'bar')

adm.bucket_remove('new-bucket')
adm = Admin('admin', 'An3WeeWa', host=SERVER_IP, port=8091)


class Buckets():
    offering_bucket = cluster.open_bucket('offerings')
    schedule_bucket = cluster.open_bucket('schedules')
    user_bucket = cluster.open_bucket('users')
    course_bucket = cluster.open_bucket('courses')

    _all = [offering_bucket, schedule_bucket, user_bucket, course_bucket]
    _timeout = 2.000

    for bucket in _all:
        bucket.timeout = _timeout


if __name__ == '__main__':
    bckt = input("Enter bucket name to create: ")
    if not bckt:
        exit(0)
    res = adm.bucket_create(bckt)
    print(res)
"""
CREATE INDEX `quarterId` ON `schedules`(`quarterId`)
CREATE INDEX `schedCourses` ON `schedules`(`offerings`)
CREATE INDEX `studentId` ON `schedules`(`studentId`)



"""
Ejemplo n.º 7
0
from couchbase.admin import Admin
from couchbase.exceptions import HTTPError
from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
from couchbase.analytics import AnalyticsQuery

# The terraform script will out put the IP address
ip_f = open('terraform/ip_address.txt')
ip = str(ip_f.read()).strip('\n')

print('Connecting to Couchbase instance at %s' % (ip))

adm = Admin('Administrator', 'password', host=ip, port=8091)

try:
    adm.bucket_create('commerce')
except HTTPError as err:
    v = err.__dict__['all_results'][None]
    if 'already exists' in v.value['errors']['name']:
        print('Bucket already exists, not creating.')

adm.wait_ready('commerce', timeout=10)

# connect w/ SDK
cluster = Cluster('couchbase://' + ip)
auth = PasswordAuthenticator('Administrator', 'password')
cluster.authenticate(auth)
cb = cluster.open_bucket('commerce')

# create anlytics indexes
queries = [
Ejemplo n.º 8
0
cb.remove('user6')  # supprime document
cb.upsert('user6', user6)
cb.get('user6', ttl=0)  # change ttl
cb.touch('user6', ttl=60)  #idem
cb.get('user6')

# 4
doc = ['user1', 'user2', 'user3', 'user4']
gm = cb.get_multi(doc)
for key, result in gm.items():
    print "Value is", result.value

# création bucket
from couchbase.admin import Admin
adm = Admin('Julie', 'CBD1jg', host='localhost')
adm.bucket_create('TP4', bucket_type='couchbase', ram_quota=100)

# génération de 1000 documents à la volée fichier dans le cache
cb = cluster.open_bucket('TP4')
documents = {}
for i in range(1000):
    documents['user' + str(i)] = {
        'ID': 's' + str(i),
        'type': 'spy',
        'login': '******' + str(i),
        'mdp': 'mission' + str(i)
    }

cb.upsert_multi(documents)

for i in range(1000):