Example #1
0
    def add_nodes(self, hosts, vid=None, layout=None):
        """ Add storaged nodes to the platform

        Args:
            hosts: hosts to be added
            vid: volume to use, if none a new one will be created
            layout: specific layout to use, if none the default layout or
                    the layout of the already defined volume will be used
        """
        enode = self._get_exportd_node()
        econfig = enode.get_configurations(Role.EXPORTD)

        if econfig is None:
            raise Exception("exportd node is off line.")
        
        # Find the default layout
        if layout is None:
            if ((vid is not None) and
                (vid in econfig[Role.EXPORTD].volumes) and
                (econfig[Role.EXPORTD].volumes[vid].layout is not None)):
                default_layout = econfig[Role.EXPORTD].volumes[vid].layout
            else:
                default_layout = econfig[Role.EXPORTD].layout
        else:
            default_layout = layout
        
        # Checks coherence between layout and size of cluster to add
        if len(hosts) < LAYOUT_VALUES[default_layout][LAYOUT_SAFE]:
            raise Exception('too few hosts: only %s hosts are specified '
                            '(%s are needed for the layout %s)' % (len(hosts),
                    LAYOUT_VALUES[default_layout][LAYOUT_SAFE], default_layout))

        # Checks coherence between layout and vid
        if vid is not None:
            # check if the given one is a new one 
            # else get the related VolumeConfig
            if vid in econfig[Role.EXPORTD].volumes:
                
                authorized_layout = econfig[Role.EXPORTD].layout
                if (econfig[Role.EXPORTD].volumes[vid].layout is not None):
                    authorized_layout = \
                        econfig[Role.EXPORTD].volumes[vid].layout

                if(authorized_layout != default_layout):
                    raise Exception('only the layout %s can be used for the '
                                    'volume %s' % ( authorized_layout, vid))
                vconfig = econfig[Role.EXPORTD].volumes[vid]
            else:
                if(layout == econfig[Role.EXPORTD].layout):
                    # avoid to set a specific layout if it's not necessary
                    vconfig = VolumeConfig(vid, None)
                else:
                    vconfig = VolumeConfig(vid, layout)
        else:
            vids = econfig[Role.EXPORTD].volumes.keys()
            if len(vids) != 0 :
                vid = max(vids) + 1
            else:
                vid = 1
            if(layout == econfig[Role.EXPORTD].layout):
                # avoid to set a specific layout if it's not necessary
                vconfig = VolumeConfig(vid, None)
            else:
                vconfig = VolumeConfig(vid, layout)

        # find a cluster id
        cids = [c.cid for v in econfig[Role.EXPORTD].volumes.values()
                      for c in v.clusters.values()]
        if len(cids) != 0:
            cid = max(cids) + 1
        else:
            cid = 1

        # as we create a new cluster sids always starts at 1
        sid = 1

        cconfig = ClusterConfig(cid)
        roles = Role.STORAGED

        for h in hosts:
            # if it's a new node register it
            # else just update its role
            if h not in self._nodes:
                self._nodes[h] = Node(h, roles)
            else:
                # maybe overkill since the node could already have this role
                self._nodes[h].set_roles(self._nodes[h].get_roles() | roles)

            # configure the storaged
            sconfig = self._nodes[h].get_configurations(Role.STORAGED)
            sconfig[Role.STORAGED].storages[(cid, sid)] = StorageConfig(cid,
                 sid, "%s/storage_%d_%d" % (STORAGES_ROOT, cid, sid))
            self._nodes[h].set_configurations(sconfig)

            # add the storage to the cluster
            cconfig.storages[sid] = h
            sid += 1

        # add the cluster to the volume
        vconfig.clusters[cid] = cconfig
        # update the exportd config
        econfig[Role.EXPORTD].volumes[vid] = vconfig
        enode.set_configurations(econfig)
Example #2
0
    def add_nodes(self, hosts, vid=None):
        """ Add storaged nodes to the platform

        Args:
            vid: volume to use, if none a new one will be created
            hosts: hosts to be added
        """
        enode = self._get_exportd_node()
        econfig = enode.get_configurations(Role.EXPORTD)

        if econfig is None:
            raise Exception("Exportd node is off line.")

        if len(hosts) < LAYOUT_VALUES[econfig[Role.EXPORTD].layout][LAYOUT_SAFE]:
            raise Exception("too few hosts: %s over %s" % (len(hosts),
                    LAYOUT_VALUES[econfig[Role.EXPORTD].layout][LAYOUT_SAFE]))

        if vid is not None:
            # check if the given one is a new one else get the related VolumeConfig
            if vid in econfig[Role.EXPORTD].volumes:
                vconfig = econfig[Role.EXPORTD].volumes[vid]
            else:
                vconfig = VolumeConfig(vid)
        else:
            vids = econfig[Role.EXPORTD].volumes.keys()
            if len(vids) != 0 :
                vid = max(vids) + 1
            else:
                vid = 1
            vconfig = VolumeConfig(vid)

        # find a cluster id
        cids = [c.cid for v in econfig[Role.EXPORTD].volumes.values()
                      for c in v.clusters.values()]
        if len(cids) != 0:
            cid = max(cids) + 1
        else:
            cid = 1

        # as we create a new cluster sids always starts at 1
        sid = 1

        cconfig = ClusterConfig(cid)
        roles = Role.STORAGED

        for h in hosts:
            # if it's a new node register it (and duplicate platform config)
            # else just update its role
            if h not in self._nodes:
                self._nodes[h] = Node(h, roles)
            else:
                # maybe overkill since the node could already have this role
                self._nodes[h].set_roles(self._nodes[h].get_roles() | roles)

            # configure the storaged
            sconfig = self._nodes[h].get_configurations(Role.STORAGED)
            # XXX root could (should ?) be compute on storaged module
            sconfig[Role.STORAGED].storages[(cid, sid)] = StorageConfig(cid,
                 sid, "%s/storage_%d_%d" % (STORAGES_ROOT, cid, sid))
            self._nodes[h].set_configurations(sconfig)

            # add the storage to the cluster
            cconfig.storages[sid] = h
            sid += 1

        # add the cluster to the volume
        vconfig.clusters[cid] = cconfig
        # update the exportd config
        econfig[Role.EXPORTD].volumes[vid] = vconfig
        enode.set_configurations(econfig)
Example #3
0
    def add_nodes(self, hosts, vid=None, layout=None, dev_t=1, dev_m=1, dev_r=1):
        """ Add storaged nodes to the platform

        Args:
            hosts: hosts to be added
            vid: volume to use, if none a new one will be created
            layout: specific layout to use, if none the default layout or
                    the layout of the already defined volume will be used
            dev_t: total number of devices
            dev_m: number of devices used for file to device mapping
            dev_r: number of copies of each file to device mapping file
        """
        enode = self._get_exportd_node()
        econfig = enode.get_configurations(Role.EXPORTD)

        if econfig is None:
            raise Exception("exportd node is off line.")
        
        # Find the default layout
        if layout is None:
            if ((vid is not None) and
                (vid in econfig[Role.EXPORTD].volumes) and
                (econfig[Role.EXPORTD].volumes[vid].layout is not None)):
                default_layout = econfig[Role.EXPORTD].volumes[vid].layout
            else:
                default_layout = econfig[Role.EXPORTD].layout
        else:
            default_layout = layout
        
        # Checks coherence between layout and size of cluster to add
        if len(hosts) < LAYOUT_VALUES[default_layout][LAYOUT_SAFE]:
            raise Exception('too few hosts: only %s hosts are specified '
                            '(%s are needed for the layout %s)' % (len(hosts),
                    LAYOUT_VALUES[default_layout][LAYOUT_SAFE], default_layout))

        # Checks coherence between layout and vid
        if vid is not None:
            # check if the given one is a new one 
            # else get the related VolumeConfig
            if vid in econfig[Role.EXPORTD].volumes:
                
                authorized_layout = econfig[Role.EXPORTD].layout
                if (econfig[Role.EXPORTD].volumes[vid].layout is not None):
                    authorized_layout = \
                        econfig[Role.EXPORTD].volumes[vid].layout

                if(authorized_layout != default_layout):
                    raise Exception('only the layout %s can be used for the '
                                    'volume %s' % ( authorized_layout, vid))
                vconfig = econfig[Role.EXPORTD].volumes[vid]
            else:
                if(layout == econfig[Role.EXPORTD].layout):
                    # avoid to set a specific layout if it's not necessary
                    vconfig = VolumeConfig(vid, None)
                else:
                    vconfig = VolumeConfig(vid, layout)
        else:
            vids = econfig[Role.EXPORTD].volumes.keys()
            if len(vids) != 0 :
                vid = max(vids) + 1
            else:
                vid = 1
            if(layout == econfig[Role.EXPORTD].layout):
                # avoid to set a specific layout if it's not necessary
                vconfig = VolumeConfig(vid, None)
            else:
                vconfig = VolumeConfig(vid, layout)

        # Check devices args
        if (dev_t < 1) or (dev_m < 1) or (dev_r < 1):
            raise Exception('device number(s) must be greater than 0')
        if (dev_t > 64) or (dev_m > 64) or (dev_r > 64):
            raise Exception('device number(s) must be lower or equal than 64')
        if (dev_t < dev_m):
            raise Exception('device-mapper must be lower than or equal to device-total')
        if (dev_r > dev_m):
            raise Exception('device-redundancy must be lower than or equal to device-mapper')

        # find a cluster id
        cids = [c.cid for v in econfig[Role.EXPORTD].volumes.values()
                      for c in v.clusters.values()]
        if len(cids) != 0:
            cid = max(cids) + 1
        else:
            cid = 1

        # as we create a new cluster sids always starts at 1
        sid = 1

        cconfig = ClusterConfig(cid)
        roles = Role.STORAGED

        for h in hosts:
            # if it's a new node register it
            # else just update its role
            if h not in self._nodes:
                self._nodes[h] = Node(h, roles)
            else:
                # maybe overkill since the node could already have this role
                self._nodes[h].set_roles(self._nodes[h].get_roles() | roles)

            # configure the storaged
            sconfig = self._nodes[h].get_configurations(Role.STORAGED)

            # Check if a storage is already configured for this node
            # If no storage configured crc32 activation is forced
            if len(sconfig[Role.STORAGED].storages) == 0:
                if sconfig[Role.STORAGED].crc32c_check is None:
                    sconfig[Role.STORAGED].crc32c_check = True
                if sconfig[Role.STORAGED].crc32c_generate is None:
                    sconfig[Role.STORAGED].crc32c_generate = True
                if sconfig[Role.STORAGED].crc32c_hw_forced is None:
                    sconfig[Role.STORAGED].crc32c_hw_forced = True

            sconfig[Role.STORAGED].storages[(cid, sid)] = StorageConfig(cid,
                                                                        sid,
                                                                        "%s/storage_%d_%d" % (STORAGES_ROOT, cid, sid),
                                                                        dev_t,
                                                                        dev_m,
                                                                        dev_r)
            self._nodes[h].set_configurations(sconfig)

            # add the storage to the cluster
            cconfig.storages[sid] = h
            sid += 1

        # add the cluster to the volume
        vconfig.clusters[cid] = cconfig
        # update the exportd config
        econfig[Role.EXPORTD].volumes[vid] = vconfig
        enode.set_configurations(econfig)
Example #4
0
    def add_nodes(self, hosts, vid=None):
        """ Add storaged nodes to the platform

        Args:
            vid: volume to use, if none a new one will be created
            hosts: hosts to be added
        """
        enode = self._get_exportd_node()
        econfig = enode.get_configurations(Role.EXPORTD)

        if econfig is None:
            raise Exception("Exportd node is off line.")

        if len(hosts) < LAYOUT_VALUES[econfig[
                Role.EXPORTD].layout][LAYOUT_SAFE]:
            raise Exception(
                "too few hosts: %s over %s" %
                (len(hosts),
                 LAYOUT_VALUES[econfig[Role.EXPORTD].layout][LAYOUT_SAFE]))

        if vid is not None:
            # check if the given one is a new one else get the related VolumeConfig
            if vid in econfig[Role.EXPORTD].volumes:
                vconfig = econfig[Role.EXPORTD].volumes[vid]
            else:
                vconfig = VolumeConfig(vid)
        else:
            vids = econfig[Role.EXPORTD].volumes.keys()
            if len(vids) != 0:
                vid = max(vids) + 1
            else:
                vid = 1
            vconfig = VolumeConfig(vid)

        # find a cluster id
        cids = [
            c.cid for v in econfig[Role.EXPORTD].volumes.values()
            for c in v.clusters.values()
        ]
        if len(cids) != 0:
            cid = max(cids) + 1
        else:
            cid = 1

        # as we create a new cluster sids always starts at 1
        sid = 1

        cconfig = ClusterConfig(cid)
        roles = Role.STORAGED

        for h in hosts:
            # if it's a new node register it (and duplicate platform config)
            # else just update its role
            if h not in self._nodes:
                self._nodes[h] = Node(h, roles)
            else:
                # maybe overkill since the node could already have this role
                self._nodes[h].set_roles(self._nodes[h].get_roles() | roles)

            # configure the storaged
            sconfig = self._nodes[h].get_configurations(Role.STORAGED)
            # XXX root could (should ?) be compute on storaged module
            sconfig[Role.STORAGED].storages[(cid, sid)] = StorageConfig(
                cid, sid, "%s/storage_%d_%d" % (STORAGES_ROOT, cid, sid))
            self._nodes[h].set_configurations(sconfig)

            # add the storage to the cluster
            cconfig.storages[sid] = h
            sid += 1

        # add the cluster to the volume
        vconfig.clusters[cid] = cconfig
        # update the exportd config
        econfig[Role.EXPORTD].volumes[vid] = vconfig
        enode.set_configurations(econfig)