استفاده از object storage پیشروزمان مطالعه این مطلب 15 دقیقه

۱- احراز هویت

برای استفاده از وب سرویس های زیرساخت پیشرو بدون واسطه (ارتباط مستقیم با وب سرویس های openstack) ابتدا می بایست با استفاده از وب سرویس identity احراز هویت صورت بگیرد.

پس از احراز هویت، با توکن صادر شده می توان وب سرویس های object storage را فراخوانی کرد.

۱-۱- آدرس پایه

آدرس پایه برای استفاده از وب سرویس احراز هویت به صورت زیر است:

http://213.233.176.11:5000

۱-۲- وب سرویس احراز هویت

۱-۲-۱- آدرس

POST<base_url>/v3/auth/tokens

۱-۲-۲- پارامترهای ورودی

NameRequiredInTypeDescription
authbodyobject.An auth object
identitybodyobject.An identity object
methodsbodyarrayThe authentication method. For password authentication,.specify password
passwordbodyobjectThe password object, contains the authentication information.
userbodyobjectA user object
domainquerystringA domain object. (use admin_domain)

نمونه اطلاعات ورودی وب سرویس احراز هویت (صدور توکن):

{    "auth": {        "identity": {            "methods": [                "password"            ],            "password": {                "user": {                    "name": "admin",                    "domain": {                        "name": "admin_domain"                   },                    "password": "adminpassword"                }            }        }    }}

۱-۲-۳- خروجی وب سرویس

NameInTypeDescription
X-Subject-TokenheaderstringThe authentication token. An authentication response returns the token ID in this header rather than in the response body.
expires_atbodystringThe date and time when the token expires.The date and time stamp format is ISO 8601:CCYY-MM-DDThh:mm:ss.sssZFor example, 2015-08-27T09:49:58.000000Z.A null value indicates that the token never expires.
tokenbodyobjectA token object.
userbodyobjectA user object.
issued_atbodystringThe date and time when the token was issued.The date and time stamp format is ISO 8601:CCYY-MM-DDThh:mm:ss.sssZFor example, 2015-08-27T09:49:58.000000Z.

نمونه خروجی وب سرویس:

 
{    "token": {        "methods": [            "password"        ],        "expires_at": "2019-07-31T15:32:17.893769Z",        "user": {            "domain": {                "id": "default",                "name": "admin_domain"            },            "id": "423f19a4ac1e4f48bbb4180756e6eb6c",            "name": "admin",            "password_expires_at": null        },        "audit_ids": [            "ZzZwkUflQfygX7pdYDBCQQ"        ],        "issued_at": "2019-07-31T14:32:17.893797Z"    }}

۲- استفاده از object storage

عناصر اصلی object storage را container ها تشکیل می دهند. به طوری که برای بارگذاری object ها در فضای ابری نیاز است ابتدا برای object ها، container ایجاد شود و از آن جایی که نام containerها در تمام سیستم بین تمام کاربران یکتا است، پیشنهاد می شود container هایی که اسامی مربوط به email یا نام کاربریتان دارند ایجاد کنید. به عنوان مثال می توانید container هایی ایجاد کنید که نام آن در هم سازی شده ی (hash) آدرس email تان باشد. به این ترتیب می توان مطمئن بود که نام آن container یکتا خواهد بود.

نکته ای که درمورد object storage وجود دارد این است که تنها مفهومی که به پوشه بندی شباهت دارد همین container ها هستند که فقط می توان از آنها در پوشه ی اصلی object storage یا همان root آنها را ایجاد کرد. در نام container ها نمی توان از علامت ممیز یا همان slash (/) استفاده کرد. پس از ایجاد container ها در داخل آنها فقط می توان object ساخت و امکان ایجاد پوشه یا directory وجود ندارد. در نام object ها می توان از slash استفاده کرد و این ویژگی این امکان را می دهد که بتوانیم ساختار پوشه و فایل را به کمک پارامترهای prefix و delimiter و یا تنها با استفاده از پارامتر path شبیه سازی کنیم.

۲-۱- آدرس پایه

آدرس پایه (base url) وب سرویس های object storage رایانش ابری پیشرو به صورت زیر است:

http://213.233.176.11:8080/swift

۲-۲- گرفتن اطلاعات container و لیست object ها

