if '__file__' in globals():
    sys.path.insert(0, os.path.join(os.path.abspath(__file__), 'scripts'))
else:
    sys.path.insert(0, os.path.join(os.path.abspath(os.getcwd()), 'scripts'))

from discovery_setup_utils import discovery, find_byod_environment_id  # noqa


def getEnvironmentStatusMessage(output):
    message = 'Status for "' + output.get('name') + '" '
    message += 'is "' + output.get('status') + '"'
    return message


# Running command that gets your environment from a list of environments
environments_response = discovery.get_environments()
ENVIRONMENT_ID = find_byod_environment_id(environments_response)

if not (ENVIRONMENT_ID == ''):
    # Running command that checks the status of your environment
    output = discovery.get_environment(environment_id=ENVIRONMENT_ID)
    while output.get('status') == 'pending':
        print(getEnvironmentStatusMessage(output))
        time.sleep(5)
        output = discovery.get_environment(environment_id=ENVIRONMENT_ID)

    print(getEnvironmentStatusMessage(output))
else:
    print('BYOD Environment ID not found')
    print(json.dumps(environments_response, indent=4))
Exemple #2
0
# load the proper path for discovery setup utils
if '__file__' in globals():
    sys.path.insert(0, os.path.join(os.path.abspath(__file__), 'scripts'))
else:
    sys.path.insert(0, os.path.join(os.path.abspath(os.getcwd()), 'scripts'))

from discovery_setup_utils import (discovery, find_byod_environment_id,
                                   find_collection_id)  # noqa

# retrieve the regular collection name from the .env file or default
COLLECTION_NAME = os.getenv('DISCOVERY_REGULAR_COLLECTION_NAME',
                            'knowledge_base_regular')

# retrieve our environment id
ENVIRONMENT_ID = find_byod_environment_id(discovery.get_environments())
print('Environment ID: ' + ENVIRONMENT_ID)

# Check to see if collection already exists
collection_id = ''
output = discovery.list_collections(environment_id=ENVIRONMENT_ID)

try:
    collection_id = find_collection_id(output, COLLECTION_NAME)
    print('Collection ID: ' + collection_id)
except Exception:
    print('Command:')
    print('discovery.list_collections')
    print('Response:')
    print(json.dumps(output, indent=4))
else:
    sys.path.insert(0, os.path.join(os.path.abspath(os.getcwd()), 'scripts'))

from discovery_setup_utils import discovery, find_byod_environment_id  # noqa

# please provide any custom name of the environment below
ENVIRONMENT_NAME = 'byod'

# Size of the enviroment to create.
# For trial, use 0. For other plans see documentation
ENVIRONMENT_SIZE = 0

environment_id = ''
output = discovery.get_environments()
try:
    environment_id = find_byod_environment_id(output)
except Exception:
    print('Command:')
    print('discovery.get_environments')
    print('Response:')
    print(json.dumps(output, indent=4))

if not (environment_id == ''):
    print 'Environment already exists with ID ' + environment_id + '.'
    print json.dumps(output, indent=4)
else:
    # Running command that creates a environment
    output = discovery.create_environment(name=ENVIRONMENT_NAME,
                                          description="Default environment",
                                          size=ENVIRONMENT_SIZE)
    print('New Environment created:')