/** * Creates container * * @param string $container_id * @param string $error * @return boolean */ function create_container(&$container_id, &$error) { if (!$this->_init($error)) { return false; } try { $containers = $this->_connection->list_containers(); } catch (Exception $exception) { $error = sprintf('Unable to list containers (%s).', $exception->getMessage()); return false; } if (in_array($this->_config['container'], (array) $containers)) { $error = sprintf('Container already exists: %s.', $this->_config['container']); return false; } try { $container = $this->_connection->create_container($this->_config['container']); $container->make_public(); } catch (Exception $exception) { $error = sprintf('Unable to create container: %s (%s).', $this->_config['container'], $exception->getMessage()); return false; } $matches = null; if (preg_match('~^https?://(.+)$~', $container->cdn_uri, $matches)) { $container_id = $matches[1]; } return true; }
private function init_connection() { // Verify authentication information try { $this->auth = new CF_Authentication($this->username, $this->api_key); $this->auth->authenticate(); } catch (Exception $e) { throw new moodle_exception('repo_auth_fail', 'repository_rackspace_cf'); } // Initialize the connection $conn = new CF_Connection($this->auth); // Get a list of all the available containers $containers = $conn->list_containers(); // See if the container already exists $container_exists = in_array($this->container_name, $containers); if ($container_exists) { // Save a connection to the container $this->container = $conn->get_container($this->container_name); } else { // The container specified does not exists so create it. $this->container = $conn->create_container($this->container_name); } if ($this->cdn_enable) { // Enable CDN for the container $this->container->make_public(); } else { // Disable CDN for the container $this->container->make_private(); } }