本文整理汇总了Python中girder_client.GirderClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python GirderClient.post方法的具体用法?Python GirderClient.post怎么用?Python GirderClient.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类girder_client.GirderClient
的用法示例。
在下文中一共展示了GirderClient.post方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NewtIntegrationTest
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
class NewtIntegrationTest(BaseIntegrationTest):
def __init__(self, name, girder_url, girder_user, girder_password, machine, job_timeout=60 * 5):
super(NewtIntegrationTest, self).__init__(name, girder_url, girder_user, girder_password, job_timeout)
self._cluster_id = None
self._machine = machine
def setUp(self):
# First authenticate with NEWT
self._session = Session()
r = self._session.post(
"https://newt.nersc.gov/newt/auth", {"username": self._girder_user, "password": self._girder_password}
)
self.assertEqual(r.status_code, 200)
print r.json()
self._newt_session_id = r.json()["newt_sessionid"]
# Now authenticate with Girder using the session id
url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
r = self._session.put(url)
self.assertEqual(r.status_code, 200)
url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
r = self._session.put(url)
self.assertEqual(r.status_code, 200)
url = "%s/api/v1" % self._girder_url
self._client = GirderClient(apiUrl=url)
self._client.token = self._session.cookies["girderToken"]
user = self._client.get("user/me")
self._user_id = user["_id"]
r = self._client.listFolder(self._user_id, "user", name="Private")
r = list(r)
self.assertEqual(len(r), 1)
self._private_folder_id = r[0]["_id"]
def tearDown(self):
super(NewtIntegrationTest, self).tearDown()
if self._cluster_id:
try:
url = "clusters/%s" % self._cluster_id
self._client.delete(url)
except Exception:
traceback.print_exc()
def create_cluster(self):
body = {"config": {"host": self._machine}, "name": "NewtIntegrationTest", "type": "newt"}
r = self._client.post("clusters", data=json.dumps(body))
self._cluster_id = r["_id"]
# Now test the connection
r = self._client.put("clusters/%s/start" % self._cluster_id)
sleeps = 0
while True:
time.sleep(1)
r = self._client.get("clusters/%s/status" % self._cluster_id)
if r["status"] == "running":
break
elif r["status"] == "error":
r = self._client.get("clusters/%s/log" % self._cluster_id)
self.fail(str(r))
if sleeps > 9:
self.fail("Cluster never moved into running state")
sleeps += 1
def assert_output(self):
r = self._client.listItem(self._output_folder_id)
self.assertEqual(len(r), 4)
stdout_item = None
for i in r:
if i["name"].startswith("CumulusIntegrationTestJob-%s.o" % self._job_id):
stdout_item = i
break
self.assertIsNotNone(stdout_item)
r = self._client.get("item/%s/files" % i["_id"])
self.assertEqual(len(r), 1)
url = "%s/api/v1/file/%s/download" % (self._girder_url, r[0]["_id"])
r = self._session.get(url)
self.assertEqual(r.content, self._data)
def test(self):
try:
self.create_cluster()
self.create_script()
self.create_input()
self.create_output_folder()
self.create_job()
self.submit_job(timeout=self._job_timeout)
self.assert_output()
except HttpError as error:
self.fail(error.responseText)
示例2: _update_girder
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
def _update_girder(taskflow, body):
taskflow = to_taskflow(taskflow)
taskflow_id = taskflow['id']
girder_token = taskflow['girder_token']
girder_api_url = taskflow['girder_api_url']
client = GirderClient(apiUrl=girder_api_url)
client.token = girder_token
client = _create_girder_client(girder_api_url, girder_token)
# If this is a retry then we have already create a task get it from
# the current tasks headers.
if body['retries'] > 0:
taskflow_task_id = \
current_task.request.headers[TASKFLOW_TASK_ID_HEADER]
# Celery always fires the postrun handler with a state of SUCCESS
# for retries. So we need to save the retries here so we can
# determine in the postrun handler if the task is really complete.
current_task.request.headers[TASKFLOW_RETRY_HEADER] \
= body['retries']
else:
# This is a new task so create a taskflow task instance
body = {
'celeryTaskId': body['id'],
'name': body['task']
}
url = 'taskflows/%s/tasks' % taskflow_id
r = client.post(url, data=json.dumps(body))
taskflow_task_id = r['_id']
return taskflow, taskflow_task_id
示例3: ensure_user
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
ensure_user(client,
login=user,
password=password,
email='[email protected]',
firstName='Girder',
lastName='Admin')
client.authenticate(user, password)
s3_assetstore_name = 's3'
if find_assetstore(s3_assetstore_name) is None:
client.post('assetstore',
parameters=dict(name=s3_assetstore_name,
type=str(AssetstoreType.S3),
bucket=args.s3,
accessKeyId=args.aws_key_id,
secret=args.aws_secret_key))
client.put(
'system/plugins',
parameters=dict(plugins=json.dumps(['jobs', 'worker', 'osumo']))
)
client.put('system/restart')
sleep(30)
client.put('system/setting',
parameters=dict(list=json.dumps([
dict(key='worker.broker', value=args.broker),
dict(key='worker.backend', value=args.broker),
示例4: BaseIntegrationTest
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
class BaseIntegrationTest(unittest.TestCase):
def __init__(self, name, girder_url, girder_user, girder_password, job_timeout=60, cleanup=True):
super(BaseIntegrationTest, self).__init__(name)
self._job_id = None
self._script_id = None
self._output_folder_id = None
self._input_folder_id = None
self._girder_url = girder_url
self._girder_user = girder_user
self._girder_password = girder_password
self._job_timeout = job_timeout
self._data = 'Need more input!'
self._cleanup = cleanup
def setUp(self):
url = '%s/api/v1' % self._girder_url
self._client = GirderClient(apiUrl=url)
self._client.authenticate(self._girder_user,
self._girder_password)
user = self._client.get('user/me')
self._user_id = user['_id']
r = list(self._client.listFolder(self._user_id, 'user', name='Private'))
self.assertEqual(len(r), 1)
self._private_folder_id = r[0]['_id']
def tearDown(self):
if not self._cleanup:
return
if self._job_id:
try:
url = 'jobs/%s' % self._job_id
self._client.delete(url)
except Exception as e:
traceback.print_exc()
if self._script_id:
try:
url = 'scripts/%s' % self._script_id
self._client.delete(url)
except Exception:
traceback.print_exc()
if self._output_folder_id:
try:
url = 'folder/%s' % self._output_folder_id
self._client.delete(url)
except Exception:
traceback.print_exc()
if self._input_folder_id:
try:
url = 'folder/%s' % self._input_folder_id
self._client.delete(url)
except Exception:
traceback.print_exc()
def create_script(self, commands=[
'sleep 10', 'cat CumulusIntegrationTestInput'
]):
body = {
'commands': commands,
'name': 'CumulusIntegrationTestLob'
}
r = self._client.post('scripts', data=json.dumps(body))
self._script_id = r['_id']
def create_input(self, folder_name='CumulusInput'):
r = self._client.createFolder(self._private_folder_id, folder_name)
self._input_folder_id = r['_id']
size = len(self._data)
item = self._client.uploadFile(self._input_folder_id,
StringIO(self._data), 'CumulusIntegrationTestInput', size,
parentType='folder')
self._item_id = item['itemId']
def create_output_folder(self, folder_name='CumulusOutput'):
r = self._client.createFolder(self._private_folder_id, folder_name)
self._output_folder_id = r['_id']
def create_job(self, job_name='CumulusIntegrationTestJob', tail=None):
body = {
'name': job_name,
'scriptId': self._script_id,
'output': [{
'folderId': self._output_folder_id,
'path': '.'
}],
'input': [
{
'folderId': self._input_folder_id,
'path': '.'
}
]
#.........这里部分代码省略.........
示例5: GirderClient
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
client = GirderClient(host=args.host, port=args.port)
register_and_authenticate(client,
login=args.user,
password=args.password,
email='{}@localhost.com'.format(args.user),
firstName='Girder',
lastName='Admin')
local_assetstore_name = 'local'
if find_assetstore(local_assetstore_name) is None:
client.post('assetstore',
parameters=dict(name=local_assetstore_name,
type=str(AssetstoreType.FILESYSTEM),
root=os.path.join(args.data_root,
'assetstores',
'local'),
readOnly="false"))
client.put('system/plugins',
parameters=dict(plugins=json.dumps(['celery_jobs',
'climos_test',
'user_quota',
'hdfs_assetstore',
'jobs',
'romanesco',
'sparktest'])))
client.put('system/restart')
示例6: len
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
# We use the directory name as the collection name in Girder.
fullpath = os.path.join(root, file)
analysis_filename = os.path.basename(fullpath)
analysis_name = os.path.splitext(analysis_filename)[0]
analysis_dir = os.path.dirname(fullpath)
collection_name = os.path.basename(analysis_dir)
# Create this collection if it doesn't already exist.
collection_search = c.get('resource/search', parameters={
'q': collection_name,
'types': '["collection"]'
})
if len(collection_search["collection"]) == 0:
collection = c.post('collection', parameters={
'name': collection_name,
'description': collection_name,
'public': 'true'
})
c.post('folder', parameters={
'parentType': 'collection',
'parentId': collection['_id'],
'name': 'Data',
'description': 'Data Folder',
'public': 'true'
})
c.post('folder', parameters={
'parentType': 'collection',
'parentId': collection['_id'],
'name': 'Analyses',
'description': 'Analysis folder',
'public': 'true'
示例7: open
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
try:
# Now download the dataset
(fd, filepath) = tempfile.mkstemp()
os.close(fd)
client.downloadFile(fileId, filepath)
# Create temp file and convert to GeoJs contour JSON format
output_dir = tempfile.mkdtemp()
output_filepath = os.path.join(output_dir, output_file_name)
with open(output_filepath, 'w') as fp:
fp.write(json_util.dumps(convert(filepath, variable, timestep)))
# Create an item for this file
output_item = client.createItem(dataset_folder_id, output_file_name, output_file_name)
# Now upload the result
client.uploadFileToItem(output_item['_id'], output_filepath)
output_item_id = output_item['_id']
# Finally promote item to dataset
client.post('minerva_dataset/%s/dataset' % output_item_id)
finally:
if filepath and os.path.exists(filepath):
os.remove(filepath)
if output_dir and os.path.exists(output_dir):
shutil.rmtree(output_dir)
示例8: len
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
"user",
{
"login": "girder",
"password": "girder",
"email": "[email protected]",
"firstName": "Girder",
"lastName": "Admin",
},
)
c.authenticate("girder", "girder")
# Create a tangelo hub collection if there isn't one
coll_search = c.get("resource/search", parameters={"q": "Default", "types": '["collection"]'})
if len(coll_search["collection"]) == 0:
collection = c.post(
"collection", parameters={"name": "Default", "description": "Default workspace", "public": "true"}
)
c.post(
"folder",
parameters={
"parentType": "collection",
"parentId": collection["_id"],
"name": "Data",
"description": "Data Folder",
"public": "true",
},
)
c.post(
"folder",
parameters={
"parentType": "collection",
示例9: NewtIntegrationTest
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import post [as 别名]
class NewtIntegrationTest(BaseIntegrationTest):
def __init__(self, name, girder_url, girder_user, girder_password, machine,
job_timeout=60*5):
super(NewtIntegrationTest, self).__init__(name, girder_url, girder_user,
girder_password, job_timeout)
self._cluster_id = None
self._machine = machine
def setUp(self):
# First authenticate with NEWT
self._session = Session()
r = self._session.post('https://newt.nersc.gov/newt/auth',
{
'username': self._girder_user,
'password': self._girder_password})
self.assertEqual(r.status_code, 200)
print r.json()
self._newt_session_id = r.json()['newt_sessionid']
# Now authenticate with Girder using the session id
url = '%s/api/v1/newt/authenticate/%s' % (self._girder_url, self._newt_session_id)
r = self._session.put(url)
self.assertEqual(r.status_code, 200)
url = '%s/api/v1/newt/authenticate/%s' % (self._girder_url, self._newt_session_id)
r = self._session.put(url)
self.assertEqual(r.status_code, 200)
url = '%s/api/v1' % self._girder_url
self._client = GirderClient(apiUrl=url)
self._client.token = self._session.cookies['girderToken']
user = self._client.get('user/me')
self._user_id = user['_id']
r = self._client.listFolder(self._user_id, 'user', name='Private')
self.assertEqual(len(r), 1)
self._private_folder_id = r[0]['_id']
def tearDown(self):
super(NewtIntegrationTest, self).tearDown()
if self._cluster_id:
try:
url = 'clusters/%s' % self._cluster_id
self._client.delete(url)
except Exception:
traceback.print_exc()
def create_cluster(self):
body = {
'config': {
'host': self._machine
},
'name': 'NewtIntegrationTest',
'type': 'newt'
}
r = self._client.post('clusters', data=json.dumps(body))
self._cluster_id = r['_id']
# Now test the connection
r = self._client.put('clusters/%s/start' % self._cluster_id)
sleeps = 0
while True:
time.sleep(1)
r = self._client.get('clusters/%s/status' % self._cluster_id)
if r['status'] == 'running':
break
elif r['status'] == 'error':
r = self._client.get('clusters/%s/log' % self._cluster_id)
self.fail(str(r))
if sleeps > 9:
self.fail('Cluster never moved into running state')
sleeps += 1
def assert_output(self):
r = self._client.listItem(self._output_folder_id)
self.assertEqual(len(r), 4)
stdout_item = None
for i in r:
if i['name'].startswith('CumulusIntegrationTestJob-%s.o' % self._job_id):
stdout_item = i
break
self.assertIsNotNone(stdout_item)
r = self._client.get('item/%s/files' % i['_id'])
self.assertEqual(len(r), 1)
url = '%s/api/v1/file/%s/download' % (self._girder_url, r[0]['_id'])
r = self._session.get(url)
self.assertEqual(r.content, self._data)
def test(self):
try:
#.........这里部分代码省略.........