try:
    import boto
    from boto.ec2.regioninfo import RegionInfo
    from boto.exception import EC2ResponseError
    has_boto=True
except:
    has_boto=False    

from sfa.util.sfalogging import logger
from sfa.openstack.nova_shell import NovaShell
from sfa.util.config import Config

class EucaShell:
    """
    A xmlrpc connection to the euca api. 
    """    

    def __init__(self, config):
        self.config = config
        self.nova_shell = NovaShell(config)
        self.access_key = None
        self.secret_key = None

    def _init_ctx(self, username=None, project=None):
        if username and project:
            self.access_key = "%s:%s" % (username, project)
            self.secret_key = self.nova_shell.auth_manager.get_user(username).secret
        else:
            admin_user = self.nova_shell.auth_manager.get_user(self.config.SFA_NOVA_USER)
            #access_key = admin_user.access
            self.access_key = '%s' % admin_user.name
            self.secret_key = admin_user.secret
        


    def get_euca_connection(self, username=None, project=None):
        if not has_boto:
            logger.info('Unable to access EC2 API - boto library not found.')
            return None

        if username and project:
            self._init_ctx(username, project)
        elif not self.access_key or not self.secret_key:
            self._init_ctx()
        
        url = self.config.SFA_NOVA_API_URL
        host = None
        port = None    
        path = "/"
        use_ssl = False
        # Split the url into parts 
        if url.find('https://') >= 0:
            use_ssl  = True
            url = url.replace('https://', '')
        elif url.find('http://') >= 0:
            use_ssl  = False
            url = url.replace('http://', '')
        parts = url.split(':')
        host = parts[0]
        if len(parts) > 1:
            parts = parts[1].split('/')
            port = int(parts[0])
            parts = parts[1:]
            path = '/'+'/'.join(parts)
        return boto.connect_ec2(aws_access_key_id=self.access_key,
                                aws_secret_access_key=self.secret_key,
                                is_secure=use_ssl,
                                region=RegionInfo(None, 'eucalyptus', host),
                                host=host,
                                port=port,
                                path=path) 

    def __getattr__(self, name):
        def func(*args, **kwds):
            conn = self.get_euca_connection()


@@ -541,28 +541,35 @@
 def 
-_
 init_c
+ontex
 t
-x
 (self, 
-user
+project_
 name
@@ -577,57 +577,203 @@
 None
-, project=None):%0A        if username and 
+):%0A        %0A        # use the context of the specified  project's project%0A        # manager. %0A        if project_name:%0A            project = self.nova_shell.auth_manager.get_project(
 project
-:
+_name)
 %0A   
@@ -810,20 +810,40 @@
 :%25s%22 %25 (
-user
+project.project_manager.
 name, pr
@@ -839,32 +839,37 @@
 er.name, project
+_name
 )%0A            se
@@ -888,76 +888,91 @@
 y = 
-self.nova_shell.auth_manager.get_user(username).secret%0A        else:
+project.project_manager.secret%0A        else:%0A            # use admin user's context
 %0A   
@@ -1207,18 +1207,8 @@
 ret%0A
-        %0A%0A
 %0A   
@@ -1241,31 +1241,16 @@
 elf,
- username=None,
  project
 =Non
@@ -1245,16 +1245,21 @@
  project
+_name
 =None):%0A
@@ -1401,89 +1401,8 @@
  if 
-username and project:%0A            self._init_ctx(username, project)%0A        elif 
 not 
@@ -1462,18 +1462,33 @@
 elf.
-_
 init_c
-tx(
+ontext(project_name
 )%0A  

modified init_context(). got rid unnecessary methods