Hello,

I'm working on a personal project using Rackspace's "pyrax" bindings to 
create a "Control Panel". I've made some progress however am confused on a 
few things and could use some guidance.

1) Correctly storing authenticated user data. 

e.g.

I have a module called "rs_auth.py" that takes username/apikey and 
authenticates to the service.

import pyrax

def cloud_auth(username, apikey):
    pyrax.set_setting("identity_type", "rackspace")
    ctx = pyrax.create_context(username=username, api_key=apikey)
    try:
        if ctx.authenticated == 'True':
            pass
        else:
            ctx.authenticate()
    except Exception as e:
        return e
    return ctx

I have tried doing "session.dbaas = rs_auth.cloud_auth(session.username, 
session.apikey" however this ends up not working and I have to instantiate 
"dbaas = rs_auth.cloud_auth(session.username, session.apikey)" in every 
controller function that requires to interact with the service. I'm sure 
there is a simpler way.

For example, "databases.py":

def index():
    if not session.username:
        redirect(URL('default', 'login'))
    else:
        *dbaas = rs_auth.cloud_auth(session.username, session.apikey)*
        ord_d = dbaas.ORD.database.client
        dfw_d = dbaas.DFW.database.client
        iad_d = dbaas.IAD.database.client
        syd_d = dbaas.SYD.database.client
        hkg_d = dbaas.HKG.database.client
        cdb = (ord_d, dfw_d, iad_d, syd_d, hkg_d)
    return dict(cdb=cdb)


def instance():
    *dbaas = rs_auth.cloud_auth(session.username, session.apikey)*
    region = request.args(0)
    dbi = request.args(1)
    instance = None
    try:
        if region == "DFW":
            instance = dbaas.DFW.database.client.get(dbi)
        elif region == "ORD":
            instance = dbaas.ORD.database.client.get(dbi)
        elif region == "IAD":
            instance = dbaas.IAD.database.client.get(dbi)
        elif region == "SYD":
            instance = dbaas.SYD.database.client.get(dbi)
        elif region == "HKG":
            instance = dbaas.HKG.database.client.get(dbi)
    except Exception as e:
        return e
    return dict(instance=instance)

2) Executing a object method in a view. 

e.g. From the above "instance" function, a database is looked up and then 
returned to the view, "instance.html".

{{extend 'layout.html'}}
Name: {{=instance.name}} <br />
ID: {{=instance.id}} <br />
Hostname: {{=instance.hostname}} <br />
Status: {{=instance.status}} <br />
Volume size: {{=instance.volume.size}} <br />
Volume used: {{=instance.volume.used}} <br />
*<INPUT type="button" value="Reboot" onclick="" /> <br /> (no clue what to 
do here)*
<INPUT type="button" value="Back" 
onclick="location.href='{{=URL('index')}}'" />

There is a method available for the object, "instance.restart()", but I've 
been unable to figure out how to execute it, (do I have to create a 
separate "restart" function to actually call the objects restart method? 
Having read the book I /think/ ajax/jquery would be the solution however I 
greatly lack skills in those areas.

Thus with that being mentioned, the issues here are most likely due to lack 
of know how on my end, if any references could be provided to provide a 
clearer understanding, it would be greatly appreciated.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to