def _access_allow(self, share): share_proto = share.share_proto if share_proto not in self.proto_access_type_map.keys(): raise exceptions.InvalidProtocol("Not enabled share protocol %s" % share_proto) try: if self.check_access_allowed(share): return access_type = self.proto_access_type_map[share_proto] access_to = self._get_access_to(access_type) LOG.info( "Allow machine to access share %(shr)s with " "access_type %(type)s and access_to %(to)s", { 'shr': share, 'type': access_type, 'to': access_to }) self.manilaclient.shares.allow(share, access_type, access_to, 'rw') except manila_exception.ClientException as e: LOG.error("Failed to grant access for server, %s", e) raise LOG.info("Waiting share %s access to be active", share) state_monitor.StateMonitor(self.manilaclient, share, 'active', ('new', )).monitor_share_access( access_type, access_to)
def _set_proto_access_type_map(self): conf_proto_at_map = CONF.manila.proto_access_type_map conf_proto_at_map = dict( (k.upper(), v.lower()) for k, v in conf_proto_at_map.items()) unable_proto = [ k for k in conf_proto_at_map.keys() if k not in PROTO_ACCESS_TYPE_MAP.keys() ] if unable_proto: raise exceptions.InvalidProtocol( "Find temporary unable share protocol {0}".format( unable_proto)) self.proto_access_type_map = dict() for key, value in PROTO_ACCESS_TYPE_MAP.items(): if key in conf_proto_at_map: if conf_proto_at_map[key] in value: self.proto_access_type_map[key] = conf_proto_at_map[key] else: raise exceptions.InvalidAccessType( "Access type {0} is not enabled for share " "protocol {1}, please chose from {2}".format( conf_proto_at_map[key], key, PROTO_ACCESS_TYPE_MAP[key])) else: self.proto_access_type_map[key] = value[0]