Beispiel #1
0
def list_snaps():

    # Get creds from database
    creds = get()
    hostip = str(creds[2], 'utf-8')
    username = str(creds[0], 'utf-8')
    password = str(creds[1], 'utf-8')

    # Connect to the system
    api = client(hostip, username, password)

    volz = []
    vols = api.volumes.list()

    for vol in vols:
        current_vol = []
        name = vol.attrs['name']
        current_vol.append(name)
        snap_list = api.snapshots.list(vol_name=vol.attrs['name'])
        for snap in snap_list:
            current_vol.append(snap.attrs['name'])
        volz.append(current_vol)

    #rick.append('fail')
    return render_template('menu/list_snaps.html', volz=volz)
Beispiel #2
0
def delete_vol():

    # Get creds from database
    creds = get()
    hostip = str(creds[2], 'utf-8')
    username = str(creds[0], 'utf-8')
    password = str(creds[1], 'utf-8')

    #Get volume data from form
    name = request.form['name']

    result = smash_vol(username, password, hostip, name)

    if result.attrs['id']:
        try:
            volz = volumes(hostip, username, password)
        except:
            error = "ERR003 - Error deleting system volumes"
            return render_template('error/gen_error.html', error=error)

        msg = 'Volume deleted!'
        return render_template('success/success.html', msg=msg)
    else:
        error = 'Failed to delete the volume ....call the wookiee'
        return render_template('error/gen_error.html', error=error)
Beispiel #3
0
def create_vol():

    # Get creds from database
    creds = get()
    hostip = str(creds[2], 'utf-8')
    username = str(creds[0], 'utf-8')
    password = str(creds[1], 'utf-8')

    #Get volume data from form
    name = request.form['name']
    size = request.form['size']
    limit_iops = request.form['limit_iops']

    # result = create_vol()
    result = make_vol(username, password, hostip, name, size, limit_iops)

    if result.attrs['id']:
        try:
            volz = volumes(hostip, username, password)
        except:
            error = "ERR003 - Error getting system volumes after volume creation"
            return render_template('error/gen_error.html', error=error)

        msg = 'Volume created!'
        return render_template('success/success.html', msg=msg)
    else:
        error = 'Failed to create the volume ....call the wookiee'
        return render_template('error/gen_error.html', error=error)
Beispiel #4
0
def menu_logs():

    # Get logs from Nimble
    creds = get()
    hostip = str(creds[2], 'utf-8')
    username = str(creds[0], 'utf-8')
    password = str(creds[1], 'utf-8')

    try:

        logz = log(hostip, username, password)
    except:
        error = "ERR006 - Error getting system logs"
        return render_template('error/gen_error.html', error=error)

    return render_template('menu/logs.html', logz=logz)
Beispiel #5
0
def main_refresh():

    creds = get()

    username = str(creds[0], 'utf-8')
    password = str(creds[1], 'utf-8')
    hostip = str(creds[2], 'utf-8')

    try:
        inv = inventory(hostip, username, password)
    except:
        error = "ERR002 - Invalid Credentials...better luck next time"
        return render_template('error/error.html', error=error)

    usable = int(inv[6])

    #In a production demo chaneg this to be used = inv[7]
    #used = inv[7]
    used = 14968658889

    try:
        volz = volumes(hostip, username, password)
    except:
        error = "ERR003 - Error getting system volumes"
        return render_template('error/gen_error.html', error=error)

    try:
        eventz = events(hostip, username, password)
    except:
        error = "ERR004 - Error getting system events"
        return render_template('error/gen_error.html', error=error)

    try:
        counts = counter()
    except:
        error = "ERR004 - Error getting system event counts"
        return render_template('error/gen_error.html', error=error)

    chartData = [{
        "country": "Warning",
        "visits": counts[0]
    }, {
        "country": "Info",
        "visits": counts[1]
    }, {
        "country": "Critical",
        "visits": counts[2]
    }, {
        "country": "Notice",
        "visits": counts[3]
    }]

    # Pie chart
    chartData2 = [{
        "category": "Available Capacity Bytes",
        "column-1": usable
    }, {
        "category": "Used Space",
        "column-1": used
    }]

    return render_template('main/main_menu.html',
                           chartData=chartData,
                           chartData2=chartData2,
                           inventory=inv,
                           volumes=volz,
                           events=eventz)
Beispiel #6
0
def main_select():
    '''
    read creds
    '''

    # If this is a POSt it is from the login screen capture creds and save
    if request.method == 'POST':

        #Get creds from login
        ipaddress = request.form['ipaddress']
        user = request.form['user']
        password = request.form['password']

        # make them UTF-8
        ipaddress = ipaddress.encode('utf-8')
        user = user.encode('utf-8')
        password = password.encode('utf-8')

        # Save the creds to mongo
        savecreds = save(ipaddress, user, password)

    # Returning to the main page if HTTP GET pull creds from DB
    creds = get()
    # Setting up URLs and default header parameters
    root_url = 'https://' + creds[0] + ':8000'
    login_url = root_url + '/v1/session/login'
    who_am_i_url = root_url + '/v1/session/who-am-i'
    version_url = root_url + '/v1/version'
    nodes_url = root_url + '/v1/cluster/nodes/'
    default_header = {'content-type': 'application/json'}

    # Authenticate to controller
    post_data = {'username': creds[1], 'password': creds[2]}

    resp = requests.post(login_url,
                         data=json.dumps(post_data),
                         headers=default_header,
                         verify=False)

    # Check to see if the cred are correct
    if resp.status_code != 200:
        error = "ERR002 -Invalid username/password in credentials"
        return render_template('main/dberror1.html', error=error)

    resp_data = json.loads(resp.text)

    # Get the bearer token
    default_header['Authorization'] = 'Bearer ' + resp_data['bearer_token']

    # Get Identity
    resp = requests.get(who_am_i_url, headers=default_header, verify=False)

    identity = (json.loads(resp.text))

    # Get Version
    resp = requests.get(version_url, headers=default_header, verify=False)

    version = (json.loads(resp.text))

    # Get cluster nodes
    resp = requests.get(nodes_url, headers=default_header, verify=False)

    nodes = (json.loads(resp.text))

    #  TODO  replace with proper rest calls
    rc = RestClient(creds[0], 8000)
    rc.login(creds[1], creds[2])
    #
    stats = rc.fs.read_fs_stats()
    total_bytes = stats['total_size_bytes']
    free_size = stats['free_size_bytes']
    block_size_bytes = stats['block_size_bytes']

    return render_template('main/index.html',
                           total_bytes=total_bytes,
                           free_size=free_size,
                           block_size_bytes=block_size_bytes,
                           identity=identity,
                           version=version,
                           nodes=nodes)