۲-۲-۱- آدرس

GET<base_url>/v1/{container}

۲-۲-۲- پارامترهای ورودی

NameRequiredInTypeDescription
container pathstringThe unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
limit query int

For an integer value n , limits the number of results to n .
prefix query string Only objects with this prefix will be returned. When combined with a delimiter query, this enables API users to simulate and traverse the objects in a container as if they were in a directory tree.
format query string The response format. Valid values are json, xml, or plain. The default is plain. If you append the format=xml or format=json query parameter to the storage account URL, the response shows extended container information serialized in that format. If you append the format=plain query parameter, the response lists the container names separated by newlines.
delimiter query string The delimiter is a single character used to split object names to present a pseudo-directory hierarchy of objects. When combined with a prefix query, this enables API users to simulate and traverse the objects in a container as if they were in a directory tree.
path query string For a string value, returns the object names that are nested in the pseudo path. Please use prefix/delimiter queries instead of using this path query.
X-Auth-Token header string Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).
Accept header string Instead of using the format query parameter, set this header to application/json, application/xml, or text/xml.

۲-۲-۳- خروجی وب سرویس

NameInTypeDescription
X-Container-Meta-nameheaderstringThe custom container metadata item, where name is the name of the metadata item. One X-Container-Meta-name response header appears for each metadata item (for each name).
Content-LengthheaderstringIf the operation succeeds, the length of the response body in bytes. On error, this is the length of the error text.
X-Container-Object-CountheaderintegerThe number of objects.
X-Container-Read (Optional)headerstringThe ACL that grants read access. If there is no ACL, this header is not returned by this operation. See Container ACLs for more information.
X-Container-Write (Optional)headerstringThe ACL that grants write access. If there is no ACL, this header is not returned by this operation. See Container ACLs for more information.
X-TimestampheaderintegerThe date and time in UNIX Epoch time stamp format when the account, container, or object was initially created as a current version. For example, 1440619048 is equivalent to Mon, Wed, 26 Aug 2015 19:57:28 GMT.
Content-TypeheaderstringIf the operation succeeds, this value is the MIME type of the list response. The MIME type is determined by the listing format specified by the request and will be one of text/plain, application/json, application/xml, or text/xml. If the operation fails, this value is the MIME type of the error text in the response body.
hashbodystringThe MD5 checksum value of the object content.
last_modifiedbodystringThe date and time when the object was last modified.The date and time stamp format is ISO 8601:CCYY-MM-DDThh:mm:ss±hh:mmFor example, 2015-08-27T09:49:58-05:00.The ±hh:mm value, if included, is the time zone as an offset from UTC. In the previous example, the offset value is -05:00.
content_typebodystringThe content type of the object.
bytesbodyintegerThe total number of bytes that are stored in Object Storage for the container.
namebodystringThe name of the object.
symlink_pathbodystringThis field exists only when the object is symlink. This is the target path of the symlink object.

۲-۳- ایجاد container

هر کاربر می تواند به تعداد بی نهایت container ایجاد کند. نام container در تمام object storage یکتا است. به همین دلیل پیشنهاد می شود از اسامی خاص و یکتا و مختص کاربر استفاده شود.

یک container را می توان به صورت public و یا private (قابل تنظیم با ACL) ایجاد کرد. در اینصورت با توجه به نوع container تمام object های داخل container نیز public و یا private خواهند بود.

۲-۳-۱- آدرس

PUT<base_url>/v1/{container}

۲-۳-۲- پارامترهای ورودی

NameRequiredInType Description
containerpathstring The unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
X-Auth-Tokenheaderstring Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).
X-Container-Read header string .r:*Sets a container access control list (ACL) that grants write access. The scope of the access is specific to the container. The ACL grants the ability to perform PUT, POST and DELETE operations on objects in the container. It does not grant write access to the container metadata.
The format of the ACL is dependent on the authorization system used by the Object Storage service. See Container ACLs for more information.
X-Container-Write header string Sets a container access control list (ACL) that grants write access. The scope of the access is specific to the container. The ACL grants the ability to perform PUT, POST and DELETE operations on objects in the container. It does not grant write access to the container metadata.
The format of the ACL is dependent on the authorization system used by the Object Storage service. See Container ACLs for more information.
X-Container-Meta-Access-Control-Allow-Origin header string Originating URLs allowed to make cross-origin requests (CORS), separated by spaces. This heading applies to the container only, and all objects within the container with this header applied are CORS-enabled for the allowed origin URLs. A browser (user-agent) typically issues a preflighted request , which is an OPTIONS call that verifies the origin is allowed to make the request. The Object Storage service returns 200 if the originating URL is listed in this header parameter, and issues a 401 if the originating URL is not allowed to make a cross-origin request. Once a 200 is returned, the browser makes a second request to the Object Storage service to retrieve the CORS-enabled object.

