Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
TFS
controller
Commits
5a15c97e
Commit
5a15c97e
authored
5 months ago
by
Shayan Hajipour
Browse files
Options
Downloads
Patches
Plain Diff
debug:
- app_flow_name retrieval from config rule fixed
parent
91b779d7
No related branches found
No related tags found
2 merge requests
!359
Release TeraFlowSDN 5.0
,
!304
Resolve "(CTTC) Driver required to interact with NCE controller"
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/device/service/drivers/nce/driver.py
+2
-7
2 additions, 7 deletions
src/device/service/drivers/nce/driver.py
src/device/service/drivers/nce/nce_fan_client.py
+12
-4
12 additions, 4 deletions
src/device/service/drivers/nce/nce_fan_client.py
with
14 additions
and
11 deletions
src/device/service/drivers/nce/driver.py
+
2
−
7
View file @
5a15c97e
...
@@ -128,20 +128,14 @@ class NCEDriver(_Driver):
...
@@ -128,20 +128,14 @@ class NCEDriver(_Driver):
return
results
return
results
def
Connect
(
self
)
->
bool
:
def
Connect
(
self
)
->
bool
:
url
=
(
self
.
__tfs_nbi_root
+
"
/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services
"
)
with
self
.
__lock
:
with
self
.
__lock
:
if
self
.
__started
.
is_set
():
if
self
.
__started
.
is_set
():
return
True
return
True
try
:
try
:
# requests.get(url, timeout=self.__timeout)
...
...
except
requests
.
exceptions
.
Timeout
:
except
requests
.
exceptions
.
Timeout
:
LOGGER
.
exception
(
"
Timeout connecting {:s}
"
.
format
(
url
))
return
False
return
False
except
Exception
:
# pylint: disable=broad-except
except
Exception
:
# pylint: disable=broad-except
LOGGER
.
exception
(
"
Exception connecting {:s}
"
.
format
(
url
))
return
False
return
False
else
:
else
:
self
.
__started
.
set
()
self
.
__started
.
set
()
...
@@ -206,6 +200,7 @@ class NCEDriver(_Driver):
...
@@ -206,6 +200,7 @@ class NCEDriver(_Driver):
with
self
.
__lock
:
with
self
.
__lock
:
for
resource
in
resources
:
for
resource
in
resources
:
resource_key
,
resource_value
=
resource
resource_key
,
resource_value
=
resource
LOGGER
.
debug
(
"
resource = {:s}
"
.
format
(
str
(
resource
)))
if
RE_NCE_APP_FLOW_OPERATION
.
match
(
resource_key
):
if
RE_NCE_APP_FLOW_OPERATION
.
match
(
resource_key
):
operation_type
=
json
.
loads
(
resource_value
)[
"
type
"
]
operation_type
=
json
.
loads
(
resource_value
)[
"
type
"
]
results
.
append
((
resource_key
,
True
))
results
.
append
((
resource_key
,
True
))
...
@@ -224,7 +219,7 @@ class NCEDriver(_Driver):
...
@@ -224,7 +219,7 @@ class NCEDriver(_Driver):
elif
operation_type
==
"
delete
"
:
elif
operation_type
==
"
delete
"
:
app_flow_name
=
resource_value
[
"
huawei-nce-app-flow:app-flows
"
][
app_flow_name
=
resource_value
[
"
huawei-nce-app-flow:app-flows
"
][
"
app-flow
"
"
app-flow
"
][
0
][
"
name
"
]
][
0
][
"
app-
name
"
]
self
.
nce
.
delete_app_flow
(
app_flow_name
)
self
.
nce
.
delete_app_flow
(
app_flow_name
)
LOGGER
.
debug
(
f
"
app_flow_datamodel
{
resource_value
}
"
)
LOGGER
.
debug
(
f
"
app_flow_datamodel
{
resource_value
}
"
)
results
.
append
((
resource_key
,
True
))
results
.
append
((
resource_key
,
True
))
...
...
This diff is collapsed.
Click to expand it.
src/device/service/drivers/nce/nce_fan_client.py
+
12
−
4
View file @
5a15c97e
...
@@ -12,11 +12,14 @@
...
@@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
logging
from
typing
import
Optional
from
typing
import
Optional
import
requests
import
requests
from
requests.auth
import
HTTPBasicAuth
from
requests.auth
import
HTTPBasicAuth
LOGGER
=
logging
.
getLogger
(
__name__
)
NCE_FAN_URL
=
"
{:s}://{:s}:{:d}/restconf/v1/data
"
NCE_FAN_URL
=
"
{:s}://{:s}:{:d}/restconf/v1/data
"
TIMEOUT
=
30
TIMEOUT
=
30
...
@@ -48,6 +51,7 @@ MAPPING_DRIVER = {
...
@@ -48,6 +51,7 @@ MAPPING_DRIVER = {
"
DEVICEDRIVER_OC
"
:
11
,
"
DEVICEDRIVER_OC
"
:
11
,
}
}
HEADERS
=
{
'
Content-Type
'
:
'
application/json
'
}
class
NCEClient
:
class
NCEClient
:
def
__init__
(
def
__init__
(
...
@@ -65,20 +69,24 @@ class NCEClient:
...
@@ -65,20 +69,24 @@ class NCEClient:
try
:
try
:
app_data
=
app_flow_data
[
"
huawei-nce-app-flow:app-flows
"
][
"
applications
"
]
app_data
=
app_flow_data
[
"
huawei-nce-app-flow:app-flows
"
][
"
applications
"
]
app_url
=
self
.
_nce_fan_url
+
"
/app-flows/apps
"
app_url
=
self
.
_nce_fan_url
+
"
/app-flows/apps
"
requests
.
post
(
app_url
,
json
=
app_data
)
LOGGER
.
info
(
f
'
Creating app:
{
app_data
}
URL:
{
app_url
}
'
)
# requests.post(app_url, json=app_data, headers=HEADERS)
app_flow_data
=
{
app_flow_data
=
{
"
app-flow
"
:
app_flow_data
[
"
huawei-nce-app-flow:app-flows
"
][
"
app-flow
"
]
"
app-flow
"
:
app_flow_data
[
"
huawei-nce-app-flow:app-flows
"
][
"
app-flow
"
]
}
}
app_flow_url
=
self
.
_nce_fan_url
+
"
/app-flows
"
app_flow_url
=
self
.
_nce_fan_url
+
"
/app-flows
"
requests
.
post
(
app_flow_url
,
json
=
app_flow_data
)
LOGGER
.
info
(
f
'
Creating app flow:
{
app_flow_data
}
URL:
{
app_flow_url
}
'
)
# requests.post(app_flow_url, json=app_flow_data, headers=HEADERS)
except
requests
.
exceptions
.
ConnectionError
:
except
requests
.
exceptions
.
ConnectionError
:
raise
Exception
(
"
faild to send post requests to NCE FAN
"
)
raise
Exception
(
"
faild to send post requests to NCE FAN
"
)
def
delete_app_flow
(
self
,
app_flow_name
:
str
)
->
None
:
def
delete_app_flow
(
self
,
app_flow_name
:
str
)
->
None
:
try
:
try
:
app_url
=
self
.
_nce_fan_url
+
f
"
/app-flows/apps/application=
{
app_flow_name
}
"
app_url
=
self
.
_nce_fan_url
+
f
"
/app-flows/apps/application=
{
app_flow_name
}
"
requests
.
delete
(
app_url
)
LOGGER
.
info
(
f
'
Deleting app:
{
app_flow_name
}
URL:
{
app_url
}
'
)
# requests.delete(app_url)
app_flow_url
=
self
.
_nce_fan_url
+
f
"
/app-flows/app-flow=
{
app_flow_name
}
"
app_flow_url
=
self
.
_nce_fan_url
+
f
"
/app-flows/app-flow=
{
app_flow_name
}
"
requests
.
delete
(
app_flow_url
)
LOGGER
.
info
(
f
'
Deleting app flow:
{
app_flow_name
}
URL:
{
app_flow_url
}
'
)
# requests.delete(app_flow_url)
except
requests
.
exceptions
.
ConnectionError
:
except
requests
.
exceptions
.
ConnectionError
:
raise
Exception
(
"
faild to send delete request to NCE FAN
"
)
raise
Exception
(
"
faild to send delete request to NCE FAN
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment