在本地设置Bluemix VCAP_SERVICES环境变量,以便可以在本地进行开发? [英] Set Bluemix VCAP_SERVICES environment variable locally so that I can develop locally?

查看:91
本文介绍了在本地设置Bluemix VCAP_SERVICES环境变量,以便可以在本地进行开发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置Bluemix VCAP_SERVICES环境变量在本地,但是在终端中出现此错误:

I am trying to set my Bluemix VCAP_SERVICES environment variable locally, but I'm getting this error in the terminal:

NoSQL:找不到命令

NoSQL: command not found

复制步骤

  1. 登录到Bluemix.net
  2. 部署你好世界烧瓶应用程序
  3. 将Bluemix Cloudant服务绑定到应用程序
  4. 从适用于Python的应用程序上的运行时/环境变量中复制VCAP_SERVICES环境变量
  5. 在本地编辑器中,删除Mac终端上的所有换行符
  6. vi ~/.bash_profile
  7. 使用i
  8. 进入插入模式
  9. 粘贴到VCAPSERVICES中,我的样子是这样的:

  1. Login to Bluemix.net
  2. Deploy a hello world flask application
  3. Bind a Bluemix Cloudant Service to the application
  4. Copy the VCAP_SERVICES Environment Variables from the Runtime / Environment Variables on the application for Python
  5. In local editor remove all the line breaks on Mac terminal
  6. vi ~/.bash_profile
  7. Enter insert mode with i
  8. paste in VCAPSERVICES, mine looks like this:

