def ui_setgroup_luns(self, key, value): key = int(key) res = None vol = None try: res = DrbdResource.objects.get(name=value) except DrbdResource.DoesNotExist: vol = Volume(value) if res: self.obj.devices[key] = res elif vol.exists(): self.obj.devices[key] = vol.name else: raise ValueError('Could not find replicated resource or Volume named "%s"' % value)
def ui_command_attach(self, volume=None, resource=None, index=None): assert not volume and resource backstore = None if resource: try: res = DrbdResource.objects.get(name=resource) except DrbdResource.DoesNotExist: raise ValueError('Resource "%s" does not exist.' % resource) backstore, created = DrbdResourceBackstore.objects.get_or_create(resource=res) if created: backstore.name = resource backstore.save() elif volume: vol = Volume(volume) if not vol.exists(): raise ValueError('Volume "%s" does not exist.' % volume) # TODO Make sure this volume isn't being used by a resource backstore, created = VolumeBackstore.objects.get_or_create(volume_name=vol.name) if created: logger.info('Created Backstore "%s".', backstore) backstore.name = vol.basename() backstore.save() else: raise ValueError('You must specify either volume or resource to attach') if index is not None: self.group.luns.insert(index, backstore) else: self.group.luns.append(backstore) self.target.save() return True
def volumes(self, **kwargs): # TODO Fix this, nasty from solarsan.storage.volume import Volume kwargs['pool'] = self.name return Volume.list(**kwargs)