def __init__(self):
     self.client = Client('PUPdwX4Dwbl9Xc3lYrhEp',
                          'vYe2LKXyP1Dfa3lKX6ASg2vEhd6xJFt0HXpfE500n')
     self.images = []
     self.sizes = []
     self.regions = []
     self.refresh = True
Ejemplo n.º 2
0
def initialize(client_id = 'ce302478afc77902c6fb05ba4ca5683e',\
               api_key = 'e4a865a093fe5c2f704c194e91135b74'):
    client_id = client_id
    api_key = api_key

    client = Client(client_id, api_key)
    # if client != None:
    return client
Ejemplo n.º 3
0
def up(count, client_key, api_key, login, size=66, region_id=1, ssh_keys=None):
    """
    Startup the load testing server.
    """
    count = int(count)
    client = Client(client_key, api_key)
    print 'Attempting to call up %i minnows.' % count

    if not ssh_keys:
        ssh_keys = [str(k.id) for k in client.all_ssh_keys()]

    droplet_ids = []
    droplets = []

    #25489 is ubuntu 12.04
    for i in range(0, count):
        droplet = client.create_droplet('minnow-%s' % i, size, 25489,
                                        region_id, ssh_keys)
        droplet_ids.append(droplet.id)

    print "Started droplets with ids: %s" % ','.join(
        [str(i) for i in droplet_ids])
    print "Waiting for minnows to wake up..."

    for drop_id in droplet_ids:
        droplet = client.show_droplet(drop_id)
        while (not droplet.status == 'active') or droplet.ip_address == -1:
            print '.'
            time.sleep(4)
            droplet = client.show_droplet(drop_id)
        droplets.append(droplet)
        print "Droplet id %s is ready" % drop_id

    print "The school of minnows has been assembled."
    _write_server_list(client_key, api_key, login, droplets)
    print "Arming the minnows with Apache Bench..."
    #TODO: Can't ssh into the servers for a bit...is there a better way to do this rather than
    #sleeping for an arbitrary amount of time?
    time.sleep(20)

    params = []
    for droplet in droplets:
        params.append({
            'droplet_id': droplet.id,
            'ip_address': droplet.ip_address,
            'login': login,
        })
    # Spin up processes for connecting to EC2 instances
    pool = Pool(len(params))
    pool.map(_install_apache_utils, params)
    return
Ejemplo n.º 4
0
def status():
    """
    Report the status of the load testing servers.
    """
    client_key, api_key, login, droplet_ids = _read_server_list()
    client = Client(client_key, api_key)

    if len(droplet_ids) == 0:
        print 'No minnows have been mobilized.'
        return
    print "Getting status of minnows"
    for drop_id in droplet_ids:
        droplet = client.show_droplet(drop_id)
        print 'minnow %s: %s @ %s' % (droplet.id, droplet.status,
                                      droplet.ip_address)
Ejemplo n.º 5
0
def spawn(client, num_instances=5):
    client_id = 'ce302478afc77902c6fb05ba4ca5683e'
    api_key = 'e4a865a093fe5c2f704c194e91135b74'

    client = Client(client_id, api_key)
    print "HERE"
    images = client.images()
    sizes = client.sizes()
    print 'before create'
    for x in client.show_active_droplets():
        print x.id
    print 'after create'
    job_id = 'job'
    for x in range(num_instances):
        drop_name = job_id + '-' + str(x)
        client.create_droplet(name=drop_name, image_id=2393479, size_id=66)
Ejemplo n.º 6
0
def down():
    """
    Shutdown the load testing server.
    """
    client_key, api_key, login, droplet_ids = _read_server_list()

    if not droplet_ids:
        print 'No minnows have been mobilized.'
        return

    print 'Connecting to the ocean.'
    client = Client(client_key, api_key)

    for droplet_id in droplet_ids:
        res = client.destroy_droplet(droplet_id)
        print "Destroyed %s" % res

    _delete_server_list()
