details: http://www.bx.psu.edu/hg/galaxy/rev/5963dd169715 changeset: 3086:5963dd169715 user: Enis Afgan <afgane@gmail.com> date: Fri Nov 06 13:45:57 2009 -0500 description: Implemented on-line checking of zone availability when registering a UCI. This introduces provider-specific ties in cloud.py controller that will need to be modified if non-EC2 cloud providers are added. diffstat: lib/galaxy/cloud/providers/ec2.py | 1 + lib/galaxy/cloud/providers/eucalyptus.py | 1 + lib/galaxy/web/controllers/cloud.py | 72 ++++++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 23 deletions(-) diffs (127 lines): diff -r dc1a6f3a2c08 -r 5963dd169715 lib/galaxy/cloud/providers/ec2.py --- a/lib/galaxy/cloud/providers/ec2.py Fri Nov 06 12:27:52 2009 -0500 +++ b/lib/galaxy/cloud/providers/ec2.py Fri Nov 06 13:45:57 2009 -0500 @@ -633,6 +633,7 @@ log.error( "Establishing connection with cloud failed: %s" % str(e) ) uci.error( "Establishing connection with cloud failed: " + str(e) ) uci.state( uci_states.ERROR ) + uci.flush() return None return conn diff -r dc1a6f3a2c08 -r 5963dd169715 lib/galaxy/cloud/providers/eucalyptus.py --- a/lib/galaxy/cloud/providers/eucalyptus.py Fri Nov 06 12:27:52 2009 -0500 +++ b/lib/galaxy/cloud/providers/eucalyptus.py Fri Nov 06 13:45:57 2009 -0500 @@ -599,6 +599,7 @@ log.error( "Establishing connection with cloud failed: %s" % str(e) ) uci.error( "Establishing connection with cloud failed: " + str(e) ) uci.state( uci_states.ERROR ) + uci.flush() return None return conn diff -r dc1a6f3a2c08 -r 5963dd169715 lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Fri Nov 06 12:27:52 2009 -0500 +++ b/lib/galaxy/web/controllers/cloud.py Fri Nov 06 13:45:57 2009 -0500 @@ -25,6 +25,8 @@ from boto.ec2.connection import EC2Connection from boto.ec2.regioninfo import RegionInfo from galaxy.cloud import CloudManager +import boto.exception +import boto import logging log = logging.getLogger( __name__ ) @@ -270,22 +272,38 @@ user = trans.get_user() storedCreds = trans.sa_session.query( model.CloudUserCredentials ).filter_by( user=user ).all() if len( storedCreds ) == 0: - return trans.show_error_message( "You must register credentials before configuring a Galaxy instance." ) - # TODO: This should be filled automatically but ties to implementation for diff provider is a problem... + return trans.show_error_message( "You must register credentials before configuring a Galaxy cloud instance." ) # Create dict mapping of cloud providers to zones available by those providers providersToZones = {} for storedCred in storedCreds: - if storedCred.provider.region_name == 'us-east-1': - ec2_zones = ['us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1d'] - providersToZones[storedCred.name] = ec2_zones - elif storedCred.provider.region_name == 'eu-west-1': - ec2_zones = ['eu-west-1a', 'eu-west-1b'] - providersToZones[storedCred.name] = ec2_zones - elif storedCred.provider.type == 'eucalyptus': - providersToZones[storedCred.name] = ['epc'] + zones = None + conn = get_connection( trans, storedCred ) + if conn != None: + avail_zones = [] + try: + zones = conn.get_all_zones() + for zone in zones: + zone = str( zone ).split(':')[1] + avail_zones.append( zone ) + providersToZones[storedCred.name] = avail_zones + except boto.exception.EC2ResponseError, e: + log.error( "Retrieving zones for credentials '%s' failed." % storedCred.name ) + providersToZones[storedCred.name] = ['Unknown provider zone'] else: providersToZones[storedCred.name] = ['Unknown provider zone'] + # Hard-coded solution +# if storedCred.provider.storedCred.provider.region_name == 'us-east-1': +# ec2_zones = ['us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1d'] +# providersToZones[storedCred.name] = ec2_zones +# elif storedCred.provider.region_name == 'eu-west-1': +# ec2_zones = ['eu-west-1a', 'eu-west-1b'] +# providersToZones[storedCred.name] = ec2_zones +# elif storedCred.provider.type == 'eucalyptus': +# providersToZones[storedCred.name] = ['epc'] +# else: +# providersToZones[storedCred.name] = ['Unknown provider zone'] + if instanceName: # Check if volume size is entered as an integer try: @@ -1030,22 +1048,30 @@ return instances -def get_connection( trans, credName ): +def get_connection( trans, creds ): """ - Establishes EC2 connection using user's default credentials + Establishes cloud connection using user's credentials """ - log.debug( '##### Establishing cloud connection.' ) - user = trans.get_user() - creds = trans.sa_session.query( model.CloudUserCredentials ).filter_by( user=user, name=credName ).first() + log.debug( 'Establishing cloud connection.' ) +# user = trans.get_user() +# creds = trans.sa_session.query( model.CloudUserCredentials ) \ +# .filter_by( user=user, name=credName ) \ +# .first() + #.filter( model.CloudUserCredentials.c.deleted != True ) \ MOVE TO LINE ABOVE ONCE DELETE COLUMS ARE IMPLEMENTED + if creds: a_key = creds.access_key s_key = creds.secret_key - # Amazon EC2 - #conn = EC2Connection( a_key, s_key ) - # Eucalyptus Public Cloud - euca_region = RegionInfo( None, "eucalyptus", "mayhem9.cs.ucsb.edu" ) - conn = EC2Connection( aws_access_key_id=a_key, aws_secret_access_key=s_key, is_secure=False, port=8773, region=euca_region, path="/services/Eucalyptus" ) + try: + euca_region = RegionInfo( None, creds.provider.region_name, creds.provider.region_endpoint ) + conn = EC2Connection( aws_access_key_id=a_key, + aws_secret_access_key=s_key, + is_secure=creds.provider.is_secure, + port=creds.provider.port, + region=euca_region, + path=creds.provider.path ) + except boto.exception.EC2ResponseError, e: + log.error( "Establishing connection with cloud failed: %s" % str(e) ) + return None + return conn - else: - error( "You must specify default credentials before starting an instance." ) - return 0