X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FRO.git;a=blobdiff_plain;f=RO-plugin%2Fosm_ro_plugin%2Fvim_dummy.py;h=e90d213b227b94ed7011532bbcdfc427fbb3c23d;hp=8154304de25fbe1d1be0c4bbd29160bf9604a21d;hb=70eeb18e4fcbb8bc3c81c88f270b59966ae4d463;hpb=7277486065c905f91477bb064da86855a8fa269a diff --git a/RO-plugin/osm_ro_plugin/vim_dummy.py b/RO-plugin/osm_ro_plugin/vim_dummy.py index 8154304d..e90d213b 100644 --- a/RO-plugin/osm_ro_plugin/vim_dummy.py +++ b/RO-plugin/osm_ro_plugin/vim_dummy.py @@ -24,9 +24,11 @@ import yaml from osm_ro_plugin import vimconn from uuid import uuid4 from copy import deepcopy +import logging +from random import randrange __author__ = "Alfonso Tierno" -__date__ = "2020-04-20" +__date__ = "2020-04-20" class VimDummyConnector(vimconn.VimConnector): @@ -39,6 +41,9 @@ class VimDummyConnector(vimconn.VimConnector): config={}, persistent_info={}): super().__init__(uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level, config, persistent_info) + self.logger = logging.getLogger('openmano.vim.dummy') + if log_level: + self.logger.setLevel(getattr(logging, log_level)) self.nets = { "mgmt": { "id": "mgmt", @@ -91,6 +96,8 @@ class VimDummyConnector(vimconn.VimConnector): def new_network(self, net_name, net_type, ip_profile=None, shared=False, provider_network_profile=None): net_id = str(uuid4()) + self.logger.debug("new network id={}, name={}, net_type={}, ip_profile={}, provider_network_profile={}". + format(net_id, net_name, net_type, ip_profile, provider_network_profile)) net = { "id": net_id, "name": net_name, @@ -120,8 +127,9 @@ class VimDummyConnector(vimconn.VimConnector): def delete_network(self, net_id, created_items=None): if net_id not in self.nets: raise vimconn.VimConnNotFoundException("network with id {} not found".format(net_id)) - return net_id + self.logger.debug("delete network id={}, created_items={}".format(net_id, created_items)) self.nets.pop(net_id) + return net_id def refresh_nets_status(self, net_list): nets = {} @@ -131,7 +139,7 @@ class VimDummyConnector(vimconn.VimConnector): else: net = self.nets[net_id].copy() net["vim_info"] = yaml.dump({"status": "ACTIVE", "name": net["name"]}, - default_flow_style=True, width=256) + default_flow_style=True, width=256) nets[net_id] = net return nets @@ -143,6 +151,7 @@ class VimDummyConnector(vimconn.VimConnector): def new_flavor(self, flavor_data): flavor_id = str(uuid4()) + self.logger.debug("new flavor id={}, flavor_data={}".format(flavor_id, flavor_data)) flavor = deepcopy(flavor_data) flavor["id"] = flavor_id if "name" not in flavor: @@ -153,8 +162,9 @@ class VimDummyConnector(vimconn.VimConnector): def delete_flavor(self, flavor_id): if flavor_id not in self.flavors: raise vimconn.VimConnNotFoundException("flavor with id {} not found".format(flavor_id)) - return flavor_id + self.logger.debug("delete flavor id={}".format(flavor_id)) self.flavors.pop(flavor_id) + return flavor_id def get_flavor_id_from_data(self, flavor_dict): for flavor_id, flavor_data in self.flavors.items(): @@ -169,6 +179,7 @@ class VimDummyConnector(vimconn.VimConnector): def new_tenant(self, tenant_name, tenant_description): tenant_id = str(uuid4()) + self.logger.debug("new tenant id={}, description={}".format(tenant_id, tenant_description)) tenant = {'name': tenant_name, 'description': tenant_description, 'id': tenant_id} self.tenants[tenant_id] = tenant return tenant_id @@ -176,8 +187,9 @@ class VimDummyConnector(vimconn.VimConnector): def delete_tenant(self, tenant_id): if tenant_id not in self.tenants: raise vimconn.VimConnNotFoundException("tenant with id {} not found".format(tenant_id)) - return tenant_id self.tenants.pop(tenant_id) + self.logger.debug("delete tenant id={}".format(tenant_id)) + return tenant_id def get_tenant_list(self, filter_dict=None): tenants = [] @@ -193,6 +205,7 @@ class VimDummyConnector(vimconn.VimConnector): def new_image(self, image_dict): image_id = str(uuid4()) + self.logger.debug("new image id={}, iamge_dict={}".format(image_id, image_dict)) image = deepcopy(image_dict) image["id"] = image_id if "name" not in image: @@ -203,8 +216,9 @@ class VimDummyConnector(vimconn.VimConnector): def delete_image(self, image_id): if image_id not in self.images: raise vimconn.VimConnNotFoundException("image with id {} not found".format(image_id)) - return image_id + self.logger.debug("delete image id={}".format(image_id)) self.images.pop(image_id) + return image_id def get_image_list(self, filter_dict=None): images = [] @@ -222,16 +236,25 @@ class VimDummyConnector(vimconn.VimConnector): return images def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None, - availability_zone_index=None, availability_zone_list=None): + availability_zone_index=None, availability_zone_list=None): vm_id = str(uuid4()) interfaces = [] + self.logger.debug("new vm id={}, name={}, image_id={}, flavor_id={}, net_list={}, cloud_config={}". + format(vm_id, name, image_id, flavor_id, net_list, cloud_config)) for iface_index, iface in enumerate(net_list): iface["vim_id"] = str(iface_index) interface = { - "ip_address": self.config.get("vm_ip") or "192.168.4.2", + "ip_address": iface.get("ip_address") or self.config.get("vm_ip") or "192.168.4.2", + "mac_address": iface.get("mac_address") or self.config.get("vm_mac") or "00:11:22:33:44:55", "vim_interface_id": str(iface_index), "vim_net_id": iface["net_id"], } + if iface.get("type") in ("SR-IOV", "PCI-PASSTHROUGH") and self.config.get("sdn-port-mapping"): + compute_index = randrange(len(self.config["sdn-port-mapping"])) + port_index = randrange(len(self.config["sdn-port-mapping"][compute_index]["ports"])) + interface["compute_node"] = self.config["sdn-port-mapping"][compute_index]["compute_node"] + interface["pci"] = self.config["sdn-port-mapping"][compute_index]["ports"][port_index]["pci"] + interfaces.append(interface) vm = { "id": vm_id, @@ -257,8 +280,9 @@ class VimDummyConnector(vimconn.VimConnector): def delete_vminstance(self, vm_id, created_items=None): if vm_id not in self.vms: raise vimconn.VimConnNotFoundException("vm with id {} not found".format(vm_id)) - return vm_id self.vms.pop(vm_id) + self.logger.debug("delete vm id={}, created_items={}".format(vm_id, created_items)) + return vm_id def refresh_vms_status(self, vm_list): vms = {} @@ -268,7 +292,7 @@ class VimDummyConnector(vimconn.VimConnector): else: vm = deepcopy(self.vms[vm_id]) vm["vim_info"] = yaml.dump({"status": "ACTIVE", "name": vm["name"]}, - default_flow_style=True, width=256) + default_flow_style=True, width=256) vms[vm_id] = vm return vms