+ # Override descriptor with kwargs
+ if kwargs:
+ desc = self.update_descriptor(desc, kwargs)
+
+ all_tenants = False
+ if item in ("tenant", "vim"):
+ all_tenants = None
+
+ action = None
+ if item == "vims":
+ action = "sdn_mapping"
+ elif item in ("vim_account", "ns"):
+ action = "action"
+
+ # create_desc = self._create_envelop(item, desc)
+ create_desc = desc
+
+ async with aiohttp.ClientSession(loop=self.loop) as session:
+ _all_tenants = all_tenants
+ if item == "vim":
+ _all_tenants = True
+ # item_id = await self._get_item_uuid(session, self.client_to_RO[item], item_id_name,
+ # all_tenants=_all_tenants)
+ outdata = await self._create_item(
+ session,
+ self.client_to_RO[item],
+ create_desc,
+ item_id_name=item_id_name, # item_id_name=item_id
+ action=action,
+ all_tenants=_all_tenants,
+ )
+ return remove_envelop(item, outdata)
+ except (aiohttp.ClientOSError, aiohttp.ClientError) as e:
+ raise ROClientException(e, http_code=504)
+ except asyncio.TimeoutError:
+ raise ROClientException("Timeout", http_code=504)
+
+ async def attach(
+ self, item, item_id_name=None, descriptor=None, descriptor_format=None, **kwargs
+ ):
+ """
+ Attach a datacenter or wim to a tenant, creating a vim_account, wim_account
+ :param item: can be vim_account or wim_account
+ :param item_id_name: id or name of the datacenter, wim
+ :param descriptor:
+ :param descriptor_format:
+ :param kwargs:
+ :return:
+ """
+ try:
+ if isinstance(descriptor, str):
+ descriptor = self._parse(descriptor, descriptor_format)
+ elif descriptor:
+ pass
+ else:
+ descriptor = {}
+
+ desc = remove_envelop(item, descriptor)
+
+ # # check that exist
+ # uuid = self._get_item_uuid(session, "datacenters", uuid_name, all_tenants=True)
+ # tenant_text = "/" + self._get_tenant()
+ if kwargs:
+ desc = self.update_descriptor(desc, kwargs)
+
+ if item == "vim_account":
+ if not desc.get("vim_tenant_name") and not desc.get("vim_tenant_id"):
+ raise ROClientException(
+ "Wrong descriptor. At least vim_tenant_name or vim_tenant_id must be "
+ "provided"
+ )
+ elif item != "wim_account":
+ raise ROClientException(
+ "Attach with unknown item {}. Must be 'vim_account' or 'wim_account'".format(
+ item
+ )
+ )
+ create_desc = self._create_envelop(item, desc)
+ payload_req = yaml.safe_dump(create_desc)
+ async with aiohttp.ClientSession(loop=self.loop) as session:
+ # check that exist
+ item_id = await self._get_item_uuid(
+ session, self.client_to_RO[item], item_id_name, all_tenants=True
+ )
+ await self._get_tenant(session)
+
+ url = "{}/{tenant}/{item}/{item_id}".format(
+ self.uri,
+ tenant=self.tenant,
+ item=self.client_to_RO[item],
+ item_id=item_id,
+ )
+ self.logger.debug("RO POST %s %s", url, payload_req)
+ # timeout = aiohttp.ClientTimeout(total=self.timeout_large)
+ async with session.post(
+ url, headers=self.headers_req, data=payload_req
+ ) as response: