Software

How to Delete an Object in OpenStack Swift

API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

public class OpenStackSample {

  public static void main(String[] args) {
    Client client = ClientBuilder.newClient();

    client.target("https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).delete();

    client.close();
  }

}

API w/ Go

package main

import "gopkg.in/resty.v1"

func main() {
  resty.R().SetHeader("X-Auth-Token", ...).Delete("https://host/v1/sampleAccount/sampleBucket/sampleObject")
}

API w/ Node.js

var https = require('https');

var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'DELETE', path: '/v1/sampleAccount/sampleBucket/sampleObject' });

req.end();

API w/ Python

import requests

requests.delete('https://host/v1/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })

API w/ Ruby

require 'rest-client'

RestClient.delete 'https://host/v1/sampleAccount/sampleBucket/sampleObject', :x_auth_token => ...

CLI

1) Configure the CLI:

export ST_AUTH=https://host/auth/v1.0
export ST_USER=sampleUser
export ST_KEY=samplePassword

2) Run the following command:

swift delete sampleBucket sampleObject

Client

from swiftclient.service import SwiftService

service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' })

for res in service.delete('sampleBucket', [ 'sampleObject' ]):
  print res

Terraform Provider

1) Configure the provider:

export OS_SWAUTH=true
export OS_AUTH_URL=https://host/
export OS_USERNAME=sampleuser
export OS_PASSWORD=samplepassword

2) If needed, import the object:

terraform import openstack_objectstorage_container_v1.sampleobject sampleobject

3) Destroy the object.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.