Skip to content

Commit

Permalink
untracked changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminLudwigSAP committed Nov 4, 2024
1 parent 11cad11 commit 65e9e2e
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions octavia_f5/controller/worker/tasks/f5_tasks_rseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2022 SAP SE
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import requests
import tenacity
from netaddr import IPNetwork
from oslo_config import cfg
from oslo_log import log as logging
from taskflow import task

from octavia.network import data_models as network_models
from octavia_f5.common import constants
from octavia_f5.network import data_models as f5_network_models
from octavia_f5.restclient.bigip import bigip_restclient
from octavia_f5.utils import driver_utils, decorators

LOG = logging.getLogger(__name__)
CONF = cfg.CONF


class EnsureVLAN(task.Task):
default_provides = 'device_vlan'

""" Task to create or update VLAN if needed """

@decorators.RaisesIControlRestError()
@tenacity.retry(
retry=tenacity.retry_if_exception_type(requests.HTTPError),
wait=tenacity.wait_fixed(2),
stop=tenacity.stop_after_attempt(3)
)
# TODO Are we really still gonna use bigip_restclient.BigIPRestClient for F5OS-A?
# => Yes, but I have to tweak it to be able to auth to rSeries
#
# bigip is L2SyncManager._vcmps for host and L2SyncManager._bigips for guests,
# each initialized via L2SyncManager.initialize_bigips
def execute(self,
bigip: bigip_restclient.BigIPRestClient,
network: f5_network_models.Network):

vlan_id = network.vlan_id
vlan = {
'vlan-id': vlan_id,
'config': {
'vlan-id': VLAN_ID,
'name': f'vlan-{VLAN_ID}',
}
}

# Only create VLAN if it doesn't exist
device_response = bigip.get(url=f'/data/openconfig-vlan:vlans/vlan={vlan_id}')
# FIXME What's the response code when we GET a non-existing VLAN?
if device_response.status_code == 200:
return vlan # FIXME return what?

res = bigip.put(url=f'/data/openconfig-vlan:vlans/vlan={vlan_id}',
json={'openconfig-vlan:vlan': [vlan]})
res.raise_for_status()
# FIXME is this correct? What does this JSON contain? Make sure it fits self.default_provides
return res.json()

0 comments on commit 65e9e2e

Please sign in to comment.