target_vdu["vdu-name"],
target_vdu.get("count-index") or 0,
)
+ security_group_name = None
if additional_params := target_vdu.get("additionalParams"):
if additional_params.get("OSM", {}).get("instance_name"):
instance_name = additional_params.get("OSM", {}).get("instance_name")
if count_index := target_vdu.get("count-index"):
if count_index >= 1:
instance_name = "{}-{}".format(instance_name, count_index)
+ if additional_params.get("OSM", {}).get("security-group-name"):
+ security_group_name = additional_params.get("OSM", {}).get(
+ "security-group-name"
+ )
+ else:
+ security_group_name = None
extra_dict["params"] = {
"name": instance_name,
"net_list": net_list,
"cloud_config": cloud_config or None,
"disk_list": disk_list,
+ "security_group_name": security_group_name,
"availability_zone_index": None, # TODO
"availability_zone_list": None, # TODO
}
if count_index := existing_vdu.get("count-index"):
if count_index >= 1:
instance_name = "{}-{}".format(instance_name, count_index)
+ if additional_params.get("OSM", {}).get("security-group-name"):
+ security_group_name = additional_params.get("OSM", {}).get(
+ "security-group-name"
+ )
+ else:
+ security_group_name = None
extra_dict["params"] = {
"name": instance_name,
"net_list": net_list,
"cloud_config": cloud_config or None,
"disk_list": disk_list,
+ "security_group_name": security_group_name,
"availability_zone_index": None, # TODO
"availability_zone_list": None, # TODO
}
"availability_zone_index": None,
"availability_zone_list": None,
"cloud_config": None,
+ "security_group_name": None,
"description": "several_volumes-VM",
"disk_list": [],
"flavor_id": f"TASK-{ns_preffix}:flavor.0",
"availability_zone_index": None,
"availability_zone_list": None,
"cloud_config": None,
+ "security_group_name": None,
"description": "without_volumes-VM",
"disk_list": [],
"flavor_id": f"TASK-{ns_preffix}:flavor.0",
]
availability_zone_index = 0
availability_zone_list = ["nova"]
+security_group_name = None
floating_network_vim_id = "108b73-e9cc-5a6a-t270-82cc4811bd4a"
net_id = "83372685-f67f-49fd-8722-eabb7692fc22"
net2_id = "46472685-f67f-49fd-8722-eabb7692fc22"
"name": "management",
"admin_state_up": True,
}
+ security_group_name = None
new_port_result, port_result = self.vimconn._create_port(
net, name, created_items
self.assertDictEqual(new_port_result, new_port)
self.assertDictEqual(port_result, expected_port)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
mock_create_new_port.assert_called_once_with(port_dict, created_items, net)
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
new_port_result, port_result = self.vimconn._create_port(
net, name, created_items
self.assertDictEqual(new_port_result, new_port)
self.assertDictEqual(port_result, expected_port)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
mock_create_new_port.assert_called_once_with(port_dict, created_items, net)
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
new_port_result, port_result = self.vimconn._create_port(
net, name, created_items
self.assertDictEqual(new_port_result, new_port)
self.assertDictEqual(port_result, expected_port)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
mock_create_new_port.assert_called_once_with(port_dict, created_items, net)
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
with self.assertRaises(Exception):
self.vimconn._create_port(net, name, created_items)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
mock_create_new_port.assert_called_once_with(port_dict, created_items, net)
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
with self.assertRaises(Exception):
self.vimconn._create_port(net, name, created_items)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_not_called()
mock_prepare_port_dict_mac_ip_addr.assert_not_called()
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
with self.assertRaises(Exception):
self.vimconn._create_port(net, name, created_items)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
"admin_state_up": True,
"name": name,
}
+ security_group_name = None
with self.assertRaises(Exception):
self.vimconn._create_port(net, name, created_items)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
"fixed_ips": [{"ip_address": ip_addr1}],
},
}
+ security_group_name = None
mock_create_new_port.return_value = new_port
with self.assertRaises(VimConnException):
self.vimconn._create_port(net, name, created_items)
- mock_prepare_port_dict_security_groups.assert_called_once_with(net, port_dict)
+ mock_prepare_port_dict_security_groups.assert_called_once_with(
+ net, port_dict, security_group_name
+ )
mock_prepare_port_dict_binding.assert_called_once_with(net, port_dict)
mock_prepare_port_dict_mac_ip_addr.assert_called_once_with(net, port_dict)
mock_create_new_port.assert_called_once_with(port_dict, created_items, net)
self.assertEqual(external_network, expected_external_network)
self.assertEqual(expected_no_secured_ports, no_secured_ports)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
@patch.object(vimconnector, "_reload_connection")
self.assertEqual(external_network, expected_external_network)
self.assertEqual(expected_no_secured_ports, no_secured_ports)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
@patch.object(vimconnector, "_reload_connection")
no_secured_ports,
)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
self.assertEqual(expected_net_list_vim, net_list_vim)
self.assertEqual(external_network, expected_external_network)
no_secured_ports,
)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
self.assertEqual(expected_net_list_vim, net_list_vim)
self.assertEqual(external_network, expected_external_network)
no_secured_ports,
)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
self.assertEqual(expected_net_list_vim, net_list_vim)
self.assertEqual(external_network, expected_external_network)
self.assertEqual(type(err.exception), KeyError)
+ security_group_name = None
mock_create_port.assert_called_once_with(
{
"net_id": net2_id,
},
name,
created_items,
+ security_group_name,
)
self.assertEqual(expected_net_list_vim, net_list_vim)
self.assertEqual(external_network, expected_external_network)
disk_list2,
availability_zone_index,
availability_zone_list,
+ security_group_name,
)
self.assertEqual(result, expected_result)
net_list_vim=[],
external_network=[],
no_secured_ports=[],
+ security_group_name=security_group_name,
)
mock_create_user_data.assert_called_once_with(cloud_config)
mock_get_vm_availability_zone.assert_called_once_with(
disk_list,
availability_zone_index,
availability_zone_list,
+ security_group_name,
)
mock_reload_connection.assert_called_once()
net_list_vim=[],
external_network=[],
no_secured_ports=[],
+ security_group_name=security_group_name,
)
mock_create_user_data.assert_called_once_with(cloud_config)
mock_get_vm_availability_zone.assert_not_called()
net_list_vim=[],
external_network=[],
no_secured_ports=[],
+ security_group_name=security_group_name,
)
mock_create_user_data.assert_called_once_with(cloud_config)
mock_get_vm_availability_zone.assert_called_once_with(
disk_list2,
availability_zone_index,
availability_zone_list,
+ security_group_name,
)
self.assertEqual(result, expected_result)
net_list_vim=[],
external_network=[],
no_secured_ports=[],
+ security_group_name=security_group_name,
)
mock_create_user_data.assert_called_once_with(cloud_config)
mock_get_vm_availability_zone.assert_called_once_with(
disk_list2,
availability_zone_index,
availability_zone_list,
+ security_group_name,
)
mock_reload_connection.assert_called_once()
net_list_vim=[],
external_network=[],
no_secured_ports=[],
+ security_group_name=security_group_name,
)
mock_create_user_data.assert_called_once_with(cloud_config)
mock_get_vm_availability_zone.assert_called_once_with(
type(exception).__name__ + ": " + message_error
)
- def _get_ids_from_name(self):
+ def _get_ids_from_name(self, security_group_name=None):
"""
Obtain ids from name of tenant and security_groups. Store at self .security_groups_id"
:return: None
)
)
+ neutron_sg_list = self.neutron.list_security_groups(
+ tenant_id=self.my_tenant_id
+ )["security_groups"]
+
if self.config.get("security_groups") and not self.security_groups_id:
# convert from name to id
- neutron_sg_list = self.neutron.list_security_groups(
- tenant_id=self.my_tenant_id
- )["security_groups"]
+ # neutron_sg_list = self.neutron.list_security_groups(
+ # tenant_id=self.my_tenant_id
+ # )["security_groups"]
self.security_groups_id = []
for sg in self.config.get("security_groups"):
"Not found security group {} for this tenant".format(sg)
)
+ if security_group_name is not None:
+ self.security_groups_id = []
+ for neutron_sg in neutron_sg_list:
+ if security_group_name in (neutron_sg["id"], neutron_sg["name"]):
+ self.security_groups_id.append(neutron_sg["id"])
+ break
+ else:
+ self.security_groups_id = None
+ raise vimconn.VimConnConnectionException(
+ "Not found security group {} for this tenant".format(sg)
+ )
+
def _find_nova_server(self, vm_id):
"""
Returns the VM instance from Openstack and completes it with flavor ID
"No enough availability zones at VIM for this deployment"
)
- def _prepare_port_dict_security_groups(self, net: dict, port_dict: dict) -> None:
+ def _prepare_port_dict_security_groups(
+ self, net: dict, port_dict: dict, security_group_name=None
+ ) -> None:
"""Fill up the security_groups in the port_dict.
Args:
port_dict["security_groups"] = self.security_groups_id
+ if security_group_name is not None:
+ self._get_ids_from_name(security_group_name)
+ port_dict["security_groups"] = self.security_groups_id
+
def _prepare_port_dict_binding(self, net: dict, port_dict: dict) -> None:
"""Fill up the network binding depending on network type in the port_dict.
return new_port
def _create_port(
- self, net: dict, name: str, created_items: dict
+ self, net: dict, name: str, created_items: dict, security_group_name=None
) -> Tuple[dict, dict]:
"""Create port using net details.
if not port_dict["name"]:
port_dict["name"] = name
- self._prepare_port_dict_security_groups(net, port_dict)
+ self._prepare_port_dict_security_groups(net, port_dict, security_group_name)
self._prepare_port_dict_binding(net, port_dict)
net_list_vim: list,
external_network: list,
no_secured_ports: list,
+ security_group_name=None,
) -> None:
"""Create port and fill up net dictionary for new VM instance creation.
if not net.get("net_id"):
continue
- new_port, port = self._create_port(net, name, created_items)
+ new_port, port = self._create_port(
+ net, name, created_items, security_group_name
+ )
net_list_vim.append(port)
disk_list=None,
availability_zone_index=None,
availability_zone_list=None,
+ security_group_name=None,
) -> tuple:
"""Adds a VM instance to VIM.
net_list_vim=net_list_vim,
external_network=external_network,
no_secured_ports=no_secured_ports,
+ security_group_name=security_group_name,
)
# Cloud config
--- /dev/null
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# 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.
+#######################################################################################
+---
+prelude: >
+ Replace this text with content to appear at the top of the section for this
+ release. All of the prelude content is merged together and then rendered
+ separately from the items listed in other parts of the file, so the text
+ needs to be worded so that both the prelude and the other items make sense
+ when read independently. This may mean repeating some details. Not every
+ release note requires a prelude. Usually only notes describing major
+ features or adding release theme details should have a prelude.
+features:
+ - |
+ List new features here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+issues:
+ - |
+ List known issues here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+upgrade:
+ - |
+ List upgrade notes here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+deprecations:
+ - |
+ List deprecations notes here, or remove this section. All of the list
+ items in this section are combined when the release notes are rendered, so
+ the text needs to be worded so that it does not depend on any information
+ only available in another section, such as the prelude. This may mean
+ repeating some details.
+critical:
+ - |
+ Add critical notes here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+security:
+ - |
+ Add security notes here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+fixes:
+ - |
+ Add normal bug fixes here, or remove this section. All of the list items
+ in this section are combined when the release notes are rendered, so the
+ text needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.
+other:
+ - |
+ Add other notes here, or remove this section. All of the list items in
+ this section are combined when the release notes are rendered, so the text
+ needs to be worded so that it does not depend on any information only
+ available in another section, such as the prelude. This may mean repeating
+ some details.