details: http://www.bx.psu.edu/hg/galaxy/rev/6b3f453078c4 changeset: 3052:6b3f453078c4 user: Enis Afgan <afgane@gmail.com> date: Mon Aug 24 17:46:22 2009 -0400 description: Added ability to select default credentials. diffstat: eggs.ini | 2 + lib/galaxy/model/mapping.py | 3 +- lib/galaxy/model/migrate/versions/0014_credentials_table.py | 3 +- lib/galaxy/web/controllers/cloud.py | 75 +++++++++++------- templates/cloud/configure_cloud.mako | 20 ++++- 5 files changed, 68 insertions(+), 35 deletions(-) diffs (236 lines): diff -r a83d7220136f -r 6b3f453078c4 eggs.ini --- a/eggs.ini Mon Aug 24 12:19:57 2009 -0400 +++ b/eggs.ini Mon Aug 24 17:46:22 2009 -0400 @@ -51,6 +51,7 @@ wsgiref = 0.1.2 Babel = 0.9.4 wchartype = 0.1 +boto = 1.8d ; extra version information [tags] @@ -100,3 +101,4 @@ wsgiref = http://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip Babel = http://ftp.edgewall.com/pub/babel/Babel-0.9.4.zip wchartype = http://ginstrom.com/code/wchartype-0.1.zip +boto = http://boto.googlecode.com/files/boto-1.8d.tar.gz \ No newline at end of file diff -r a83d7220136f -r 6b3f453078c4 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Mon Aug 24 12:19:57 2009 -0400 +++ b/lib/galaxy/model/mapping.py Mon Aug 24 17:46:22 2009 -0400 @@ -386,7 +386,8 @@ Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), Column( "name", TEXT), Column( "access_key", TEXT), - Column( "secret_key", TEXT) + Column( "secret_key", TEXT), + Column( "defaultCred", Boolean, default=False) ) StoredWorkflow.table = Table( "stored_workflow", metadata, diff -r a83d7220136f -r 6b3f453078c4 lib/galaxy/model/migrate/versions/0014_credentials_table.py --- a/lib/galaxy/model/migrate/versions/0014_credentials_table.py Mon Aug 24 12:19:57 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0014_credentials_table.py Mon Aug 24 17:46:22 2009 -0400 @@ -19,7 +19,8 @@ Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), Column( "name", TEXT), Column( "access_key", TEXT), - Column( "secret_key", TEXT) ) + Column( "secret_key", TEXT), + Column( "defaultCred", Boolean, default=False ) ) def upgrade(): metadata.reflect() diff -r a83d7220136f -r 6b3f453078c4 lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Mon Aug 24 12:19:57 2009 -0400 +++ b/lib/galaxy/web/controllers/cloud.py Mon Aug 24 17:46:22 2009 -0400 @@ -15,7 +15,11 @@ from galaxy.model.mapping import desc from galaxy.model.orm import * +# Required for Cloud tab +import galaxy.eggs +galaxy.eggs.require("boto") from boto.ec2.connection import EC2Connection + import logging log = logging.getLogger( __name__ ) @@ -32,34 +36,32 @@ Render cloud main page (management of cloud resources) """ user = trans.get_user() - #awsCredentials = 0 awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ) \ .order_by( desc( model.StoredUserCredentials.c.update_time ) ) \ .all() - log.debug( "in list" ) - log.debug( awsCredentials ) - - workflows = trans.sa_session.query( model.StoredWorkflow ) \ - .filter_by( user=user, deleted=False ) \ - .order_by( desc( model.StoredWorkflow.c.update_time ) ) \ - .all() - return trans.fill_template( "cloud/configure_cloud.mako", - awsCredentials = awsCredentials, - workflows = workflows ) - - @web.expose - @web.require_login( "use Galaxy cloud" ) - def makeDefault( self, trans ): - """ - Set current credentials as default to be used for submitting jobs - TODO: Implement, this is only a dummy method. - """ - awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() return trans.fill_template( "cloud/configure_cloud.mako", awsCredentials = awsCredentials ) @web.expose + @web.require_login( "use Galaxy cloud" ) + def makeDefault( self, trans, id=None ): + """ + Set current credentials as default to be used for acquiring cloud resources. + """ + currentDefault = get_defalt_credentials (trans) + if currentDefault: + currentDefault.defaultCred = False + + newDefault = get_stored_credentials( trans, id ) + newDefault.defaultCred = True + trans.sa_session.flush() + trans.set_message( "Credentials '%s' set as default." % newDefault.name ) + + return self.list( trans ) #trans.fill_template( "cloud/configure_cloud.mako", + #awsCredentials = awsCredentials ) + + @web.expose @web.require_login( "use Galaxy workflows" ) def list_for_run( self, trans ): """ @@ -176,10 +178,9 @@ @web.expose @web.require_login( "add credentials" ) - def add( self, trans, credName='', accessKey='', secretKey='', default=False ): + def add( self, trans, credName='', accessKey='', secretKey='', defaultCred=False ): """ Add user's AWS credentials stored under name `credName`. - TODO: Make use of 'default' credential selection """ user = trans.get_user() cred_error = accessKey_error = secretKey_error = None @@ -203,18 +204,15 @@ # Log and display the management page trans.log_event( "User added new credentials" ) trans.set_message( "Credential '%s' created" % credentials.name ) - if default: - mail = os.popen("%s -t" % trans.app.config.sendmail_path, 'w') - mail.write("To: %s\nFrom: %s\nSubject: Join Mailing List\n\nJoin Mailing list." % (trans.app.config.mailing_join_addr,email) ) - if mail.close(): - return trans.show_warn_message( "Now logged in as " + user.email+". However, subscribing to the mailing list has failed.", refresh_frames=refresh_frames ) + if defaultCred: + self.makeDefault( trans, credentials.id) return self.list( trans ) return trans.show_form( web.FormBuilder( web.url_for(), "Add credentials", submit_text="Add" ) .add_text( "credName", "Credentials name", value="Unnamed credentials", error=cred_error ) .add_text( "accessKey", "Access key", value='', error=accessKey_error ) .add_password( "secretKey", "Secret key", value='', error=secretKey_error ) - .add_input( "checkbox","Make default credentials","default", value='default' ) ) + .add_input( "checkbox","Make default credentials","defaultCred", value='defaultCred' ) ) @web.expose @web.require_login( "view credentials" ) @@ -232,7 +230,7 @@ @web.require_login( "delete credentials" ) def delete( self, trans, id=None ): """ - Delete credentials + Delete user's cloud credentials """ # Load credentials from database stored = get_stored_credentials( trans, id ) @@ -690,8 +688,11 @@ """ Get a StoredUserCredntials from the database by id, verifying ownership. """ - # Load credentials from database - id = trans.security.decode_id( id ) + # Check if 'id' is in int (i.e., it was called from this program) or + # it was passed from the web (in which case decode it) + if not isinstance( id, int ): + id = trans.security.decode_id( id ) + stored = trans.sa_session.query( model.StoredUserCredentials ).get( id ) if not stored: error( "Credentials not found" ) @@ -704,6 +705,18 @@ # Looks good return stored +def get_defalt_credentials( trans, check_ownership=True ): + """ + Get a StoredUserCredntials from the database by 'default' setting, verifying ownership. + """ + user = trans.get_user() + # Load credentials from database + stored = trans.sa_session.query( model.StoredUserCredentials ) \ + .filter_by (user=user, defaultCred=True) \ + .first() + + return stored + def attach_ordered_steps( workflow, steps ): ordered_steps = order_workflow_steps( steps ) if ordered_steps: diff -r a83d7220136f -r 6b3f453078c4 templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Mon Aug 24 12:19:57 2009 -0400 +++ b/templates/cloud/configure_cloud.mako Mon Aug 24 17:46:22 2009 -0400 @@ -9,6 +9,9 @@ except: messagetype = "done" %> + + + <p /> <div class="${messagetype}message"> ${message} @@ -31,7 +34,6 @@ <tr class="header"> <th>Credentials Name</th> <th>Default</th> - ## <th>Last Updated</th> <th></th> </tr> %for i, awsCredential in enumerate( awsCredentials ): @@ -41,8 +43,17 @@ <a id="wf-${i}-popup" class="popup-arrow" style="display: none;">▼</a> </td> ## Comment <td>${len(workflow.latest_workflow.steps)}</td> - ##<td>${str(awsCredentials.update_time)[:19]}</td> + ##<td>${str(awsCredential.update_time)[:19]}</td> <td> + ${str(awsCredential.defaultCred)} + <% + c=str(awsCredential.defaultCred) + %> + + ##${dflt(cred=c)} + </td> + + <td> <div popupmenu="wf-${i}-popup"> <a class="action-button" href="${h.url_for( action='view', id=trans.security.encode_id(awsCredential.id) )}">View</a> <a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(awsCredential.id) )}">Rename</a> @@ -65,3 +76,8 @@ %endif +<%def name="dflt(cred)"> + %if cred: + default + %endif +</%def>