self.id = id
+class Server:
+ def __init__(self, name="", status="", flavor="", id=""):
+ self.id = id
+ self.name = name
+ self.status = status
+ self.flavor = flavor
+
+
class CopyingMock(MagicMock):
def __call__(self, *args, **kwargs):
args = deepcopy(args)
@patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock())
def test_get_monitoring_data(self, mock_reload_conection):
- servers = ["server1", "server2"]
+ flavors = [
+ {"original_name": "flavor1", "id": "367fc1eb-bd22-40f8-a519-ed2fb4e5976b"},
+ {"original_name": "flavor2", "id": "5dcf9732-d17d-40b3-910d-37fc4c5aacc0"},
+ ]
+ servers = [
+ Server(
+ "server1", "ACTIVE", flavors[0], "312200db-42e3-4772-9518-d5db85468392"
+ ),
+ Server(
+ "server2", "ACTIVE", flavors[1], "39a166cf-e4e6-479c-b88c-9ad558cf2cbf"
+ ),
+ ]
ports = {"ports": ["port1", "port2"]}
self.vimconn.nova.servers.list.return_value = servers
self.vimconn.neutron.list_ports.return_value = ports
version = self.config.get("microversion")
if not version:
- version = "2.1"
+ version = "2.60"
# addedd region_name to keystone, nova, neutron and cinder to support distributed cloud for Wind River
# Titanium cloud and StarlingX
"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
+ Do not call nova.servers.find directly, as it does not return flavor ID with microversion>=2.47
+ """
+ try:
+ self._reload_connection()
+ server = self.nova.servers.find(id=vm_id)
+ # TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema)
+ server_dict = server.to_dict()
+ try:
+ server_dict["flavor"]["id"] = self.nova.flavors.find(
+ name=server_dict["flavor"]["original_name"]
+ ).id
+ except nClient.exceptions.NotFound as e:
+ self.logger.warning(str(e.message))
+ return server_dict
+ except (
+ ksExceptions.ClientException,
+ nvExceptions.ClientException,
+ nvExceptions.NotFound,
+ ConnectionError,
+ ) as e:
+ self._format_exception(e)
+
def check_vim_connectivity(self):
# just get network list to check connectivity and credentials
self.get_network_list(filter_dict={})
def get_vminstance(self, vm_id):
"""Returns the VM instance information from VIM"""
- # self.logger.debug("Getting VM from VIM")
- try:
- self._reload_connection()
- server = self.nova.servers.find(id=vm_id)
- # TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema)
-
- return server.to_dict()
- except (
- ksExceptions.ClientException,
- nvExceptions.ClientException,
- nvExceptions.NotFound,
- ConnectionError,
- ) as e:
- self._format_exception(e)
+ return self._find_nova_server(vm_id)
def get_vminstance_console(self, vm_id, console_type="vnc"):
"""
self.logger.debug("Getting the status of VM")
self.logger.debug("VIM VM ID %s", vm_id)
self._reload_connection()
- server = self.nova.servers.find(id=vm_id)
- server_dict = server.to_dict()
+ server_dict = self._find_nova_server(vm_id)
vdu_data = [
server_dict["status"],
server_dict["flavor"]["id"],
self.logger.debug("Getting servers and ports data from Openstack VIMs.")
self._reload_connection()
all_servers = self.nova.servers.list(detailed=True)
+ try:
+ for server in all_servers:
+ server.flavor["id"] = self.nova.flavors.find(
+ name=server.flavor["original_name"]
+ ).id
+ except nClient.exceptions.NotFound as e:
+ self.logger.warning(str(e.message))
all_ports = self.neutron.list_ports()
return all_servers, all_ports
except (
--- /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.
+#######################################################################################
+---
+other:
+ - |
+ Add support of OpenStack Nova client microversion 2.60, by retrieving the flavor ID and
+ adding it to the VM information.
+