Updated on 2024-09-05 GMT+08:00

Creating a Parallel File System (SDK for Go)

Function

Parallel file systems (PFSs) are containers for storing objects in OBS. Files uploaded to OBS are stored as objects in PFSs. This API creates a PFS.

When creating a PFS, you can also configure parameters such as the storage class, region, and access control as needed.

Restrictions

  • To create a PFS, you must have the obs:bucket:CreateBucket permission. IAM is recommended for granting permissions. For details, see IAM Custom Policies.
  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.

    When creating a PFS, if you use the endpoint obs.myhuaweicloud.com for client initialization, you do not have to specify a region (indicated by location) where the PFS will be created, because OBS automatically creates the PFS in the CN North-Beijing1 (cn-north-1) region. However, if the endpoint you use is not obs.myhuaweicloud.com, you must specify a region that matches the used endpoint, or status code 400 is returned.

    For example, if the endpoint used for initialization is obs.ap-southeast-1.myhuaweicloud.com, you must set Location to ap-southeast-1 when creating a PFS. Otherwise, status code 400 is returned.

  • A maximum of 100 PFSs (regardless of regions) can be created for an account. There is no limit on the number and size of objects in a PFS.
  • The name of a PFS must be unique in OBS. If you repeatedly create PFSs with the same name in the same region, an HTTP status code 200 will be returned. In other cases, creating a PFS with the same name as an existing PFS will have an HTTP status code 409 returned, indicating that such a PFS already exists.
  • The name of a deleted PFS can be reused for another PFS at least 30 minutes after the deletion.
  • Not all regions support the creation of multi-AZ PFSs. You can check whether a region allows you to create multi-AZ PFSs by referring to Product Pricing Details.

Method

func (obsClient ObsClient) CreateBucket(input *CreateBucketInput) (output *BaseModel, err error)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

input

*CreateBucketInput

Yes

Explanation:

Input parameters for creating a PFS. For details, see Table 2.

Table 2 CreateBucketInput

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

string

Yes

Explanation:

PFS name.

Restrictions:

  • A PFS name must be unique across all accounts and regions.
  • A PFS name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create PFSs with the same name in the same region, no error will be reported and the PFS attributes comply with those set in the first creation request.

Default value:

None

Location

string

Yes if the region where the OBS service resides is not the default region

Explanation:

Region where the PFS is to be created.

Restrictions:

If the specified endpoint is obs.myhuaweicloud.com, this parameter is not required. If any other endpoints are specified, this parameter is required.

Value range:

To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator.

Default value:

If obs.myhuaweicloud.com is used as the endpoint and no region is specified, cn-north-1 (the CN North-Beijing1 region) is used by default.

ACL

AclType

No

Explanation:

Access control list (ACL) that can be pre-defined when a PFS is created. For details about ACLs, see ACLs.

Value range:

See Table 3.

Default value:

private

StorageClass

StorageClassType

No

Explanation:

PFS storage class that can be specified at PFS creation.

Value range:

See Table 4.

Default value:

STANDARD

GrantReadId

string

No

Explanation:

ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can list objects, multipart uploads, and object versions in the PFS you are creating, and can obtain PFS metadata.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantWriteId

string

No

Explanation:

ID (domain_id) of an account the WRITE permission is granted to. The account with the WRITE permission can create, delete, and overwrite objects in the PFS you are creating, and can initiate or abort multipart uploads, as well as upload, copy, and assemble parts.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantReadAcpId

string

No

Explanation:

ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the PFS you are creating.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantWriteAcpId

string

No

Explanation:

ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the PFS you are creating.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantFullControlId

string

No

Explanation:

ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can perform any operation on the PFS you are creating.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantReadDeliveredId

string

No

Explanation:

ID (domain_id) of an account the READ permission is granted to. By default, this READ permission applies to all objects in the PFS.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

GrantFullControlDeliveredId

string

No

Explanation:

ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission has full control over the PFS you are creating. By default, the FULL_CONTROL permission applies to all objects in the PFS.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

Epid

string

No

Explanation:

Enterprise project ID that can be specified at PFS creation. If you have enabled EPS, you can obtain the project ID from the EPS console.

Restrictions:

The value of Epid is a UUID. Epid is not required if you have not enabled EPS.

Example: 9892d768-2d13-450f-aac7-ed0e44c2585f

Default value:

None

AvailableZone

string

No

Explanation:

Data redundancy type that can be specified at PFS creation.

Restrictions:

Multi-AZ redundancy is not available for Archive storage. If the region where the PFS is to be created does not support multi-AZ storage, the PFS uses single-AZ storage by default.

Value range:

To configure multi-AZ storage for the PFS, set this parameter to 3az. To configure single-AZ storage (default value assigned by OBS) for the PFS, you do not need to specify this parameter.

Default value:

single AZ

IsFSFileInterface

bool

No

Explanation:

Whether a PFS is created

Value range:

  • true: A PFS is created.
  • false: A bucket is created.

Default value:

false

Table 3 AclType

Constant

Default Value

Description

AclPrivate

private

Private read/write

A bucket or object can only be accessed by its owner.

AclPublicRead

public-read

Public read and private write

If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket.

If it is granted on an object, anyone can read the content and metadata of the object.

AclPublicReadWrite

public-read-write

Public read/write

If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks.

If it is granted on an object, anyone can read the content and metadata of the object.

AclPublicReadDelivered

public-read-delivered

Public read on a bucket as well as objects in the bucket

If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions, and read the content and metadata of objects in the bucket.

NOTE:

AclPublicReadDelivered does not apply to objects.

AclPublicReadWriteDelivered

public-read-write-delivered

Public read/write on a bucket as well as objects in the bucket

If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of objects in the bucket.

NOTE:

AclPublicReadWriteDelivered does not apply to objects.

AclBucketOwnerFullControl

bucket-owner-full-control

If this permission is granted on an object, only the bucket and object owners have the full control over the object.

By default, if you upload an object to a bucket of any other user, the bucket owner does not have the permissions on your object. After you grant this policy to the bucket owner, the bucket owner can have full control over your object.

Table 4 StorageClassType

Constant

Default Value

Description

StorageClassStandard

STANDARD

OBS Standard

Features low access latency and high throughput and is used for storing massive, frequently accessed (multiple times a month) or small objects (< 1 MB) requiring quick response.

StorageClassWarm

WARM

OBS Infrequent Access

Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but is instantly available when needed.

StorageClassCold

COLD

OBS Archive

Used for storing rarely accessed (once a year) data.

Responses

Table 5 List of returned results

Parameter

Type

Description

output

*BaseModel

Explanation:

Returned results. For details, see Table 6.

err

error

Explanation:

Error messages returned by the API

Table 6 BaseModel

Parameter

Type

Description

StatusCode

int

Explanation:

HTTP status code

Value range:

A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code.

Default value:

None

RequestId

string

Explanation:

Request ID returned by the OBS server

Default value:

None

ResponseHeaders

map[string][]string

Explanation:

HTTP response headers

Default value:

None

Code Examples

This example creates a PFS.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
    "fmt"
    "os"
    obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)

func main() {
    //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
    //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    ak := os.Getenv("AccessKeyID")
    sk := os.Getenv("SecretAccessKey")
    // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
    // securityToken := os.Getenv("SecurityToken")
    // Enter the endpoint corresponding to the region where the bucket is to be created. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    endPoint := "https://obs.ap-southeast-1.myhuaweicloud.com"
    // Create an obsClient instance.
    // If you use a temporary AK/SK pair and a security token to access OBS, use the obs.WithSecurityToken method to specify a security token when creating an instance.
    obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/)
    if err != nil {
        fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
    }
    input := &obs.CreateBucketInput{}
    // Specify the name of the PFS.
    input.Bucket = "examplebucket"
    // Specify the region where the bucket is to be created. The region must be the same as that in the passed endpoint. ap-southeast-1 is used as an example.
    input.Location = "ap-southeast-1"
    // Specify an access control policy for the bucket. obs.AclPrivate is used as an example.
    input.ACL = obs.AclPrivate
    // Specify the AZ type for the bucket. If this parameter is not specified, or it is specified but the involved region does not support multi-AZ storage, single-AZ storage is applied. 3az is used as an example.
    input.AvailableZone = "3az"
    // Specify the bucket type as PFS.
    input.IsFSFileInterface = true
   // Create a bucket.
    output, err := obsClient.CreateBucket(input)
    if err == nil {
        fmt.Printf("Create bucket:%s successful!\n", input.Bucket)
        fmt.Printf("RequestId:%s\n", output.RequestId)
        return
    }
    fmt.Printf("Create bucket:%s fail!\n", input.Bucket)
    if obsError, ok := err.(obs.ObsError); ok {
        fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.")
        fmt.Println(obsError.Error())
    } else {
        fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.")
        fmt.Println(err)
    }
}