-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.9.1-6 - Retries, DummyAuthorization, documentation
Added: Automatic retires for hcpsdk.Connection.request() in case of a timeout or connection abort. A DummyAuthorization class for use with the Default Namespace An appendiy on the difference when working with the Default Namespace
- Loading branch information
Showing
12 changed files
with
298 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
0.9.1-6 2015-02-18 | ||
------------------ | ||
Changed: - | ||
Added: Automatic retires for hcpsdk.Connection.request() in case of a | ||
timeout or connection abort. | ||
A DummyAuthorization class for use with the Default Namespace | ||
An appendiy on the difference when working with the Default | ||
Namespace | ||
Fixed: - | ||
|
||
Version Date | ||
------------------ | ||
Changed: - | ||
Added: - | ||
Fixed: - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include DESCRIPTION.rst | ||
include CHANGELOG.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Appendixes | ||
========== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
A1_apdx1_defns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Appendix 1 - Default Namespace | ||
============================== | ||
|
||
**hcpsdk** is primarily targeting the :term:`authenticated Namespaces <Namespace>` | ||
invented with HCP version 3. | ||
|
||
Nevertheless, it is possible to use **hcpsdk** with the legacy :term:`Default Namespace` | ||
by taking notice of a few differences: | ||
|
||
* As there is no user authentication with the Default Namespace, use the | ||
*hcpsdk.DummyAuthorization* class as the *authorization* argument when | ||
instantiating an *hcpsdk.Target* | ||
|
||
* Different from authenticated Namespaces, the root folder for requests is | ||
``/fcfs_data`` (instead of ``/rest``) | ||
|
||
* An *HEAD* request for an object stored in the Default Namespace will yield very | ||
limited object metadata, only. If you need more, you need to request the | ||
metadata by a *GET* from ``/fcfs_metadata/your/path/to/object/core-metadata.xml`` | ||
|
||
* The Default Namespace can have a single annotation (custom metadata), only. | ||
You need to request it by a *GET* from ``/fcfs_metadata/your/path/to/object/custom-metadata.xml`` | ||
|
||
* Several actions you can trigger by a *POST* request to an authenticated Namespace need | ||
to be executed by a *PUT* to one of the files in ``/fcfs_metadata/your/path/to/object/``. | ||
|
||
|
||
.. Note:: | ||
|
||
Consult the manual **Using the Default Namespace** available from the HCP | ||
System and Tenant Management Consoles for details about working with the | ||
Default Namespace. | ||
|
||
|
||
Example | ||
^^^^^^^ | ||
|
||
:: | ||
|
||
>>> import hcpsdk | ||
>>> | ||
>>> auth = hcpsdk.DummyAuthorization() | ||
>>> t = hcpsdk.Target('default.default.hcp1.snomis.local', auth, port=443) | ||
>>> c = hcpsdk.Connection(t) | ||
>>> c.connect_time | ||
'0.000000000010' | ||
>>> | ||
>>> r = c.PUT('/fcfs_data/hcpsdk/test1.txt', body='This is an example', params={'index': 'true'}) | ||
>>> c.response_status, c.response_reason | ||
(201, 'Created') | ||
>>> | ||
>>> r = c.HEAD('/fcfs_data/hcpsdk/test1.txt') | ||
>>> c.response_status, c.response_reason | ||
(200, 'OK') | ||
>>> c.getheaders() | ||
[('Date', 'Wed, 18 Feb 2015 16:48:49 GMT'), | ||
('Server', 'HCP V7.1.0.10'), | ||
('X-ArcServicedBySystem', 'hcp1.snomis.local'), | ||
('X-ArcClusterTime', '1424278129'), | ||
('X-RequestId', '6BB17FCE72FECA84'), | ||
('X-HCP-ServicedBySystem', 'hcp1.snomis.local'), | ||
('X-HCP-Time', '1424278129'), | ||
('X-HCP-SoftwareVersion', '7.1.0.10'), | ||
('ETag', '"68791e1b03badd5e4eb9287660f67745"'), | ||
('Cache-Control', 'no-cache,no-store'), | ||
('Pragma', 'no-cache'), | ||
('Expires', 'Thu, 01 Jan 1970 00:00:00 GMT'), | ||
('Content-Type', 'text/plain'), | ||
('Content-Length', '18'), | ||
('X-ArcPermissionsUidGid', 'mode=0100400; uid=0; gid=0'), | ||
('X-ArcTimes', 'ctime=1424278066; mtime=1424278066; atime=1424278065'), | ||
('X-ArcSize', '18')] | ||
>>> | ||
>>> r = c.GET('/fcfs_data/hcpsdk/test1.txt') | ||
>>> c.response_status, c.response_reason | ||
(200, 'OK') | ||
>>> c.read() | ||
b'This is an example' | ||
>>> c.service_time2 | ||
0.00039696693420410156 | ||
>>> | ||
>>> r = c.DELETE('/fcfs_data/hcpsdk/test1.txt') | ||
>>> c.response_status, c.response_reason | ||
(200, 'OK') | ||
>>> c.service_time2 | ||
0.0001819133758544922 | ||
>>> | ||
>>> c.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import sys | ||
from os.path import join, normpath | ||
import time | ||
import pprint | ||
import http.client | ||
import hcpsdk | ||
|
||
T_NAMESPACE = 'n1.m.hcp1.snomis.local' | ||
T_DAAC = 'n' | ||
T_DAAC_PWD = 'n01' | ||
T_PORT = 443 | ||
T_DEBUG = True | ||
|
||
T_OBJ = 128 # the object we will use in a run (from objs) | ||
T_NAME = '/rest/hcpsdk/failtest' # path to write to | ||
|
||
T_OBJ = '256kbfile' # the source object | ||
|
||
|
||
if __name__ == '__main__': | ||
if T_DEBUG: | ||
import logging | ||
logging.basicConfig(level=logging.DEBUG, style='{', format='{levelname:>5s} {msg}') | ||
# noinspection PyShadowingBuiltins | ||
print = pprint = logging.info | ||
|
||
# the place where we will find the needed source objects | ||
if sys.platform == 'win32': | ||
T_INPATH = 'd:\\__files' | ||
elif sys.platform == 'darwin': | ||
T_INPATH = '/Volumes/dev/__files' | ||
else: | ||
sys.exit('source path is undefined') | ||
T_OBJPATH = join(T_INPATH, T_OBJ) | ||
|
||
print("--> Init <hcptarget> object") | ||
try: | ||
auth = hcpsdk.NativeAuthorization(T_DAAC, T_DAAC_PWD) | ||
hcptarget = hcpsdk.Target(T_NAMESPACE, auth, T_PORT) | ||
except hcpsdk.HcpsdkError as e: | ||
sys.exit("Fatal: {}".format(e.errText)) | ||
|
||
print("--> Init <connection> object") | ||
conntimes = 0.0 | ||
outer_contime = time.time() | ||
try: | ||
con = hcpsdk.Connection(hcptarget, debuglevel=0, idletime=600, retries=2) | ||
except Exception as e: | ||
sys.exit('Exception: {}'.format(str(e))) | ||
|
||
print('--> PUT object {}'.format(T_OBJPATH)) | ||
with open(join(T_INPATH,T_OBJ), 'rb') as inHdl: | ||
r = con.PUT(T_NAME, inHdl) | ||
print('PUT result: {}'.format(con.response_status)) | ||
|
||
|
||
print('--> GET object {}'.format(T_OBJPATH)) | ||
try: | ||
r = con.HEAD(T_NAME) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
print('--> sleep 10 seconds') | ||
time.sleep(10) | ||
print('-' * 70) | ||
|
||
print('--> GET object again {}'.format(T_OBJPATH)) | ||
try: | ||
r = con.GET(T_NAME) | ||
except Exception as e: | ||
print('Exception: {}'.format(str(e))) | ||
else: | ||
print('--> read') | ||
x = con.read() | ||
print('--> read {} bytes'.format(len(x))) | ||
|
||
print('--> Close <connection>') | ||
con.close() |
Oops, something went wrong.