def update_share_stats(self, stats_dict): """Communicate with EMCNASClient to get the stats.""" stats_dict['driver_version'] = VERSION stats_dict['pools'] = [] for pool in self.client.get_pool(): if pool.name in self.pool_set: # the unit of following numbers are GB total_size = float(pool.size_total) used_size = float(pool.size_used) pool_stat = { 'pool_name': pool.name, 'thin_provisioning': True, 'total_capacity_gb': total_size, 'free_capacity_gb': total_size - used_size, 'allocated_capacity_gb': used_size, 'provisioned_capacity_gb': float(pool.size_subscribed), 'qos': False, 'reserved_percentage': self.reserved_percentage, 'max_over_subscription_ratio': self.max_over_subscription_ratio, } stats_dict['pools'].append(pool_stat) if not stats_dict.get('pools'): message = _("Failed to update storage pool.") LOG.error(message) raise exception.EMCUnityError(err=message)
def create_share(self, context, share, share_server=None): """Create a share and export it based on protocol used.""" share_name = share['id'] size = share['size'] * units.Gi # Check share's protocol. # Throw an exception immediately if it is an invalid protocol. share_proto = share['share_proto'].upper() proto_enum = self._get_proto_enum(share_proto) # Get pool name from share host field pool_name = self._get_pool_name_from_host(share['host']) # Get share server name from share server server_name = self._get_server_name(share_server) pool = self.client.get_pool(pool_name) try: nas_server = self.client.get_nas_server(server_name) except storops_ex.UnityResourceNotFoundError: message = (_LE("Failed to get NAS server %(server)s when " "creating the share %(share)s.") % { 'server': server_name, 'share': share_name }) LOG.error(message) raise exception.EMCUnityError(err=message) locations = None if share_proto == 'CIFS': filesystem = self.client.create_filesystem(pool, nas_server, share_name, size, proto=proto_enum) self.client.create_cifs_share(filesystem, share_name) locations = self._get_cifs_location(nas_server.file_interface, share_name) elif share_proto == 'NFS': self.client.create_nfs_filesystem_and_share( pool, nas_server, share_name, size) locations = self._get_nfs_location(nas_server.file_interface, share_name) return locations
def create_share_from_snapshot(self, context, share, snapshot, share_server=None): """Create a share from a snapshot - clone a snapshot.""" share_name = share['id'] # Check share's protocol. # Throw an exception immediately if it is an invalid protocol. share_proto = share['share_proto'].upper() self._validate_share_protocol(share_proto) # Get share server name from share server server_name = self._get_server_name(share_server) try: nas_server = self.client.get_nas_server(server_name) except storops_ex.UnityResourceNotFoundError: message = (_LE("Failed to get NAS server %(server)s when " "creating the share %(share)s.") % { 'server': server_name, 'share': share_name }) LOG.error(message) raise exception.EMCUnityError(err=message) backend_snap = self.client.create_snap_of_snap(snapshot['id'], share_name, snap_type='snapshot') locations = None if share_proto == 'CIFS': self.client.create_cifs_share(backend_snap, share_name) locations = self._get_cifs_location(nas_server.file_interface, share_name) elif share_proto == 'NFS': self.client.create_nfs_share(backend_snap, share_name) locations = self._get_nfs_location(nas_server.file_interface, share_name) return locations