-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from imjfckm/master
Initial code commit
- Loading branch information
Showing
21 changed files
with
1,726 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.retry | ||
|
||
*.py[cod] | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "tests/open-cas-linux"] | ||
path = tests/open-cas-linux | ||
url = https://github.com/Open-CAS/open-cas-linux.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# opencas-ansible | ||
Collection of Ansible playbooks for setting up Open CAS accelerated devices. | ||
|
||
## Configuration and usage | ||
Default playbook configuration tries to configure Open CAS on `opencas_nodes` | ||
host group from inventory. | ||
|
||
### Configuring devices | ||
Example configuration is shown in `group_vars/opencas_nodes.yml.sample`. | ||
For default, out-of-the-box configuration you can only change the name to opencas_nodes.yml, | ||
configure appropriate host groups and adjust the device names. | ||
|
||
### Configuring IO-classes | ||
Default configuration is already present at `roles/opencas-deploy/files/default.csv`. | ||
Any additional ioclass config files present in this directory will be copied over to | ||
configured hosts and may be used in cache devices configuration in group variables. | ||
|
||
## Playbooks | ||
### opencas-deploy | ||
Installs Open CAS software on `opencas-node` group and configures caching devices | ||
and cached volumes defined. | ||
|
||
### opencas-teardown | ||
Stops all cache instances and removes Open CAS software. Make sure that | ||
`/dev/casx-y` devices aren't used at time of teardown. | ||
|
||
## Roles | ||
### opencas-validate | ||
Validates the Open CAS configuration set (e.g. in `group_vars`). | ||
|
||
### opencas-defaults | ||
Gathers custom facts needed for further processing, also in `defaults/main.yml` | ||
there are some settings used by other roles e.g. version of Open CAS to be installed. | ||
|
||
### opencas-install | ||
Installs Open CAS software. | ||
|
||
### opencas-deploy | ||
Copies over the IO-class configuration files, validates configuration and deploys | ||
it on hosts. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# | ||
# Copyright(c) 2012-2019 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause-Clear | ||
# | ||
|
||
import os | ||
import csv | ||
|
||
from ansible.plugins.action import ActionBase | ||
from ansible.errors import AnsibleError | ||
from ansible.utils.vars import merge_hash | ||
|
||
|
||
def validate_ioclass_file(ioclass_file): | ||
if ioclass_file is None: | ||
return | ||
|
||
file_path = "roles/opencas-deploy/files/{0}".format(ioclass_file) | ||
if not os.path.exists(file_path): | ||
raise AnsibleError( | ||
"{0} io class file wasn't found in opencas-deploy files".format( | ||
ioclass_file | ||
) | ||
) | ||
|
||
with open(file_path, "r") as f: | ||
reader = csv.DictReader(f, restkey="unnamed fields") | ||
|
||
required = set( | ||
["IO class id", "IO class name", "Eviction priority", "Allocation"] | ||
) | ||
if set(reader.fieldnames) != required: | ||
raise AnsibleError( | ||
"Invalid IO-class file format ({0})".format(ioclass_file) | ||
) | ||
|
||
ioclass_ids = [] | ||
for ioclass in reader: | ||
if "unnamed fields" in ioclass: | ||
raise AnsibleError( | ||
"Invalid IO-class file format ({0})".format(ioclass_file) | ||
) | ||
|
||
try: | ||
id = int(ioclass["IO class id"]) | ||
except: | ||
raise AnsibleError( | ||
"Invalid IO-class id({0}) found in {1}".format( | ||
ioclass["IO class id"], ioclass_file | ||
) | ||
) | ||
|
||
if not (0 <= id < 33): | ||
raise AnsibleError( | ||
"Invalid IO-class id({0}) found in {1}".format( | ||
id, ioclass_file | ||
) | ||
) | ||
|
||
if id in ioclass_ids: | ||
raise AnsibleError( | ||
"Duplicate IO-class id({0}) found in {1}".format( | ||
id, ioclass_file | ||
) | ||
) | ||
ioclass_ids += [id] | ||
|
||
try: | ||
name = str(ioclass["IO class name"]) | ||
except: | ||
raise AnsibleError( | ||
"Invalid IO-class name({0}) found in {1}".format( | ||
ioclass["IO class name"], ioclass_file | ||
) | ||
) | ||
|
||
if len(name) >= 1024: | ||
raise AnsibleError( | ||
"Too long IO-class name({0}) found in {1}".format( | ||
name, ioclass_file | ||
) | ||
) | ||
|
||
for c in name: | ||
if c == "," or c == '"' or ord(c) < 32 or ord(c) > 126: | ||
raise AnsibleError( | ||
"Invalid character({0}) in IO-class name({1}) found in {2}".format( | ||
c, name, ioclass_file | ||
) | ||
) | ||
|
||
try: | ||
priority = int(ioclass["Eviction priority"]) | ||
except: | ||
raise AnsibleError( | ||
"Invalid IO-class priority({0}) found in {1}".format( | ||
ioclass["IO class id"], ioclass_file | ||
) | ||
) | ||
|
||
if not (0 <= priority <= 255): | ||
raise AnsibleError( | ||
"Out of range IO-class priority({0}) found in {1}".format( | ||
priority, ioclass_file | ||
) | ||
) | ||
|
||
try: | ||
allocation = int(ioclass["Allocation"]) | ||
except: | ||
raise AnsibleError( | ||
"Invalid IO-class allocation({0}) found in {1}".format( | ||
ioclass["Allocation"], ioclass_file | ||
) | ||
) | ||
|
||
if not (0 <= allocation <= 1): | ||
raise AnsibleError( | ||
"Invalid IO-class allocation({0}) found in {1}".format( | ||
allocation, ioclass_file | ||
) | ||
) | ||
|
||
|
||
class ActionModule(ActionBase): | ||
def run(self, tmp=None, task_vars=None): | ||
if ( | ||
"check_cache_config" in self._task.args | ||
and "io_class" in self._task.args["check_cache_config"] | ||
and self._task.args["check_cache_config"]["io_class"] | ||
): | ||
validate_ioclass_file( | ||
self._task.args["check_cache_config"]["io_class"] | ||
) | ||
del self._task.args["check_cache_config"]["io_class"] | ||
|
||
results = super(ActionModule, self).run(tmp, task_vars) | ||
results = merge_hash( | ||
results, self._execute_module(tmp=tmp, task_vars=task_vars) | ||
) | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
# This is a sample configuration of Open CAS deployment configuration | ||
|
||
# List of all cache devices configuration | ||
opencas_cache_devices: | ||
- cache_device: /dev/nvme0n1 # path to device or partition | ||
id: 1 # id used to corelate cores with cache instances | ||
cache_mode: wt # caching mode <wt, wb, wa, pt, wo> | ||
force: False # [OPTIONAL] Ignore and overwrite existing partition table | ||
cleaning_policy: alru # [OPTIONAL] cleaning policy <alru, acp, nop> | ||
line_size: 4 # [OPTIONAL] cache line size <4, 8, 16, 32, 64> [kb] | ||
io_class: default.csv # [OPTIONAL] io classification file name | ||
# all files used here should be put in | ||
# roles/opencas-deploy/files/ | ||
|
||
# List of all cached volumes | ||
opencas_cached_volumes: | ||
- id: 1 # id of core device | ||
cache_id: 1 # id of cache defined in open_cas_cache_devices list | ||
cached_volume: /dev/sdc # path to cached device or partition | ||
- id: 2 | ||
cache_id: 1 | ||
cached_volume: /dev/sdd | ||
... |
Oops, something went wrong.