Added support for bulk create ports.
Currently, OpenStackSDK network object doesn't provide a method for bulk create ports. This is a workaround for Kuryr, since we need it for driver NeutronPodVIFDriver. Implements: blueprint switch-to-openstacksdk Change-Id: I4d06f07eb8bd80b4a3042c98fed8acfbc6ccdd4d
This commit is contained in:
@@ -13,10 +13,13 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from kuryr.lib import utils
|
from kuryr.lib import utils
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
|
from openstack import exceptions as os_exc
|
||||||
|
from openstack.network.v2 import port as os_port
|
||||||
|
|
||||||
from kuryr_kubernetes import config
|
from kuryr_kubernetes import config
|
||||||
from kuryr_kubernetes import k8s_client
|
from kuryr_kubernetes import k8s_client
|
||||||
@@ -75,12 +78,24 @@ def setup_kubernetes_client():
|
|||||||
_clients[_KUBERNETES_CLIENT] = k8s_client.K8sClient(api_root)
|
_clients[_KUBERNETES_CLIENT] = k8s_client.K8sClient(api_root)
|
||||||
|
|
||||||
|
|
||||||
|
def _create_ports(self, payload):
|
||||||
|
"""bulk create ports using openstacksdk module"""
|
||||||
|
# TODO(gryf): this should be implemented on openstacksdk instead.
|
||||||
|
response = self.post(os_port.Port.base_path, json=payload)
|
||||||
|
|
||||||
|
if not response.ok:
|
||||||
|
raise os_exc.SDKException('Error when bulk creating ports: %s',
|
||||||
|
response.text)
|
||||||
|
return (os_port.Port(**item) for item in response.json()['ports'])
|
||||||
|
|
||||||
|
|
||||||
def setup_openstacksdk():
|
def setup_openstacksdk():
|
||||||
auth_plugin = utils.get_auth_plugin('neutron')
|
auth_plugin = utils.get_auth_plugin('neutron')
|
||||||
session = utils.get_keystone_session('neutron', auth_plugin)
|
session = utils.get_keystone_session('neutron', auth_plugin)
|
||||||
conn = connection.Connection(
|
conn = connection.Connection(
|
||||||
session=session,
|
session=session,
|
||||||
region_name=getattr(config.CONF.neutron, 'region_name', None))
|
region_name=getattr(config.CONF.neutron, 'region_name', None))
|
||||||
|
conn.network.create_ports = partial(_create_ports, conn.network)
|
||||||
_clients[_OPENSTACKSDK] = conn
|
_clients[_OPENSTACKSDK] = conn
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user