۲-۳-۳- خروجی وب سرویس

NameInTypeDescription
DateheaderstringThe date and time the system responded to the request, using the preferred format of RFC 7231 as shown in this example Thu, 16 Jun 2016 15:10:38 GMT. The time is always in UTC.
X-TimestampheaderintegerThe date and time in UNIX Epoch time stamp format when the account, container, or object was initially created as a current version. For example, 1440619048 is equivalent to Mon, Wed, 26 Aug 2015 19:57:28 GMT.
Content-LengthheaderstringIf the operation succeeds, this value is zero (0) or the length of informational or error text in the response body.
Content-TypeheaderstringIf the operation succeeds, this value is the MIME type of the list response. The MIME type is determined by the listing format specified by the request and will be one of text/plain, application/json, application/xml, or text/xml. If the operation fails, this value is the MIME type of the error text in the response body.

۲-۴- حذف container

در صورتی که در container هیچ objectی وجود نداشته باشد، می توان container را حذف کرد.

۲-۴-۱- آدرس

DELETE<base_url>/v1/{container}

۲-۴-۲- پارامترهای ورودی

NameRequiredInTypeDescription
containerpathstringThe unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
X-Auth-TokenheaderstringAuthentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).

۲-۵- دریافت object

جهت دریافت یا دانلود object از این وب سرویس می توان استفاده کرد. برای دانلود object های public نیازی به پارامترهای احراز هویت نیست، اما برای دریافت object های private می بایست پارامتر احراز هویت در header تنظیم شود.

۲-۵-۱- آدرس

GET<base_url>/v1/{container}/{object}

۲-۵-۲- پارامترهای ورودی

NameRequiredInType Description
containerpathstring The unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
objectpathstring The unique name for the object.
X-Auth-Token header string Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).

۲-۶- بارگذاری object

برای بارگذاری object باید محتوای فایل را به همراه اطلاعات دیگر از جمله نام به سرور ارسال کرد.

۲-۶-۱- آدرس

PUT<base_url>/v1/{container}/{object}

۲-۶-۲- پارامترهای ورودی

NameRequiredInType Description
containerpathstring The unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
objectpathstring The unique name for the object.
X-Auth-Tokenheaderstring Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).
temp_url_sig query string Used with temporary URLs to sign the request with an HMAC-SHA1 cryptographic signature that defines the allowed HTTP method, expiration date, full path to the object, and the secret key for the temporary URL. For more information about temporary URLs, see Temporary URL middleware.
temp_url_expires query integer The date and time in UNIX Epoch time stamp format or ISO 8601 UTC timestamp when the signature for temporary URLs expires. For example, 1440619048 or 2015-08-26T19:57:28Z is equivalent to Mon, Wed, 26 Aug 2015 19:57:28 GMT. For more information about temporary URLs, see Temporary URL middleware.
Transfer-Encoding  header string Set to chunked to enable chunked transfer encoding. If used, do not set the Content-Length header to a non-zero value.
Content-Type header string Sets the MIME type for the object.
X-Detect-Content-Type  header boolean If set to true, Object Storage guesses the content type based on the file extension and ignores the value sent in the Content-Type header, if present.
Content-Disposition  header string If set, specifies the override behavior for the browser. For example, this header might specify that the browser use a download program to save this file rather than show the file, which is the default.
Content-Encoding  header string If set, the value of the Content-Encoding metadata.
X-Delete-At header integer The date and time in UNIX Epoch time stamp format when the system removes the object. For example, 1440619048 is equivalent to Mon, Wed, 26 Aug 2015 19:57:28 GMT. The value should be a positive integer corresponding to a time in the future. If both X-Delete-After and X-Delete-At are set then X-Delete-After takes precedence.
X-Delete-After header integer The number of seconds after which the system removes the object. The value should be a positive integer. Internally, the Object Storage system uses this value to generate an X-Delete-At metadata item. If both X-Delete-After and X-Delete-At are set then X-Delete-After takes precedence.
X-Object-Meta-name  header string The object metadata, where name is the name of the metadata item. You must specify an X-Object-Meta-name header for each metadata name item that you want to add or update.