Ejemplo n.º 7
0
def attack(url, n, c, **options):
    """
    Test the root url of this site.
    """
    client_key, api_key, login, droplet_ids = _read_server_list()
    client = Client(client_key, api_key)

    if not login or not client_key or not api_key:
        print "You need to create the minnows first with the up command"
        return
    if not droplet_ids or len(droplet_ids) == 0:
        print 'No minnows are ready to attack.'
        return

    headers = options.get('headers', '')
    csv_filename = options.get("csv_filename", '')

    if csv_filename:
        try:
            stream = open(csv_filename, 'w')
        except IOError, e:
            raise IOError(
                "Specified csv_filename='%s' is not writable. Check permissions or specify a different filename and try again."
                % csv_filename)
Ejemplo n.º 8
0
            dict1[option] = Config.get(section, option)
            if dict1[option] == -1:
                DebugPrint("skip: %s" % option)
        except:
            print("exception on %s!" % option)
            dict1[option] = None
    return dict1


clientID = configSectionMap("Access")['clientid']
apiKey = configSectionMap("Access")['apikey']

# print "Client ID: %s, API Key: %s" % (clientID, apiKey)
print "Client ID and API key retrieved."

client = Client(clientID, apiKey)
droplets = client.show_active_droplets()


def printOptions():
    print ""
    print "Options:"
    print "1) List Active Droplets"
    print "2) List Available Sizes"
    print "3) List Available Images"
    print "4) List Available Regions"
    print "5) Create Drop"
    print "6) Destroy Drop"
    print "7) Install HAProxy"
    print "8) Deploy code"
    print "10) Create Downpour"
Ejemplo n.º 9
0
def show_regions(client_key, api_key):
    print "Fetching Regions..."
    client = Client(client_key, api_key)
    regions = client.regions()
    for r in regions:
        print "Region id: %s is located in %s" % (r.id, r.name[:-1])
Ejemplo n.º 10
0
def show_sizes(client_key, api_key):
    print "Fetching Sizes..."
    client = Client(client_key, api_key)
    sizes = client.sizes()
    for s in sizes:
        print "Size id: %s has %s of memory" % (s.id, s.name[:-1])
Ejemplo n.º 11
0
digital ocean server setup and installing ipython notebook, and run website on web server. 
choose os you want, choose images you want. launch. 

# <markdowncell>

# user logs into digital ocean, chooses one of my snapshots (need to make snapshots of stuff i like.
# Makes server, runs script to install software. tick box on software you want. 
# 

# <codecell>

from dop.client import Client

# <codecell>

client = Client()

# <codecell>

ls

# <codecell>

%%bash
ipython nbconvert 'digzocean.ipynb'

# <codecell>

cat digzocean.html

# <codecell>
Ejemplo n.º 12
0
 def __init__(self, client_id, api_key, name):
     from dop.client import Client
     self.name = name
     self.client = Client(client_id, api_key)
Ejemplo n.º 13
0
    for x in client.images():
        print x.to_json()


def initialize(client_id = 'ce302478afc77902c6fb05ba4ca5683e',\
               api_key = 'e4a865a093fe5c2f704c194e91135b74'):
    client_id = client_id
    api_key = api_key

    client = Client(client_id, api_key)
    # if client != None:
    return client


if __name__ == "__main__":
    client_id = 'ce302478afc77902c6fb05ba4ca5683e'
    api_key = 'e4a865a093fe5c2f704c194e91135b74'

    client = Client(client_id, api_key)

    # destroy_all_droplets(client)
    #main()
    # for x in client.show_active_droplets():
    #     print x.name
    # print x.id
    # print_sizes(client)
    spawn(client, 4)
    # print_images()
    # print_sizes()
    # print_regions()
Ejemplo n.º 14
0
from dop.client import Client
import time
import sys
import yaml

if __name__ == '__main__':
    yaml = yaml.load(open('ansible-provision/secret_vars.yml', 'r'))
    client = Client(yaml['doid'], yaml['dokey'])
    #create a droplet
    conf = {
        'name': sys.argv[1],
        'size_id': 66,
        'image_id': 3101918,
        'region_id': 3,
        'ssh_key_ids': ['20319']
    }
    droplet = client.create_droplet(**conf)
    is_active = False
    while not is_active:
        time.sleep(2)
        status = client.get_status(droplet.event_id)
        if status.percentage == '100':
            is_active = True
            print "Droplet Created."
            print client.show_droplet(droplet.id).__dict__