Example #1
0
def delete_droplet(droplet_id):
    result, retrieved_data = digital_ocean_api_call('droplets', 'delete', {'droplet_id': droplet_id})
    if result:

        return "Droplet %d successfully deleted!" % droplet_id
    else:
        return 'Sorry Error'
Example #2
0
def droplet_status():
    all_result = []
    print 'Sending Request...'
    success, call = digital_ocean_api_call('droplets', 'get')
    if success:
        print 'Success'
        data = call.json()
        droplets = data['droplets']
    else:
        print 'Failed'
        raise RuntimeError

    for droplet in droplets:
        result = {}
        result['id'] = droplet['id']
        result['name'] = droplet['name']
        result['status'] = droplet['status']
        hostname = str(droplet['name'])
        result['region'] = droplet['region']['slug']
        system_ips = {}

        for protocols, ips in droplet['networks'].items():
            temp_ips = {}
            for ip in ips:
                if ip['type'] == 'public':
                    temp_ips['public'] = ip['ip_address']
                elif ip['type'] == 'private':
                    temp_ips['private'] = ip['ip_address']
            system_ips[protocols] = temp_ips
        result.update(system_ips)
        result['ping'] = check_ping(system_ips['v4']['public']) if result['status'] == 'active' else False
        result['check_http'] = True   # check_django(hostname) if result['status'] == 'active' else False
        result['last_check'] = get_amsterdam_time()
        all_result.append(result)
    return all_result
def check_action_status(action_id):
    success, data = digital_ocean_api_call('actions/%d' % action_id, 'get')
    if success:
        res = data.json()
        return res
    else:
        return {'error': True}
def retrieve_all_do_images():
    success, data = digital_ocean_api_call('images', 'get')
    if success:
        res = data.json()
        return res
    else:
        return {'error': True}
def retrieve_all_do_ssh_keys():
    success, data = digital_ocean_api_call('account/keys', 'get')
    if success:
        res = data.json()
        ssh_keys = res['ssh_keys']
        keys = []
        for key in ssh_keys:
            keys.append({'name': key['name'], 'id': key['id']})
        return {'response': keys}
    else:
        return {'error': True}
def retrieve_available_do_regions():
    success, data = digital_ocean_api_call('regions', 'get')
    if success:
        res = data.json()
        regions = res['regions']
        result = []
        for region in regions:
            if region['available']:
                result.append({
                    'name': region['name'],
                    'slug': region['slug'],
                    'features': region['features'],
                    'sizes': region['sizes']})
        return result
    else:
        return {'error': True}
def create_digital_ocean_droplet(name, region, size, image, ssh_keys, private):
    data = {
        'name': name,
        'region': region,
        'size': size,
        'image': image,
        'ssh_keys': ssh_keys,
        'backups': False,
        'ipv6': False,
        'user_data': None,
        'private_networking': private
    }
    result, retrieved_data = digital_ocean_api_call('droplets', 'post', data)
    if result and retrieved_data.status_code == 202:
        response = retrieved_data.json()
        return response['links']['actions'][0]['id']
    else:
        return 'Sorry Error'