NAME

Net::OpenStack::Swift - Perl Bindings for the OpenStack Object Storage API, known as Swift.

SYNOPSIS

use Net::OpenStack::Swift;

my $sw = Net::OpenStack::Swift->new(
    auth_url       => 'https://auth-endpoint-url/v2.0',
    user           => 'userid',
    password       => 'password',
    tenant_name    => 'project_id',
    # auth_version => '2.0', # by default
);

my ($storage_url, $token) = $sw->get_auth();

my ($headers, $containers) = $sw->get_account(url => $storage_url, token => $token);
# or,  storage_url and token can be omitted.
my ($headers, $containers) = $sw->get_account();

# 1.0 auth
my $sw = Net::OpenStack::Swift->new(
    auth_url       => 'https://auth-endpoint-url/1.0',

    user           => 'region:user-id',
    password       => 'secret-api-key',

    # or private, if you are under the private network.
    auth_version  => '1.0',
    tenant_name   => 'public',
);

DESCRIPTION

Perl Bindings for the OpenStack Object Storage API, known as Swift.

METHODS

new

Creates a client.

auth_url

Required. The url of the authentication endpoint.

user

Required.

password

Required.

tenant_name

Required. tenant name/project

auth_version

Optional. default 2.0

get_auth

Get storage url and auth token.

my ($storage_url, $token) = $sw->get_auth();

response:

storage_url

Endpoint URL

token

Auth Token

get_account

Show account details and list containers.

my ($headers, $containers) = $sw->get_account(marker => 'hoge');
maker

Optional.

end_maker

Optional.

prefix

Optional.

limit

Optional.

head_account

Show account metadata.

my $headers = $sw->head_account();

post_account

Create, update, or delete account metadata.

get_container

Show container details and list objects.

my ($headers, $containers) = $sw->get_container(container_name => 'container1');

head_container

Show container metadata.

my $headers = $sw->head_container(container_name => 'container1');

put_container

Create container.

my $headers = $sw->put_container(container_name => 'container1')

post_container

Create, update, or delete container metadata.

delete_container

Delete container.

my $headers = $sw->delete_container(container_name => 'container1');

get_object

Get object content and metadata.

open my $fh, ">>:raw", "hoge.jpeg" or die $!;
my $etag = $sw->get_object(container_name => 'container_name1', object_name => 'masakystjpeg',
    write_file => $fh,
);
# or chunked
open my $fh, ">>:raw", "hoge.jpeg" or die $!;
my $etag = $sw->get_object(container_name => 'container1', object_name => 'hoge.jpeg',
    write_code => sub {
        my ($status, $message, $headers, $chunk) = @_;
        print $status;
        print length($chunk);
        print $fh $chunk;
});
container_name
object_name
write_file: FileHandle

the response content will be saved here instead of in the response object.

write_code: Code reference

the response content will be called for each chunk of the response content.

head_object

Show object metadata.

my $headers = $sw->head_object(container_name => 'container1', object_name => 'hoge.jpeg');

put_object

Create or replace object.

my $file = 'hoge.jpeg';
open my $fh, '<', "./$file" or die;
my $headers = $sw->put_object(container_name => 'container1',
    object_name => 'hoge.jpeg', content => $fh, content_length => -s $file);
content: Str|FileHandle
content_length: Int
content_type: Str

Optional. default 'application/octet-stream'

post_object

Create or update object metadata.

delete_object

Delete object.

my $headers = $sw->delete_object(container_name => 'container1', object_name => 'hoge.jpeg');

Debug

To print request/response Debug messages, $ENV{LM_DEBUG} must be true.

example

$ LM_DEBUG=1 carton exec perl test.pl

SEE ALSO

http://docs.openstack.org/developer/swift/

http://docs.openstack.org/developer/keystone/

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

masakyst <masakyst.public@gmail.com>