Merge pull request #46 from WriteOrRead/opencloud-adapter-factory
Documentation for configuring HPCloud with OpenStack
This commit is contained in:
commit
de1ef2f9b2
53
DependencyInjection/Factory/OpenCloudAdapterFactory.php
Normal file
53
DependencyInjection/Factory/OpenCloudAdapterFactory.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenCloud adapter factory
|
||||||
|
*
|
||||||
|
* @author Mammino Luciano 2013 <lmammino@oryzone.com>
|
||||||
|
*/
|
||||||
|
class OpenCloudAdapterFactory implements AdapterFactoryInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function create(ContainerBuilder $container, $id, array $config)
|
||||||
|
{
|
||||||
|
$container
|
||||||
|
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.opencloud'))
|
||||||
|
->replaceArgument(0, new Reference($config['object_store_id']))
|
||||||
|
->replaceArgument(1, $config['container_name'])
|
||||||
|
->replaceArgument(2, $config['create_container'])
|
||||||
|
->replaceArgument(3, $config['detect_content_type'])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getKey()
|
||||||
|
{
|
||||||
|
return 'opencloud';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function addConfiguration(NodeDefinition $node)
|
||||||
|
{
|
||||||
|
$node
|
||||||
|
->children()
|
||||||
|
->scalarNode('object_store_id')->isRequired()->cannotBeEmpty()->end()
|
||||||
|
->scalarNode('container_name')->isRequired()->cannotBeEmpty()->end()
|
||||||
|
->booleanNode('create_container')->defaultFalse()->end()
|
||||||
|
->booleanNode('detect_content_type')->defaultTrue()->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
104
README.markdown
104
README.markdown
|
@ -394,6 +394,108 @@ knp_gaufrette:
|
||||||
ttl: 0
|
ttl: 0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Open Cloud (opencloud)
|
||||||
|
|
||||||
|
Adapter for OpenCloud (Rackspace)
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `object_store_id`: the id of the object store service
|
||||||
|
* `container_name`: the name of the container to use
|
||||||
|
* `create_container`: if `true` will create the container in case it's needed *(default `false`)*
|
||||||
|
* `detect_content_type`: if `true` will detect the content type for each file *(default `true`)*
|
||||||
|
|
||||||
|
### Defining services
|
||||||
|
|
||||||
|
To use the OpenCloud adapter you should provide a valid `ObjectStore` instance. You can retrieve an instance through the
|
||||||
|
`OpenCloud\OpenStack` or `OpenCloud\Rackspace` instances. We can provide a comprehensive configuration through the Symfony
|
||||||
|
DiC configuration.
|
||||||
|
|
||||||
|
#### Define OpenStack/Rackspace service
|
||||||
|
|
||||||
|
Generic OpenStack:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
services:
|
||||||
|
opencloud.connection:
|
||||||
|
class: OpenCloud\OpenStack
|
||||||
|
arguments:
|
||||||
|
- %openstack_identity_url%
|
||||||
|
- {username: %openstack_username%, password: %openstack_password%, tenantName: %openstack_tenant_name%}
|
||||||
|
```
|
||||||
|
|
||||||
|
HPCloud:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
services:
|
||||||
|
opencloud.connection.hpcloud:
|
||||||
|
class: OpenCloud\OpenStack
|
||||||
|
arguments:
|
||||||
|
- 'https://region-a.geo-1.identity.hpcloudsvc.com:123456/v2.0/' // check https://account.hpcloud.com/account/api_keys for identities urls
|
||||||
|
- {username: %hpcloud_username%, password: %hpcloud_password%, tenantName: %hpcloud_tenant_name%}
|
||||||
|
```
|
||||||
|
The username and password are your login credentials, not the api key. Your tenantName is your Project Name on the api keys page.
|
||||||
|
|
||||||
|
Rackspace:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
services:
|
||||||
|
opencloud.connection.rackspace:
|
||||||
|
class: OpenCloud\Rackspace
|
||||||
|
arguments:
|
||||||
|
- 'https://identity.api.rackspacecloud.com/v2.0/'
|
||||||
|
- {username: %rackspace_username%, apiKey: %rackspace_apikey%}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Define ObjectStore service
|
||||||
|
|
||||||
|
HPCloud:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
services:
|
||||||
|
opencloud.object_store:
|
||||||
|
class: OpenCloud\ObjectStoreBase
|
||||||
|
factory_service: opencloud.connection.hpcloud
|
||||||
|
factory_method: ObjectStore
|
||||||
|
arguments:
|
||||||
|
- 'Object Storage' # Object storage type
|
||||||
|
- 'region-a.geo-1' # Object storage region
|
||||||
|
- 'publicURL' # url type
|
||||||
|
```
|
||||||
|
|
||||||
|
Rackspace:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
services:
|
||||||
|
opencloud.object_store:
|
||||||
|
class: OpenCloud\ObjectStoreBase
|
||||||
|
factory_service: opencloud.connection
|
||||||
|
factory_method: ObjectStore
|
||||||
|
arguments:
|
||||||
|
- 'cloudFiles' # Object storage type
|
||||||
|
- 'DFW' # Object storage region
|
||||||
|
- 'publicURL' # url type
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
Finally you can define your adapter in configuration:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# app/config/config.yml
|
||||||
|
knp_gaufrette:
|
||||||
|
adapters:
|
||||||
|
foo:
|
||||||
|
opencloud:
|
||||||
|
object_store_id: opencloud.object_store
|
||||||
|
container_name: foo
|
||||||
|
```
|
||||||
|
|
||||||
## Cache
|
## Cache
|
||||||
|
|
||||||
Adapter which allow to cache other adapters
|
Adapter which allow to cache other adapters
|
||||||
|
@ -523,4 +625,4 @@ knp_gaufrette:
|
||||||
```
|
```
|
||||||
data://backup/...
|
data://backup/...
|
||||||
data://pictures/...
|
data://pictures/...
|
||||||
```
|
```
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
<service id="knp_gaufrette.adapter.factory.acl_aware_amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AclAwareAmazonS3AdapterFactory">
|
<service id="knp_gaufrette.adapter.factory.acl_aware_amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AclAwareAmazonS3AdapterFactory">
|
||||||
<tag name="gaufrette.adapter.factory" />
|
<tag name="gaufrette.adapter.factory" />
|
||||||
</service>
|
</service>
|
||||||
|
<service id="knp_gaufrette.adapter.factory.opencloud" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\OpenCloudAdapterFactory">
|
||||||
|
<tag name="gaufrette.adapter.factory" />
|
||||||
|
</service>
|
||||||
<service id="knp_gaufrette.adapter.factory.gridfs" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GridFSAdapterFactory">
|
<service id="knp_gaufrette.adapter.factory.gridfs" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GridFSAdapterFactory">
|
||||||
<tag name="gaufrette.adapter.factory" />
|
<tag name="gaufrette.adapter.factory" />
|
||||||
</service>
|
</service>
|
||||||
|
@ -45,3 +48,4 @@
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</container>
|
</container>
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
</service>
|
</service>
|
||||||
<service id="knp_gaufrette.adapter.amazon_s3" class="Gaufrette\Adapter\AmazonS3" abstract="true" public="false" />
|
<service id="knp_gaufrette.adapter.amazon_s3" class="Gaufrette\Adapter\AmazonS3" abstract="true" public="false" />
|
||||||
<service id="knp_gaufrette.adapter.acl_aware_amazon_s3" class="Gaufrette\Adapter\AclAwareAmazonS3" abstract="true" public="false" />
|
<service id="knp_gaufrette.adapter.acl_aware_amazon_s3" class="Gaufrette\Adapter\AclAwareAmazonS3" abstract="true" public="false" />
|
||||||
|
<service id="knp_gaufrette.adapter.opencloud" class="Gaufrette\Adapter\OpenCloud" abstract="true" public="false">
|
||||||
|
<argument /><!-- ObjectStore -->
|
||||||
|
<argument /><!-- Container name -->
|
||||||
|
<argument /><!-- Create container -->
|
||||||
|
<argument /><!-- Detect content type -->
|
||||||
|
</service>
|
||||||
<service id="knp_gaufrette.adapter.gridfs" class="Gaufrette\Adapter\GridFS" abstract="true" public="false" />
|
<service id="knp_gaufrette.adapter.gridfs" class="Gaufrette\Adapter\GridFS" abstract="true" public="false" />
|
||||||
<service id="knp_gaufrette.adapter.mogilefs" class="Gaufrette\Adapter\MogileFS" abstract="true" public="false">
|
<service id="knp_gaufrette.adapter.mogilefs" class="Gaufrette\Adapter\MogileFS" abstract="true" public="false">
|
||||||
<argument /><!-- domain -->
|
<argument /><!-- domain -->
|
||||||
|
@ -42,3 +48,4 @@
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</container>
|
</container>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user