Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Merge requests
!12
Add sites, and add integration of IPtrunks and routers with LSO deployment
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add sites, and add integration of IPtrunks and routers with LSO deployment
feature/new_device_model_and_sites_and_orgs
into
develop
Overview
0
Commits
25
Pipelines
0
Changes
2
Merged
Karel van Klink
requested to merge
feature/new_device_model_and_sites_and_orgs
into
develop
2 years ago
Overview
0
Commits
25
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
804d524b
Prev
Next
Show latest version
2 files
+
68
−
25
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
Verified
804d524b
fix formatting, add documentation
· 804d524b
Karel van Klink
authored
2 years ago
gso/services/provisioning_proxy.py
+
136
−
35
Options
import
json
import
logging
import
requests
from
orchestrator
import
inputstep
from
orchestrator.config.assignee
import
Assignee
# noinspection PyProtectedMember
from
orchestrator.forms
import
FormPage
,
ReadOnlyField
from
orchestrator.forms.validators
import
Accept
,
Label
,
LongText
from
orchestrator.types
import
UUIDstr
,
State
from
orchestrator.types
import
UUIDstr
,
State
,
strEnum
from
orchestrator.utils.json
import
json_dumps
from
gso
import
settings
from
gso.products.product_types.device
import
DeviceProvisioning
from
gso.products.product_types.iptrunk
import
IptrunkProvisioning
,
Iptrunk
logger
=
logging
.
getLogger
(
__name__
)
def
provision_node
(
node_subscription_params
:
DeviceProvisioning
,
process_id
:
UUIDstr
,
dry_run
:
bool
=
True
):
class
CUDOperation
(
strEnum
):
"""
Enum for different C(R)UD operations that the provisioning proxy supports.
Read is not applicable, hence these become CUD and not CRUD operations.
"""
#: Creation is done with a POST request
POST
=
'
POST
'
#: Updating is done with a PUT request
PUT
=
'
PUT
'
#: Removal is done with a DELETE request
DELETE
=
'
DELETE
'
def
_send_request
(
endpoint
:
str
,
parameters
:
dict
,
process_id
:
UUIDstr
,
operation
:
CUDOperation
):
"""
Internal function for sending a request to LSO. The callback address is
derived using the process ID provided.
:param str endpoint: The LSO-specific endpoint to call, depending on the
type of service object that is acted upon.
:param dict parameters: JSON body for the request, which will almost always
at least consist of a subscription object, and a boolean value to
indicate a dry run.
:param UUIDstr process_id: The process ID that this request is a part of,
used to call back to when the execution of the playbook is completed.
:param :class:`CUDOperation` operation: The specific operation that is
performed with the request.
"""
oss
=
settings
.
load_oss_params
()
pp_params
=
oss
.
PROVISIONING_PROXY
assert
pp_params
device_params
=
node_subscription_params
.
device
callback_url
=
f
'
{
settings
.
load_oss_params
().
GENERAL
.
public_hostname
}
'
\
f
'
/api/processes/
{
process_id
}
/resume
'
logger
.
debug
(
f
'
[disabled] provisioning node
{
device_params
}
'
)
logger
.
debug
(
f
'
[provisioning proxy] provisioning for process
{
process_id
}
'
)
parameters
.
update
({
'
callback
'
:
callback_url
})
url
=
f
'
{
pp_params
.
scheme
}
://
{
pp_params
.
api_base
}
/api/
{
endpoint
}
'
request
=
None
if
operation
==
CUDOperation
.
POST
:
request
=
requests
.
post
(
url
,
json
=
parameters
)
elif
operation
==
CUDOperation
.
PUT
:
request
=
requests
.
put
(
url
,
json
=
parameters
)
elif
operation
==
CUDOperation
.
DELETE
:
request
=
requests
.
delete
(
url
,
json
=
parameters
)
if
request
.
status_code
!=
200
:
raise
AssertionError
(
request
.
text
)
def
provision_device
(
subscription
:
DeviceProvisioning
,
process_id
:
UUIDstr
,
dry_run
:
bool
=
True
):
"""
Function that provisions a new device using LSO.
:param :class:`DeviceProvisioning` subscription: The subscription object
that is to be provisioned.
:param UUIDstr process_id: The related process ID, used for callback.
:param bool dry_run: A boolean indicating whether this should be a dry run
or not, defaults to ``True``.
"""
parameters
=
{
'
dry_run
'
:
dry_run
,
'
subscription
'
:
json
.
loads
(
json_dumps
(
subscription
))
}
_send_request
(
'
device
'
,
parameters
,
process_id
,
CUDOperation
.
POST
)
def
provision_ip_trunk
(
subscription
:
IptrunkProvisioning
,
process_id
:
UUIDstr
,
config_object
:
str
,
dry_run
:
bool
=
True
):
"""
Function that provisions an IP trunk service using LSO.
:param :class:`IptrunkProvisioning` subscription: The subscription object
that is to be provisioned.
:param UUIDstr process_id: The related process ID, used for callback.
:param str config_object: The type of object that is deployed
:param bool dry_run: A boolean indicating whether this should be a dry run
or not, defaults to ``True``.
"""
parameters
=
{
'
subscription
'
:
json
.
loads
(
json_dumps
(
subscription
)),
'
dry_run
'
:
dry_run
,
'
verb
'
:
"
deploy
"
,
'
object
'
:
config_object
}
_send_request
(
'
ip_trunk
'
,
parameters
,
process_id
,
CUDOperation
.
POST
)
# def modify_ip_trunk(old_subscription: Iptrunk,
# new_subscription: Iptrunk,
# process_id: UUIDstr,
# dry_run: bool = True):
# """
# Function that modifies an existing IP trunk subscription using LSO.
#
# :param :class:`Iptrunk` old_subscription: The subscription object, before
# its modification.
# :param :class:`Iptrunk` new_subscription: The subscription object, after
# modifications have been made to it.
# :param UUIDstr process_id: The related process ID, used for callback.
# :param bool dry_run: A boolean indicating whether this should be a dry ryn
# or not, defaults to ``True``.
# """
# parameters = {
# 'dry_run': dry_run,
# 'old_subscription': old_subscription,
# 'subscription': new_subscription
# # FIXME missing parameters
# }
#
# _send_request('ip_trunk', parameters, process_id, CUDOperation.PUT)
def
deprovision_ip_trunk
(
subscription
:
Iptrunk
,
process_id
:
UUIDstr
,
dry_run
:
bool
=
True
):
"""
Function that provisions an IP trunk service using LSO.
:param :class:`IptrunkProvisioning` subscription: The subscription object
that is to be provisioned.
:param UUIDstr process_id: The related process ID, used for callback.
:param bool dry_run: A boolean indicating whether this should be a dry run
or not, defaults to ``True``.
"""
parameters
=
{
'
callback
'
:
callback_url
,
'
subscription
'
:
json
.
loads
(
json_dumps
(
subscription
))
,
'
dry_run
'
:
dry_run
,
'
device
'
:
{
'
fqdn
'
:
device_params
.
fqdn
,
'
lo_address
'
:
{
'
v4
'
:
str
(
device_params
.
lo_ipv4_address
),
'
v6
'
:
str
(
device_params
.
lo_ipv6_address
)
},
'
lo_iso_address
'
:
device_params
.
lo_iso_address
,
'
si_ipv4_network
'
:
str
(
device_params
.
si_ipv4_network
),
'
ias_lt_network
'
:
{
'
v4
'
:
str
(
device_params
.
ias_lt_ipv4_network
),
'
v6
'
:
str
(
device_params
.
ias_lt_ipv6_network
)
},
'
site_country_code
'
:
device_params
.
site_country_code
,
'
site_city
'
:
device_params
.
site_city
,
'
site_latitude
'
:
device_params
.
site_latitude
,
'
site_longitude
'
:
device_params
.
site_longitude
,
'
snmp_location
'
:
device_params
.
snmp_location
,
'
device_type
'
:
node_subscription_params
.
device_type
,
'
device_vendor
'
:
node_subscription_params
.
device_vendor
,
'
ts_address
'
:
device_params
.
ts_address
,
'
ts_port
'
:
device_params
.
ts_port
}
'
verb
'
:
"
remove
"
}
post_request
=
requests
.
post
(
f
'
{
pp_params
.
scheme
}
://
{
pp_params
.
api_base
}
'
f
'
/api/device
'
,
json
=
parameters
)
post_request
.
raise_for_status
()
_send_request
(
'
ip_trunk
'
,
parameters
,
process_id
,
CUDOperation
.
DELETE
)
@inputstep
(
'
Await provisioning proxy results
'
,
assignee
=
Assignee
(
'
SYSTEM
'
))
Loading