Esempio n. 1
0
    def set_ec2_connection(self, resource="ec2", ec2_conn=None, region=None, access_key=None, secret_key=None):
        # if we were handed a connection object and a region, bind it.
        if ec2_conn and region:
            self.aws_connections[region] = ec2_conn

        if not region:
            region = self.region

        if not (access_key and secret_key):
            if self.credentials_are_set:
                access_key = self.access_key
                secret_key = self.secret_key

        if bool(access_key) and bool(secret_key):

            if resource in self.resource_regional_connection_method_table:
                _conn_method = self.resource_regional_connection_method_table[resource]
                self.aws_connections[resource][region] = _conn_method(region, aws_access_key_id=access_key, aws_secret_access_key=secret_key)
            else:
                try:
                    _conn_method = self.resource_connection_method_table[resource]
                    self.aws_connections[resource] = _conn_method(aws_access_key_id=access_key, aws_secret_access_key=secret_key)

                except KeyError:
                    msg = "Unknown connection method for %s.  Check your typing and/or issue a feature request." % resource
                    log.error(msg)
                    self.errors.append(msg)

            return True

        else:
            msg = "Could not create a connection to EC2.  Missing access/secret key or both."
            log.error(msg)
            self.errors.append(msg)
            return False
Esempio n. 2
0
    def set_ec2_connection(self,
                           resource="ec2",
                           ec2_conn=None,
                           region=None,
                           access_key=None,
                           secret_key=None):
        # if we were handed a connection object and a region, bind it.
        if ec2_conn and region:
            self.aws_connections[region] = ec2_conn

        if not region:
            region = self.region

        if not (access_key and secret_key):
            if self.credentials_are_set:
                access_key = self.access_key
                secret_key = self.secret_key

        if bool(access_key) and bool(secret_key):

            if resource in self.resource_regional_connection_method_table:
                _conn_method = self.resource_regional_connection_method_table[
                    resource]
                self.aws_connections[resource][region] = _conn_method(
                    region,
                    aws_access_key_id=access_key,
                    aws_secret_access_key=secret_key)
            else:
                try:
                    _conn_method = self.resource_connection_method_table[
                        resource]
                    self.aws_connections[resource] = _conn_method(
                        aws_access_key_id=access_key,
                        aws_secret_access_key=secret_key)

                except KeyError:
                    msg = "Unknown connection method for %s.  Check your typing and/or issue a feature request." % resource
                    log.error(msg)
                    self.errors.append(msg)

            return True

        else:
            msg = "Could not create a connection to EC2.  Missing access/secret key or both."
            log.error(msg)
            self.errors.append(msg)
            return False
Esempio n. 3
0
    def get_all_instance_status_objects(self, region=None):

        _result = []

        if not region:
            region = self.region

        _conn = self.get_ec2_connection(region=self.region)

        if _conn:
            _result = _conn.get_all_instance_status()
        if _result:
            return _result
        else:
            msg = "failed to get instance status"
            log.error(msg)
            self.errors.append(msg)
            return False
Esempio n. 4
0
    def get_all_instance_status_objects(self, region=None):

        _result = []

        if not region:
            region = self.region

        _conn = self.get_ec2_connection(region=self.region)

        if _conn:
            _result = _conn.get_all_instance_status()
        if _result:
            return _result
        else:
            msg = "failed to get instance status"
            log.error(msg)
            self.errors.append(msg)
            return False