۲-۶-۳- خروجی وب سرویس

NameInTypeDescription
Content-LengthheaderstringIf the operation succeeds, this value is zero (0) or the length of informational or error text in the response body.
ETagheaderstringThe MD5 checksum of the uploaded object content. The value is not quoted. If it is an SLO, it would be MD5 checksum of the segments’ etags.
DateheaderstringThe date and time the system responded to the request, using the preferred format of RFC 7231 as shown in this example Thu, 16 Jun 2016 15:10:38 GMT. The time is always in UTC.
Content-TypeheaderstringIf the operation succeeds, this value is the MIME type of the object. If the operation fails, this value is the MIME type of the error text in the response body.
last_modifiedbodystringThe date and time when the object was last modified.The date and time stamp format is ISO 8601:CCYY-MM-DDThh:mm:ss±hh:mmFor example, 2015-08-27T09:49:58-05:00.The ±hh:mm value, if included, is the time zone as an offset from UTC. In the previous example, the offset value is -05:00.

۲-۷- حذف object

با استفاده از این وب سرویس و ارسال نام object (نام object به عنوان شناسه یکتا برای object محسوب می شود) می توان object را حذف کرد.

۲-۷-۱- آدرس

DELETE<base_url>/v1/{container}/{object}

۲-۷-۲- پارامترهای ورودی

NameRequiredInType Description
container path string The unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
object path string The unique name for the object.
X-Auth-Token header string Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).

۲-۸- گرفتن اطلاعات object

با استفاده از این وب سرویس می توان اطلاعات object (نه خود object) را دریافت کرد. یک نمونه از کاربرد آن میتواند این باشد که جهت بررسی وجود یا عدم وجود object به کار گرفته شود.

۲-۸-۱- آدرس

HEAD<base_url>/v1/{container}/{object}

۲-۸-۲- پارامترهای ورودی

NameRequiredInType Description
containerpathstring The unique (within an account) name for the container. The container name must be from 1 to 256 characters long and can start with any character and contain any pattern. Character set must be UTF-8. The container name cannot contain a slash (/) character because this character delimits the container and object name. For example, the path /v1/account/www/pages specifies the www container, not the www/pages container.
objectpathstring The unique name for the object.
X-Auth-Token header string Authentication token. If you omit this header, your request fails unless the account owner has granted you access through an access control list (ACL).

۲-۸-۳- خروجی وب سرویس

NameInTypeDescription
Content-LengthheaderstringHEAD operations do not return content. The Content-Length header value is not the size of the response body but is the size of the object, in bytes.
ETagheaderstringFor objects smaller than 5 GB, this value is the MD5 checksum of the object content. The value is not quoted. For manifest objects, this value is the MD5 checksum of the concatenated string of ETag values for each of the segments in the manifest, and not the MD5 checksum of the content that was downloaded. Also the value is enclosed in double-quote characters. You are strongly recommended to compute the MD5 checksum of the response body as it is received and compare this value with the one in the ETag header. If they differ, the content was corrupted, so retry the operation.
DateheaderstringThe date and time the system responded to the request, using the preferred format of RFC 7231 as shown in this example Thu, 16 Jun 2016 15:10:38 GMT. The time is always in UTC.
Content-TypeheaderstringIf the operation succeeds, this value is the MIME type of the object. If the operation fails, this value is the MIME type of the error text in the response body.
Last-ModifiedbodystringThe date and time when the object was created or its metadata was changed. The date and time is formatted as shown in this example: Fri, 12 Aug 2016 14:24:16 GMTThe time is always in UTC.
Content-Disposition headerstringIf present, specifies the override behavior for the browser. For example, this header might specify that the browser use a download program to save this file rather than show the file, which is the default. If not set, this header is not returned by this operation.

2 دیدگاه On استفاده از object storage پیشرو

پاسخ دادن:

ایمیل شما نمایش داده نمی‌شود.