GitHub user BryanMLima added a comment to the discussion: Instance backups

> In this case I already have one now where everything goes to it, if I add a 
> new secondary storage I can have that one for only the snapshots using the 
> above right?

@pcfriek1987, yes, you'll only need to change the UUID in the heuristic rule.

> Since this will be a bigger storage primarily for snapshots it will have 
> enough space to also hold ISO's and templates until there is a better way to 
> filter it, not sure what you mean with volumes? since i think snapshots 
> includes both normal and volume snapshots right?

Using the KVM as hypervisor, snapshots refers to volume snapshots, which are 
allocated to the secondary storages. In the other hand, VM snapshots are 
allocated in the primary storage in which the VM's root volume is allocated.

When I mentioned directing volumes to a specific secondary storage, I meant 
about the volumes that are uploaded locally or through a URL. For these 
volumes, we can use the heuristic rules.

As for your case specifically, I looked in to creating a pseudo-random 
heuristic rule for allocating the other resources. Below, it is presented a 
heuristic rule that will filter the secondary storage with UUID 
`7cdd9941-5bb5-4717-9afb-8cf803340253` from the available pools. Then, the 
script returns a pseudo-random secondary storage from the pool of secondary 
storages. I used the `Math.random()`[^mdn] function native to JS, which is not 
the best approach, but it is what we have available at the moment. If you only 
have two secondary storages, this function is overkill, as you could just 
create a rule with the UUID of the other secondary storage. However, for an 
environment where there are multiple secondary storages, this rule will try to 
allocate randomly to the other pools.

```js
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

function removeSecondaryStorage(pool) {
  return pool.id != '7cdd9941-5bb5-4717-9afb-8cf803340253';
}

filteredSecondaryStorages = secondaryStorages.filter(removeSecondaryStorage);
randomIndex = getRandomInt(filteredSecondaryStorages.length);
filteredSecondaryStorages[randomIndex].id
```

With the rule above, you can create a selector for the resource types 
`TEMPLATE`, `ISO` and `VOLUME`, and they will filter the secondary storage with 
UUID specified in the function `removeSecondaryStorage`. Using the rule above 
alongside the one mentioned in the previous comment, the desired secondary 
storage will only store volume snapshots.

[^mdn]: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

GitHub link: 
https://github.com/apache/cloudstack/discussions/9347#discussioncomment-10023729

----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscr...@cloudstack.apache.org

Reply via email to