VCAP_SERVICES="{"VCAP_SERVICES":{"cloudantNoSQLDB": [{"credentials": {"host": "fakehostc-bluemix.cloudant.com","password":"fakepassword4da6de3a12a83362b26a","port": 443,"url": "https://fakeURLc-bluemix:fakeab96175c-bluemix.cloudant.com","username": "fakeusername-b749-399cfbd1175c-bluemix"},"label":"cloudantNoSQLDB","name":"Cloudant NoSQL DB-p2","plan":"Lite","provider":null,"syslog_drain_url":null,"tags":["data_management","ibm_created","ibm_dedicated_public"]}]}}"
export VCAP_SERVICES

  • 保存文件并使用:wq!

    我在复制和设置本地Bluemix VCAP_Services环境变量时做错了什么?

    What am I doing wrong copying and setting my local Bluemix VCAP_Services Environment Variable?

    如果我复制整个内容,则会收到错误消息,提示该行太长.我如何轻松地将整个Bluemix Python Runtime VCAP_SERVICES变量复制并粘贴到我的本地Mac .bash_profile环境设置中,而无需手动按摩JSON和所有这些换行符等?

    If I copy the whole thing I get errors that the line is too long. How can I easily copy and paste the entire Bluemix Python Runtime VCAP_SERVICES Variable into my local Mac .bash_profile environment settings without manually massaging JSON and all these line breaks etc?

    我不想使用本地文件来存储这些文件,因为从开发,测试,暂存和生产阶段迁移起来,它并不十分安全.

    I don't want to use a local file to store those since it isn't very secure as I move from dev, test, staging and production.

    推荐答案

    我想出了答案,在VCAP_SERVICES的开头和结尾都使用单引号

    I figured out the answer use single quotes at the beginning and end of VCAP_SERVICES

    VCAP_SERVICES ='{"cloudantNoSQLDB":[{凭据":{主机":"fakehostc-bluemix.cloudant.com",密码":"fakepassword4da6de3a12a83362b26a",端口":443,"URL": " https://fakeURLc-bluemix:fakeab96175c-bluemix.cloudant.com ", "username":"fakeusername-b749-399cfbd1175c-bluemix"},"label":"cloudantNoSQLDB","name":"Cloudant NoSQL DB-p2","plan":"Lite","provider":null,"syslog_drain_url:null,"标记:[" data_management," ibm_created," ibm_dedicated_public]}]}''

    VCAP_SERVICES='{"cloudantNoSQLDB": [{"credentials": {"host": "fakehostc-bluemix.cloudant.com","password":"fakepassword4da6de3a12a83362b26a","port": 443,"url": "https://fakeURLc-bluemix:fakeab96175c-bluemix.cloudant.com","username": "fakeusername-b749-399cfbd1175c-bluemix"},"label":"cloudantNoSQLDB","name":"Cloudant NoSQL DB-p2","plan":"Lite","provider":null,"syslog_drain_url":null,"tags":["data_management","ibm_created","ibm_dedicated_public"]}]}'

    以下是用于检索VCAP Services环境变量并在Cloudant上执行基本操作的相应代码:

    Here is the corresponding code to retrieve VCAP Services environment variables and do basic operations on Cloudant:

    # 1. Parse VCAP_SERVICES Variable and connect to DB         
    vcap = json.loads(os.getenv("VCAP_SERVICES"))['cloudantNoSQLDB']        
    serviceUsername = vcap[0]['credentials']['username']
    servicePassword = vcap[0]['credentials']['password']    
    serviceURL = vcap[0]['credentials']['url']
    
    # Create Cloudant DB connection
    # This is the name of the database we are working with.
    databaseName = "databasedemo"
    
    # This is a simple collection of data,
    # to store within the database.
    sampleData = [
        [1, "one", "boiling", 100],
        [2, "two", "hot", 40],
        [3, "three", "warm", 20],
        [4, "four", "cold", 10],
        [5, "five", "freezing", 0]
    ]
    
    # Use the Cloudant library to create a Cloudant client.
    client = Cloudant(serviceUsername, servicePassword, url=serviceURL)
    
    # Connect to the server
    client.connect()
    
    # 2.  Creating a database within the service instance.
    
    # Create an instance of the database.
    myDatabaseDemo = client.create_database(databaseName)
    
    # Check that the database now exists.
    if myDatabaseDemo.exists():
        print "'{0}' successfully created.\n".format(databaseName)
    
    # 3.  Storing a small collection of data as documents within the database.
    
    # Create documents using the sample data.
    # Go through each row in the array
    for document in sampleData:
        # Retrieve the fields in each row.
        number = document[0]
        name = document[1]
        description = document[2]
        temperature = document[3]
    
        # Create a JSON document that represents
        # all the data in the row.
        jsonDocument = {
            "numberField": number,
            "nameField": name,
            "descriptionField": description,
            "temperatureField": temperature
        }
    
        # Create a document using the Database API.
        newDocument = myDatabaseDemo.create_document(jsonDocument)
    
        # Check that the document exists in the database.
        if newDocument.exists():
            print "Document '{0}' successfully created.".format(number)
    
    # 4.  Retrieving a complete list of the documents.
    
    # Simple and minimal retrieval of the first
    # document in the database.
    result_collection = Result(myDatabaseDemo.all_docs)
    print "Retrieved minimal document:\n{0}\n".format(result_collection[0])
    
    # Simple and full retrieval of the first
    # document in the database.
    result_collection = Result(myDatabaseDemo.all_docs, include_docs=True)
    print "Retrieved full document:\n{0}\n".format(result_collection[0])
    
    # Use a Cloudant API endpoint to retrieve
    # all the documents in the database,
    # including their content.
    
    # Define the end point and parameters
    end_point = '{0}/{1}'.format(serviceURL, databaseName + "/_all_docs")
    params = {'include_docs': 'true'}
    
    # Issue the request
    response = client.r_session.get(end_point, params=params)
    
    # Display the response content
    print "{0}\n".format(response.json())
    
    # 5.  Deleting the database.
    
    # Delete the test database.
    try :
        client.delete_database(databaseName)
    except CloudantException:
        print "There was a problem deleting '{0}'.\n".format(databaseName)
    else:
        print "'{0}' successfully deleted.\n".format(databaseName)
    
    # 6.  Closing the connection to the service instance.
    
    # Disconnect from the server
    client.disconnect()
    

    这篇关于在本地设置Bluemix VCAP_SERVICES环境变量,以便可以在本地进行开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