EzDevInfo.com

php-opencloud

The PHP SDK for OpenStack clouds Rackspace Developer Center the rackspace developer center gives developers tools and resources to build powerful, scalable apps on the only cloud backed by fanatical support®

How do you create / delete containers with laravel-rackspace-opencloud?

I'm using the laravel-rackspace-opencloud package to manage files on RackSpace's cloud files platform. Is it possible to use this library to create / delete file containers? I've not been able to find an example of this, and the README only seems to reference the management of files within containers that have already been created.


Source: (StackOverflow)

Fatal error: Class 'Size' not found in

I have this

<?php
require 'vendor/autoload.php';
use OpenCloud\Common\Constants\Size;
use OpenCloud\OpenStack;

And this function in the same file

function create_user_container($email){
 $objectStoreService = 
      $GLOBALS['client']->objectStoreService('swift','RegionOne','publicURL');
 $container = $objectStoreService->createContainer($email);

 //Set quota for total size of objects in container.
 $maximumTotalSizeOfObjectsInContainer = 1 * Size::GB;
 $container->setBytesQuota($maximumTotalSizeOfObjectsInContainer);
}

And I am getting this error

Fatal error: Class 'Size' not found in ... 

But when I am using OpenStack in same file, it works!


Source: (StackOverflow)

Advertisements

Unable to include "vendor/autoload.php" after installing Composer on Ubuntu

I'm just getting familiar with Linux servers and I'm trying to install Composer on my Ubuntu server. I think everything installed correctly except when I try to include Composer's autoloader I get a PHP error:

Warning: require(/usr/share/php/opencloud/lib/../vendor/autoload.php): failed to open stream: No such file or directory in /usr/share/php/opencloud/lib/php-opencloud.php on line 5 Fatal error: require(): Failed opening required '/usr/share/php/opencloud/lib/../vendor/autoload.php' (include_path='.:/usr/share/php') in /usr/share/php/opencloud/lib/php-opencloud.php on line 5

My composer.json is:

{
    "require": {
        "rackspace/php-opencloud": "v1.7.0"
    }
}

And when I run "composer diag" it outputs this:

Checking composer.json: FAIL
name : is missing and it is required
description : is missing and it is required

Source: (StackOverflow)

uploading large object to Cloudfiles returns different md5

So I have this code and I'm trying to upload large files as per https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/ObjectStore/Storage/Object.md to Rackspace:

$src_path = 'pathtofile.zip'; //about 700MB
$md5_checksum = md5_file($src_path); //result is f210775ccff9b0e4f686ea49ac4932c2
$trans_opts = array(
      'name' => $md5_checksum,
      'concurrency' => 6,
      'partSize'    => 25000000
 );
$trans_opts['path'] = $src_path;
$transfer = $container->setupObjectTransfer($trans_opts);
$response = $transfer->upload();

Which allegedly uploads the file just fine

However when I try to download the file as recommended here https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/ObjectStore/USERGUIDE.md:

$name = 'f210775ccff9b0e4f686ea49ac4932c2';
$object = $container->getObject($name);
$objectContent = $object->getContent();
$pathtofile = 'destinationpathforfile.zip';
$objectContent->rewind();
$stream = $objectContent->getStream();
file_put_contents($pathtofile, $stream);
$md5 = md5_file($pathtofile);

The result of md5_file ends up being different from 'f210775ccff9b0e4f686ea49ac4932c2'....moreover the downloaded zip ends up being unopenable/corrupted

What did I do wrong?


Source: (StackOverflow)

using open cloud api without composer

I am trying to use the rackspace php SDK to update to the new API since the old one has been deprecated for a while. I am trying to use the SDK without using composer since we cannot install composer on the production server. I was wondering if anyone has any pointers to this or if anyone has successfully done so. At this point the only solution I have found is to manually require the files necessary to the specific files but this will take forever.

Any help is appreciated!


Source: (StackOverflow)

Rackspace php-opencloud API calls - can't get importCredentials() to work

I am using the php-opencloud / Rackspace SDK.

I only have one user connecting to the API, which is the entire site that is running.

By default it will make an authentication request before every API call, which is of course crazy.

