Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
John Tourtellott
ACE3P Extensions
Commits
28fa919f
Commit
28fa919f
authored
Dec 23, 2019
by
John Tourtellott
Browse files
Update for latest smtk API and Girder session on NERSC/Spin
Includes supporting newt session id for authentication
parent
bed8ec40
Changes
3
Hide whitespace changes
Inline
Side-by-side
simulation-workflows/internal/writers/cumulusclient.py
View file @
28fa919f
...
...
@@ -71,7 +71,10 @@ class CumulusClient():
# Getting mixed signals on what listFolder returns
# I *think* it is a generator
try
:
self
.
_private_folder_id
=
r
.
next
()[
'_id'
]
if
sys
.
version_info
>=
(
3
,
2
):
self
.
_private_folder_id
=
next
(
r
)[
'_id'
]
else
:
self
.
_private_folder_id
=
r
.
next
()[
'_id'
]
except
Exception
as
ex
:
# But just in case
self
.
_private_folder_id
=
r
[
0
][
'_id'
]
...
...
simulation-workflows/internal/writers/nersc.py
View file @
28fa919f
...
...
@@ -65,7 +65,12 @@ def submit_ace3p(scope, sim_item):
check_file
(
path
,
'Cannot find simulation input file at %s'
)
# Start NERSC session
login_nersc
(
scope
,
sim_item
)
scope
.
newt_sessionid
=
None
sessionid
=
login_nersc
(
scope
,
sim_item
)
print
(
'newt_sessionid'
,
sessionid
)
if
sessionid
is
None
or
sessionid
==
""
:
raise
RuntimeError
(
'ERROR: Unable to get valid session id'
)
scope
.
newt_sessionid
=
sessionid
# Initialize CumulusClient
scope
.
cumulus
=
create_cumulus_client
(
scope
,
sim_item
)
...
...
@@ -117,35 +122,48 @@ def release_resources(scope):
# ---------------------------------------------------------------------
def
login_nersc
(
scope
,
sim_item
):
'''
Logs into NERSC and gets session i
d
'''
Returns NEWT session id, logging into NERSC if specifie
d
Note that this method must *also* initialize NewtClient instance
'''
scope
.
newt_sessionid
=
None
nersc_url
=
'https://newt.nersc.gov/newt'
# Check if sesson id provided
credentials_item
=
sim_item
.
find
(
'NERSCCredentials'
)
credentials_type
=
credentials_item
.
value
()
if
credentials_type
==
'newt_sessionid'
:
session_item
=
credentials_item
.
find
(
'NEWTSessionId'
)
session_id
=
session_item
.
value
()
scope
.
nersc
=
NewtClient
(
nersc_url
,
session_id
)
return
session_id
elif
credentials_type
!=
'login'
:
raise
RuntimeError
(
'ERROR - Unrecognized credentials_type'
,
credentials_type
)
# Check user inputs
username
=
get_string
(
sim_item
,
'NERSCAccountName'
)
print
(
'username'
,
username
)
if
not
username
:
raise
Exception
(
'ERROR: NERSC account name not specified'
)
#
if not username:
#
raise Exception('ERROR: NERSC account name not specified')
password
=
get_string
(
sim_item
,
'NERSCAccountPassword'
)
print
(
'password length'
,
len
(
password
))
if
not
password
:
raise
Exception
(
'ERROR: NERSC account password not specified'
)
# if not password:
# raise Exception('ERROR: NERSC account password not specified')
mfa
=
get_string
(
sim_item
,
'NERSCMultfactorToken'
)
nersc_url
=
'https://newt.nersc.gov/newt'
scope
.
nersc
=
NewtClient
(
nersc_url
)
r
=
scope
.
nersc
.
login
(
username
,
password
)
scope
.
newt_sessionid
=
scope
.
nersc
.
get_sessionid
()
print
(
'newt_sessionid'
,
scope
.
newt_sessionid
)
r
=
scope
.
nersc
.
login
(
username
,
password
+
mfa
)
return
scope
.
nersc
.
get_sessionid
()
# ---------------------------------------------------------------------
def
create_cumulus_client
(
scope
,
sim_item
):
'''Instantiates Cumulus client
'''
item
=
sim_item
.
find
(
'CumulusHost'
)
cumulus_item
=
smtk
.
attribute
.
to_concrete
(
item
)
cumulus_
item
=
sim_item
.
find
(
'CumulusHost'
)
#
cumulus_item = smtk.attribute.to_concrete(item)
cumulus_host
=
cumulus_item
.
value
(
0
)
if
not
cumulus_host
:
raise
Exception
(
'ERROR: Cumulus host not specified'
)
...
...
@@ -362,12 +380,11 @@ def get_integer(group_item, name):
if
not
item
.
isEnabled
():
return
None
concrete_item
=
smtk
.
attribute
.
to_concrete
(
item
)
if
concrete_item
.
type
()
!=
smtk
.
attribute
.
Item
.
IntType
:
if
item
.
type
()
!=
smtk
.
attribute
.
Item
.
IntType
:
print
(
'WARNING: item
\"
%s
\"
not an integer item'
%
name
)
return
None
return
concrete_
item
.
value
(
0
)
return
item
.
value
(
0
)
# ---------------------------------------------------------------------
def
get_string
(
group_item
,
name
):
...
...
@@ -383,9 +400,8 @@ def get_string(group_item, name):
if
not
item
.
isEnabled
():
return
None
concrete_item
=
smtk
.
attribute
.
to_concrete
(
item
)
if
concrete_item
.
type
()
!=
smtk
.
attribute
.
Item
.
StringType
:
if
item
.
type
()
!=
smtk
.
attribute
.
Item
.
StringType
:
print
(
'WARNING: item
\"
%s
\"
not a string item'
%
name
)
return
None
return
concrete_
item
.
value
(
0
)
return
item
.
value
(
0
)
simulation-workflows/internal/writers/newtclient.py
View file @
28fa919f
...
...
@@ -24,9 +24,9 @@ class NewtClient():
'''
# ---------------------------------------------------------------------
def
__init__
(
self
,
base_url
):
def
__init__
(
self
,
base_url
,
session_id
=
None
):
self
.
_base_url
=
base_url
self
.
_session_id
=
None
self
.
_session_id
=
session_id
# ---------------------------------------------------------------------
def
get_authentication_status
(
self
):
...
...
@@ -37,7 +37,7 @@ class NewtClient():
url
=
'%s/login/'
%
self
.
_base_url
r
=
requests
.
get
(
url
)
return
r
.
json
()
# ---------------------------------------------------------------------
def
login
(
self
,
username
,
password
):
'''Sends login command to server.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment