def set_credential_file(self, credential_file, region=None, tenant_id=None, authenticate=False): """ Reads in the credentials from the supplied file. It should be a standard config file in the format: [keystone] username = myusername password = top_secret tenant_id = my_id """ self._creds_file = credential_file cfg = ConfigParser.SafeConfigParser() try: if not cfg.read(credential_file): # If the specified file does not exist, the parser returns an # empty list. raise exc.FileNotFound("The specified credential file '%s' " "does not exist" % credential_file) except ConfigParser.MissingSectionHeaderError as e: # The file exists, but doesn't have the correct format. raise exc.InvalidCredentialFile(e) try: self._read_credential_file(cfg) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: raise exc.InvalidCredentialFile(e) if region: self.region = region if authenticate: self.authenticate()
def set_credential_file(self, credential_file, region=None, authenticate=False): """ Reads in the credentials from the supplied file. It should be a standard config file in the format: [rackspace_cloud] username = myusername api_key = 1234567890abcdef """ self._creds_file = credential_file cfg = ConfigParser.SafeConfigParser() try: if not cfg.read(credential_file): # If the specified file does not exist, the parser will # return an empty list raise exc.FileNotFound("The specified credential file '%s' " "does not exist" % credential_file) except ConfigParser.MissingSectionHeaderError as e: # The file exists, but doesn't have the correct format. raise exc.InvalidCredentialFile(e) try: self.username = cfg.get("rackspace_cloud", "username") self.api_key = cfg.get("rackspace_cloud", "api_key") except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: raise exc.InvalidCredentialFile(e) if region: self._region = region if authenticate: self.authenticate()