I want to simply cache the token (I'm thinking apc_add() / apc_fetch()) and then pass it in next time to prevent that extra API call. There will be one token for the whole site so this makes sense to me.

This is what I have but it's not recognising the data and it just keeps making the extra API call in line 2 anyway.

What am I doing wrong? How would I simply pass in a token to stop it making authentication API calls?

// uses https://github.com/rackspace/php-opencloud

$client->importCredentials(array('token'=>'the-token', 'expiration'=>'2014-03-01T01:02:09.384Z', 'tenant'=>'xxxxxxxx'));    

$queue = $client->queuesService('cloudQueues', 'LON', 'internalURL')->setClientId();

Source: (StackOverflow)

List rackspace CDN-enabled containers with php-opencloud

The documentation states

To list CDN-only containers, follow the same operation for Storage which lists all containers. The only difference is which service object you execute the method on.

But what is the right service object. I tried:

$service = objectStoreService('cloudFiles', $region);
$service = objectStoreCDNService('cloudFilesCDN', $region);
$service = objectStoreCDNService('cloudFiles', $region);
$service = objectStoreService('cloudFilesCDN', $region);

And $containers = $service->listContainers() or $containers->listContainers(array('enabled_only' => TRUE)) with all of the above to no avail.


Source: (StackOverflow)

How to get folder size from folder inside Rackspace Cloud Files container using PHP?

Basically I have created a container inside Rackspace Cloud Files, lets say work. Inside work I have so many folders by username (dynamic folders as new users register and allocate 1 GB of space). Every time a user uploads a file, I want to check whether the user exceeds his limit or not before allowing him to upload. I am using the Laravel PHP Framework along with Rackspace open cloud SDK.

Questions:

  1. I want to get folder size of particular user's folder created under main container("xyz").

  2. Is there any other way to achieve whether user has exceed limit or not?


Source: (StackOverflow)

Rackspace php-opencloud how do I create a folder

When I upload a file using $container->uploadObjects($files) I can include the directory path in the name to make a new folder. If I use Cyberduck I can see the new folder.

But if I try and get an object list with $container->objectList($options) it doesn't list the directory like [content_type] => application/directory. But it does when I use Cyberduck.

So my question is, how do I create a folder using php-opencloud?


Source: (StackOverflow)

serverList() only returns 100 results

I'm trying to write a bit of code to inventory our OpenStack deployment, and I've run into an issue where serverList() only ever returns 100 results instead of the 600+ I'm expecting. I've reviewed the documentation and a bit of the source, and as far as I can tell there's no reason that this should be happening as the PaginatedIterator should be doing its pagination transparently.

There are no errors or warning either generated in my code, or logged on my controller [that I can find]. I am using php-opencloud v1.12 via composer.

use OpenCloud\OpenStack;
$client = new OpenStack('http://1.2.3.4:5000/v2.0/', array(
    'username'  => 'admin',
    'password'  => 'hunter2',
    'tenantName'=> 'admin',
));
$service = $client->computeService('nova', 'RegionOne');

$stmt = $dbh->prepare('INSERT INTO servers VALUES (?,?)');
/* foreach($service->serverList() as $server) {
    $stmt->execute([$server->id, $server->name]);
} // neither method works */
$list = $service->serverList();
while( $list->valid() ) {
    $server = $list->current();
    $stmt->execute([$server->id, $server->name]);
    $list->next();
}
echo "\n";
var_dump($dbh->query('SELECT * FROM servers')->fetchAll(PDO::FETCH_ASSOC));

Source: (StackOverflow)

PHP OpenCloud\Rackspace Problems

I am having problems trying to get the Rackspace Opencloud API to work as expected (particularly the cloud files).

I have been following these guides:

https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/ObjectStore/Access.md http://docs.rackspace.com/sdks/api/php/namespace-OpenCloud.ObjectStore.html

The Authentication seems to work fine because a token and the service catalog is returned.

header("Content-Type: text/plain");
require '/vendor/autoload.php';

use OpenCloud\Rackspace;

$client = new Rackspace('https://lon.identity.api.rackspacecloud.com/v2.0/', array(
    'username' => 'MY_USERNAME',
    'apiKey'   => 'MY_APIKEY'
));

$client->authenticate();

echo 'Authenticated with token: '.$client->getToken()."\n\n";

print_r($client->getCatalog());

My problems start when i try to use a service from the API:

$service = $client->objectStoreService('cloudFiles');

This line kills the code. I have copied the Rackspace documentation line for line but still no luck, I am unable to get any of the services to work.

Can anyone see where I'm going wrong or provide any tips for the best way to troubleshoot this issue?


Source: (StackOverflow)