Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
onelab
myslicelib
Commits
6ee356d4
Commit
6ee356d4
authored
May 05, 2022
by
Albert
Browse files
Merge remote-tracking branch 'origin/fitcloudv2'
parents
29004cbd
1fd4d67b
Pipeline
#2999
failed with stage
in 11 seconds
Changes
13
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
myslicelib/api/__init__.py
View file @
6ee356d4
...
...
@@ -6,16 +6,20 @@ import datetime
import
threading
from
queue
import
Queue
from
myslicelib.util
import
Endpoint
,
Authentication
from
myslicelib.api.sfaam
import
SfaAm
from
myslicelib.api.sfareg
import
SfaReg
from
myslicelib.api.sfa.sfaam
import
SfaAm
from
myslicelib.api.sfa.sfareg
import
SfaReg
from
myslicelib.api.fitcloud.fitcloud
import
FitCloud
from
myslicelib.api.cbas.ma
import
MemberAuthority
from
myslicelib.api.cbas.sa
import
SliceAuthority
from
myslicelib.api.cbas.fed
import
FederationAuthority
from
myslicelib.util.config
import
getLogger
logger
=
getLogger
(
__name__
)
# from myslicelib.util.decorators import timeit
#from myslicelib.util.certificate import Keypair, Certificate
from
myslice
import
settings
import
concurrent.futures
from
pprint
import
pprint
from
myslicelib.error
import
MysParamsTypeError
...
...
@@ -47,13 +51,15 @@ class Api(object):
'user'
,
'authority'
,
'lease'
,
'project'
'project'
,
'cloud'
]
_am
=
[
'resource'
,
'slice'
,
'lease'
'lease'
,
'cloud'
]
_registry
=
[
...
...
@@ -131,12 +137,18 @@ class Api(object):
# search for the AMs
for
endpoint
in
endpoints
:
if
(
endpoint
.
protocol
==
"SFA"
)
and
(
endpoint
.
type
==
"AM"
):
if
registry_endpoint
:
self
.
ams
.
append
(
SfaAm
(
endpoint
,
self
.
registry
))
if
sa_endpoint
:
self
.
ams
.
append
(
SfaAm
(
endpoint
,
self
.
sa
))
if
endpoint
.
type
==
"AM"
:
if
endpoint
.
protocol
==
"SFA"
:
if
registry_endpoint
:
self
.
ams
.
append
(
SfaAm
(
endpoint
,
self
.
registry
))
if
sa_endpoint
:
self
.
ams
.
append
(
SfaAm
(
endpoint
,
self
.
sa
))
elif
endpoint
.
protocol
==
"REST"
and
endpoint
.
module
==
"FITCLOUD"
:
if
registry_endpoint
:
self
.
ams
.
append
(
FitCloud
(
endpoint
,
self
.
registry
))
if
sa_endpoint
:
self
.
ams
.
append
(
FitCloud
(
endpoint
,
self
.
sa
))
def
__getattr__
(
self
,
entity
):
def
method_handler
():
...
...
@@ -309,6 +321,45 @@ class Api(object):
return
result
def
renew
(
self
,
id
,
params
):
exists
=
self
.
get
(
id
)
if
not
isinstance
(
params
,
dict
):
raise
MysParamsTypeError
(
'a dict is expected'
)
threads
=
[]
result
=
{}
if
not
exists
:
raise
Exception
(
'This object do not exist'
)
if
self
.
_entity
in
self
.
_am
:
for
am
in
self
.
ams
:
threads
+=
[
self
.
_thread_handler
(
am
.
renew
,
self
.
_entity
,
id
,
params
)]
result
=
self
.
_parallel_request
(
threads
)
if
self
.
_entity
not
in
self
.
_am
:
raise
NotImplementedError
(
'Not implemented'
)
return
result
def
execute
(
self
,
id
,
action
,
params
):
exists
=
self
.
get
(
id
)
if
not
isinstance
(
params
,
dict
):
raise
MysParamsTypeError
(
'a dict is expected'
)
threads
=
[]
result
=
{}
if
not
exists
:
raise
Exception
(
'This object do not exist'
)
if
self
.
_entity
in
self
.
_am
:
for
am
in
self
.
ams
:
threads
+=
[
self
.
_thread_handler
(
am
.
execute
,
id
,
action
,
params
)]
result
=
self
.
_parallel_request
(
threads
)
if
self
.
_entity
not
in
self
.
_am
:
raise
NotImplementedError
(
'Not implemented'
)
return
result
def
merge_dicts
(
res
):
result
=
{}
...
...
myslicelib/api/fitcloud/fitcloud.py
0 → 100644
View file @
6ee356d4
This diff is collapsed.
Click to expand it.
myslicelib/api/model/am.py
0 → 100644
View file @
6ee356d4
class
Api
(
object
):
def
__init__
(
self
,
endpoint
,
authentication
):
#authenticate
pass
# Describe how to get 'object'
def
_object
(
self
,
id
):
pass
# Call _object ()
def
get
(
self
,
entity
,
id
):
pass
def
create
(
self
,
entity
,
id
,
data
):
pass
def
delete
(
self
,
entity
,
id
):
pass
def
update
(
self
,
entity
,
id
,
data
):
pass
myslicelib/api/sfa.py
→
myslicelib/api/sfa
/sfa
.py
View file @
6ee356d4
File moved
myslicelib/api/sfaam.py
→
myslicelib/api/
sfa/
sfaam.py
View file @
6ee356d4
import
traceback
from
pprint
import
pprint
from
myslicelib.util.sfa
import
hrn_to_urn
,
urn_to_hrn
,
unique_call_id
from
myslicelib.util.sfa
import
urn_to_hrn
,
unique_call_id
from
myslicelib.util.builder
import
Builder
from
myslicelib.util.parser
import
Parser
,
get_testbed_type
# from myslicelib.util.decorators import timeit
from
myslicelib.api.sfa
import
Api
as
SfaApi
from
myslicelib.api.sfa
import
SfaError
from
myslicelib.error
import
MysParameterIsRequiredError
from
myslicelib.api.sfa.sfa
import
Api
as
SfaApi
from
myslicelib.api.sfa.sfa
import
SfaError
# self.ListResources
# self.Status => geni_urn + geni_slivers
...
...
@@ -260,7 +257,7 @@ class SfaAm(SfaApi):
})
return
{
'data'
:
result
,
'errors'
:
self
.
logs
}
def
execute
(
self
,
urn
,
action
,
o
bj_type
):
def
execute
(
self
,
urn
,
action
,
o
ptions
=
{}
):
result
=
[]
try
:
if
action
.
lower
()
==
'shutdown'
:
...
...
@@ -288,6 +285,10 @@ class SfaAm(SfaApi):
return
{
'data'
:
result
,
'errors'
:
self
.
logs
}
def
renew
(
self
,
urn
,
data
):
result
=
[]
return
{
'data'
:
result
,
'errors'
:
self
.
logs
}
def
isResultOk
(
self
,
result
):
if
'code'
in
result
and
\
'geni_code'
in
result
[
'code'
]
and
\
...
...
myslicelib/api/sfareg.py
→
myslicelib/api/
sfa/
sfareg.py
View file @
6ee356d4
import
os
,
tempfile
import
pytz
import
traceback
from
sfa.trust.credential
import
Credential
from
sfa.trust.gid
import
GID
from
pprint
import
pprint
from
datetime
import
datetime
import
dateutil.parser
import
xml.etree.ElementTree
from
myslicelib.api.sfa
import
Api
as
SfaApi
from
myslicelib.api.sfa
import
SfaError
from
myslicelib.api.sfa
.sfa
import
Api
as
SfaApi
from
myslicelib.api.sfa
.sfa
import
SfaError
from
myslicelib.util.sfa
import
hrn_to_urn
,
urn_to_hrn
# from myslicelib.util.decorators import timeit
...
...
myslicelib/model/__init__.py
View file @
6ee356d4
...
...
@@ -3,6 +3,9 @@ from myslicelib import setup as s, Setup
from
myslicelib.api
import
Api
from
myslicelib.util.sfa
import
hrn_to_urn
,
urn_to_hrn
,
is_urn
from
myslicelib.util.config
import
getLogger
logger
=
getLogger
(
__name__
)
class
Entity
(
object
):
_type
=
'entity'
...
...
@@ -256,6 +259,26 @@ class Entity(object):
'errors'
:
res
.
get
(
'errors'
,
[]),
}
def
renew
(
self
,
setup
=
None
,
data
=
None
):
if
not
self
.
id
:
raise
Exception
(
"No element specified"
)
res
=
self
.
_api
(
setup
).
renew
(
self
.
id
,
data
)
return
{
'data'
:
res
.
get
(
'data'
,
[]),
'errors'
:
res
.
get
(
'errors'
,
[]),
}
def
execute
(
self
,
setup
=
None
,
action
=
None
,
options
=
None
):
if
not
self
.
id
:
raise
Exception
(
"No element specified"
)
res
=
self
.
_api
(
setup
).
execute
(
self
.
id
,
action
,
options
)
return
{
'data'
:
res
.
get
(
'data'
,
[]),
'errors'
:
res
.
get
(
'errors'
,
[]),
}
def
delete
(
self
,
setup
=
None
):
if
not
self
.
id
:
...
...
myslicelib/model/lease.py
View file @
6ee356d4
...
...
@@ -14,7 +14,9 @@ class Lease(Entity):
super
().
__init__
(
data
)
if
data
is
None
:
data
=
{}
self
.
resources
=
data
.
get
(
'resources'
,
[])
self
.
resources_data
=
data
.
get
(
'resources_data'
,
[])
def
addResource
(
self
,
resource
):
self
.
appendAttribute
(
'resources'
,
resource
.
id
)
...
...
@@ -86,7 +88,13 @@ class Lease(Entity):
if
l1
==
l2
:
return
True
# check if the list of resources is the same, order does not matter
if
set
(
l1
[
'resources'
])
==
set
(
l2
[
'resources'
]):
if
"resources_data"
in
l1
and
"resources_data"
in
l2
and
l1
[
"resources_data"
]
and
l2
[
"resources_data"
]:
l1res
=
[
r
[
"callback_id"
]
for
r
in
l1
[
"resources_data"
]
if
"callback_id"
in
r
]
l2res
=
[
r
[
"callback_id"
]
for
r
in
l2
[
"resources_data"
]
if
"callback_id"
in
r
]
if
set
(
l1res
)
==
set
(
l2res
):
return
True
if
l1
[
"resources"
]
and
l2
[
"resources"
]
and
set
(
l1
[
'resources'
])
==
set
(
l2
[
'resources'
]):
#if set(l1['resources']) == set(l2['resources']):
if
l1
[
'start_time'
]
==
l2
[
'start_time'
]
and
l1
[
'duration'
]
==
l2
[
'duration'
]:
return
True
except
Exception
as
e
:
...
...
myslicelib/model/slice.py
View file @
6ee356d4
...
...
@@ -29,6 +29,8 @@ class Slice(Entity):
if
r
[
'testbed'
]
not
in
data
[
'initial_testbeds'
]:
data
[
'initial_testbeds'
].
append
(
r
[
'testbed'
])
data
[
'leases'
]
=
data
.
get
(
'leases'
,
[])
data
[
'addedLeases'
]
=
[]
data
[
'deletedLeases'
]
=
[]
data
[
'run_am'
]
=
data
.
get
(
'run_am'
,
False
)
super
().
__init__
(
data
)
...
...
@@ -99,8 +101,9 @@ class Slice(Entity):
def
addLease
(
self
,
lease
):
self
.
appendAttribute
(
'leases'
,
lease
.
getAttributes
())
self
.
appendAttribute
(
'addedLeases'
,
lease
.
getAttributes
())
#self.addResources(list(set(lease.getAttribute('resources')) - set(self.getAttribute('resources'))))
if
lease
.
hasAttribute
(
'testbed'
)
and
lease
.
getAttribute
(
'testbed'
)
not
in
self
.
getAttribute
(
'testbeds'
):
if
lease
.
hasAttribute
(
'testbed'
)
and
lease
.
getAttribute
(
'testbed'
)
and
lease
.
getAttribute
(
'testbed'
)
not
in
self
.
getAttribute
(
'testbeds'
):
self
.
appendAttribute
(
'testbeds'
,
lease
.
getAttribute
(
'testbed'
))
self
.
setAttribute
(
'run_am'
,
True
)
return
self
...
...
@@ -114,6 +117,12 @@ class Slice(Entity):
self
.
setAttribute
(
'run_am'
,
True
)
return
self
def
deletedLease
(
self
,
lease
):
if
not
isinstance
(
lease
,
dict
):
lease
=
lease
.
dict
()
self
.
appendAttribute
(
'deletedLeases'
,
lease
.
getAttributes
())
def
save
(
self
,
setup
=
None
):
# check if we have the shortname & authority
...
...
myslicelib/query/cloud.py
0 → 100644
View file @
6ee356d4
import
logging
from
myslicelib
import
setup
as
s
,
Setup
from
myslicelib.api
import
Api
from
pprint
import
pprint
class
CloudQuery
(
object
):
_id
=
None
def
__init__
(
self
,
setup
=
None
)
->
None
:
if
setup
and
isinstance
(
setup
,
Setup
):
self
.
_setup
=
setup
else
:
self
.
_setup
=
s
self
.
api
=
getattr
(
Api
(
self
.
_setup
.
endpoints
,
self
.
_setup
.
authentication
),
"cloud"
)()
def
id
(
self
,
id
):
self
.
_id
=
id
return
self
def
get
(
self
):
# Push filter to the API
res
=
self
.
api
.
get
(
self
.
_id
)
if
"data"
in
res
:
return
res
[
"data"
]
else
:
return
[]
myslicelib/util/__init__.py
View file @
6ee356d4
import
os
from
OpenSSL
import
crypto
,
SSL
import
os.path
import
tempfile
from
OpenSSL
import
crypto
,
SSL
...
...
@@ -19,13 +19,14 @@ class Endpoint(object):
"""
def
__init__
(
self
,
type
=
"AM"
,
protocol
=
"SFA"
,
version
=
None
,
url
=
None
,
name
=
None
,
timeout
=
None
,
technologies
=
None
,
hasLeases
=
False
,
auth_level
=
1
):
def
__init__
(
self
,
type
=
"AM"
,
protocol
=
"SFA"
,
module
=
"SFA"
,
version
=
None
,
url
=
None
,
name
=
None
,
timeout
=
None
,
technologies
=
None
,
hasLeases
=
False
,
auth_level
=
1
):
self
.
name
=
name
self
.
type
=
type
self
.
protocol
=
protocol
self
.
hasLeases
=
hasLeases
self
.
auth_level
=
auth_level
self
.
version
=
version
self
.
module
=
module
if
technologies
:
...
...
@@ -56,6 +57,8 @@ class Authentication(object):
self
.
urn
=
urn
self
.
private_key
=
private_key
self
.
password
=
password
if
not
certificate
:
certificate
=
self
.
create_self_signed_cert
(
private_key
)
if
not
isinstance
(
certificate
,
str
):
...
...
@@ -67,7 +70,7 @@ class Authentication(object):
self
.
credentials
=
credentials
def
__repr__
(
self
):
return
"email: {}, hrn: {}, urn: {}"
.
format
(
self
.
email
,
self
.
hrn
,
self
.
urn
)
return
"email: {}, hrn: {}, urn:
{}, pkey: {}, password:
{}"
.
format
(
self
.
email
,
self
.
hrn
,
self
.
urn
,
self
.
private_key
,
self
.
password
)
def
create_self_signed_cert
(
self
,
private_key
=
None
):
if
not
private_key
:
...
...
myslicelib/util/sfabuilder/iotlab.py
View file @
6ee356d4
import
xml.etree.ElementTree
as
ET
from
myslicelib.api.sfa
import
SfaError
from
myslicelib.api.sfa.sfa
import
SfaError
from
myslicelib.util.sfabuilder
import
SfaBuilder
class
Iotlab
(
SfaBuilder
):
...
...
myslicelib/util/sfabuilder/omf.py
View file @
6ee356d4
import
uuid
import
xml.etree.ElementTree
as
ET
from
datetime
import
datetime
from
pprint
import
pprint
from
myslicelib.api.sfa
import
SfaError
from
myslicelib.api.sfa
.sfa
import
SfaError
from
myslicelib.util.sfabuilder
import
SfaBuilder
NEW_LEASE_TAG
=
'<ol:lease client_id="%(client_id)s" valid_from="%(valid_from_iso)sZ" valid_until="%(valid_until_iso)sZ"/>'
...
...
Write
Preview
Markdown
is supported
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