+ # Volume resources
+ try:
+ vol_lim = self.cinder.limits.get()._info["absolute"]
+ if ("storage" in vimacc_resources) and (
+ (
+ vimacc_resources["storage"]["volumes"]["total"]
+ != vol_lim["maxTotalVolumes"]
+ )
+ or (
+ vimacc_resources["storage"]["snapshots"]["total"]
+ != vol_lim["maxTotalSnapshots"]
+ )
+ or (
+ vimacc_resources["storage"]["volumes"]["used"]
+ != vol_lim["totalVolumesUsed"]
+ )
+ or (
+ vimacc_resources["storage"]["snapshots"]["used"]
+ != vol_lim["totalSnapshotsUsed"]
+ )
+ or (
+ vimacc_resources["storage"]["storage"]["total"]
+ != vol_lim["maxTotalVolumeGigabytes"]
+ )
+ or (
+ vimacc_resources["storage"]["storage"]["used"]
+ != vol_lim["totalGigabytesUsed"]
+ )
+ ):
+ update_dict = {
+ "resources.storage": {
+ "volumes": {
+ "total": vol_lim["maxTotalVolumes"],
+ "used": vol_lim["totalVolumesUsed"],
+ },
+ "snapshots": {
+ "total": vol_lim["maxTotalSnapshots"],
+ "used": vol_lim["totalSnapshotsUsed"],
+ },
+ "storage": {
+ "total": vol_lim["maxTotalVolumeGigabytes"],
+ "used": vol_lim["totalGigabytesUsed"],
+ },
+ }
+ }
+ suc_value = self.common_db.set_vim_account(
+ str(self.vim_account["_id"]), update_dict
+ )
+ log.info("Volume resources update in mongoDB = %s" % suc_value)
+ except Exception as e:
+ log.warning("Error in updating volume resources: %s" % e)
+
+ # Network resources
+ try:
+ net_lim = self.neutron.show_quota_details(self.tenant_id)["quota"]
+ if ("network" in vimacc_resources) and (
+ (
+ vimacc_resources["network"]["networks"]["total"]
+ != net_lim["network"]["limit"]
+ )
+ or (
+ vimacc_resources["network"]["networks"]["used"]
+ != net_lim["network"]["used"]
+ )
+ or (
+ vimacc_resources["network"]["subnets"]["total"]
+ != net_lim["subnet"]["limit"]
+ )
+ or (
+ vimacc_resources["network"]["subnets"]["used"]
+ != net_lim["subnet"]["used"]
+ )
+ or (
+ vimacc_resources["network"]["floating_ips"]["total"]
+ != net_lim["floatingip"]["limit"]
+ )
+ or (
+ vimacc_resources["network"]["floating_ips"]["used"]
+ != net_lim["floatingip"]["used"]
+ )
+ ):
+ update_dict = {
+ "resources.network": {
+ "networks": {
+ "total": net_lim["network"]["limit"],
+ "used": net_lim["network"]["used"],
+ },
+ "subnets": {
+ "total": net_lim["subnet"]["limit"],
+ "used": net_lim["subnet"]["used"],
+ },
+ "floating_ips": {
+ "total": net_lim["floatingip"]["limit"],
+ "used": net_lim["floatingip"]["used"],
+ },
+ }
+ }
+ suc_value = self.common_db.set_vim_account(
+ str(self.vim_account["_id"]), update_dict
+ )
+ log.info("Network resources update in mongoDB = %s" % suc_value)
+ except Exception as e:
+ log.warning("Error in updating network resources: %s" % e)
+
+ def _build_keystone_client(self, vim_account: dict) -> keystone_client.Client:
+ sess = OpenstackUtils.get_session(vim_account)
+ return keystone_client.Client(session=sess, timeout=10)
+
+ def _build_nova_client(self, vim_account: dict) -> nova_client.Client:
+ sess = OpenstackUtils.get_session(vim_account)
+ self.vim_session = sess
+ return nova_client.Client("2", session=sess, timeout=10)
+
+ def _build_cinder_client(self, vim_account: dict) -> cinder_client.Client:
+ # sess = OpenstackUtils.get_session(vim_account)
+ return cinder_client.Client("3", session=self.vim_session, timeout=10)
+
+ def _build_neutron_client(self, vim_account: dict) -> tuple:
+ # sess = OpenstackUtils.get_session(vim_account)
+ tenant_id = self.vim_session.get_project_id()
+ return (
+ neutron_client.Client("2", session=self.vim_session, timeout=10),
+ tenant_id,
+ )