MintPress Infrastructure ZFS Appliance

Copyright 2021 © LimePoint Pty Ltd. All rights reserved.

Description

The mintpress-infrastructure-zfs-appliance ruby gem provides a MintPress controller resources for interacting with ZFS appliance. It uses the underlying gem oracle-zfs-client to perform its interactions.

Prerequisites

Gem: oracle-zfs-client

The oracle-zfs-client ruby gem provides a Ruby Rest client for interacting with Oracle ZFS Appliance

Examples

Store all the credentials and data in a YAML file (you can use JSON as well but will need to modify the script to read from a JSON file). Put the following in the YAML file:

---
    zfs:
      client:
        api_url: https://10.0.8.6:215
        username: root
        password: welcome1
      pool:
        name: foo
      project:
        name: foo-project
        snapshot: initial-backup
      filesystem:
        name: foo-fs
        quota: 100
        snapshot: initial-fs-backup

Note that you can also hard code these values in the script if you choose to, there’s no binding on using the details from a file. The following scripts shows different functions you can do with this gem.

require 'mintpress-resources'
require 'mintpress-infrastructure-zfs-appliance'
require 'yaml'
require 'hashie'

require 'mintpress-logger'
include MintLogger

########## Load test data from the file #######################

# You must pass the file to this script as an argument
info "#{__FILE__}: Arguments: " + ARGV.inspect
test_data = Hashie.symbolize_keys! YAML.load_file(ARGV[0])

ENV['MINTPRESS_LOG_LEVEL']='info'
info "Log Level: " + ENV['MINTPRESS_LOG_LEVEL']

zfs_api_url = test_data[:zfs][:client][:api_url]
zfs_username = test_data[:zfs][:client][:username]
zfs_password = test_data[:zfs][:client][:password]
zfs_verify_ssl = false

pool_name = test_data[:zfs][:pool][:name]
project_name = test_data[:zfs][:project][:name]
filesystem_name = test_data[:zfs][:filesystem][:name]
filesystem_quota = test_data[:zfs][:filesystem][:quota]
project_snapshot_name = test_data[:zfs][:project][:snapshot]
filesystem_snapshot_name = test_data[:zfs][:filesystem][:snapshot]

info "API URL: #{zfs_api_url}"
info "API Username: #{zfs_username}"
info "API Password: #{zfs_password}"

## ZFS Platform
MintPress::InfrastructureZfsAppliance::UsingZfsPlatform.new(api_url: zfs_api_url, username: zfs_username, password: zfs_password, verify_ssl: zfs_verify_ssl)

#################
# ZFS Cleanup
#################
x = MintPress::InfrastructureZfsAppliance::ZfsPool.new(name: pool_name, profile: 'mirror')
y = MintPress::InfrastructureZfsAppliance::ZfsProject.new(name: project_name, pool: pool_name)
z = MintPress::InfrastructureZfsAppliance::ZfsFilesystem.new(name: filesystem_name, project: project_name, pool: pool_name)

z.delete
y.delete
x.delete

#################
# ZFS Pool
#################
pool = MintPress::InfrastructureZfsAppliance::ZfsPool.new(name: pool_name, profile: 'mirror', properties: { data: 2 })

info "Pool Exists?: #{pool.exists?}"
info JSON.pretty_generate(pool.get)
pool.create
pool.configure
pool.delete
pool.create
pool.harvest
info JSON.pretty_generate(pool.get)
::File.open('/tmp/pool.create.json', 'w') { |file| file.write(JSON.pretty_generate(pool.get)) }

#################
# ZFS Project
#################
project = MintPress::InfrastructureZfsAppliance::ZfsProject.new(name: project_name, pool: pool_name)

info "Project Exists?: #{project.exists?}"
project.delete
project.create
info JSON.pretty_generate(project.get)
::File.open('/tmp/project.create.json', 'w') { |file| file.write(JSON.pretty_generate(project.get)) }

project.properties = { 
              "aclmode" => "passthrough",
              "aclinherit" => "passthrough",
              "sharenfs" => "off"
            }
project.modify
info JSON.pretty_generate(project.get)
::File.open('/tmp/project.modify.json', 'w') { |file| file.write(JSON.pretty_generate(project.get)) }

#################
# ZFS Filesystem
#################
filesystem = MintPress::InfrastructureZfsAppliance::ZfsFilesystem.new(name: filesystem_name, project: project_name, pool: pool_name)

info "Filesystem Exists?: #{filesystem.exists?}"
filesystem.delete
filesystem.create
info JSON.pretty_generate(filesystem.get)
::File.open('/tmp/filesystem.create.json', 'w') { |file| file.write(JSON.pretty_generate(filesystem.get)) }

filesystem.properties = {
              "readonly" => true,
              "sharenfs" => "sec=sys,rw=@0.0.0.0/0,root=@0.0.0.0/0",
              "quota" => (filesystem_quota*1024*1024*1024).to_f,
              "quota_snap" => false
            }
filesystem.modify
info JSON.pretty_generate(filesystem.get)
::File.open('/tmp/filesystem.modify.readonly.json', 'w') { |file| file.write(JSON.pretty_generate(filesystem.get)) }

filesystem.properties = {
              "readonly" => false,
              "sharenfs" => "sec=sys,rw=@0.0.0.0/0,root=@0.0.0.0/0",
              "quota" => (filesystem_quota*2*1024*1024*1024).to_f,
              "quota_snap" => false
            }
filesystem.modify
info JSON.pretty_generate(filesystem.get)
::File.open('/tmp/filesystem.modify.readwrite.json', 'w') { |file| file.write(JSON.pretty_generate(filesystem.get)) }

##########################
# ZFS Filesystem Snapshot
##########################

filesystem.add_snapshot(name: filesystem_snapshot_name)
filesystem.snapshots[filesystem_snapshot_name].create
filesystem.snapshots[filesystem_snapshot_name].create
filesystem.snapshots[filesystem_snapshot_name].delete
filesystem.snapshots[filesystem_snapshot_name].delete
filesystem.snapshots[filesystem_snapshot_name].create
filesystem.snapshots[filesystem_snapshot_name].rollback
info JSON.pretty_generate(filesystem.snapshots[filesystem_snapshot_name].get)
::File.open('/tmp/filesystem.snapshot.create.json', 'w') { |file| file.write(JSON.pretty_generate(filesystem.snapshots[filesystem_snapshot_name].get)) }

#######################
# ZFS Project Snapshot
#######################
project.add_snapshot(name: project_snapshot_name)
project.snapshots[project_snapshot_name].create
project.snapshots[project_snapshot_name].create
project.snapshots[project_snapshot_name].delete
project.snapshots[project_snapshot_name].delete
project.snapshots[project_snapshot_name].create
info JSON.pretty_generate(project.snapshots[project_snapshot_name].get)
::File.open('/tmp/project.snapshot.create.json', 'w') { |file| file.write(JSON.pretty_generate(project.snapshots[project_snapshot_name].get)) }

#################
# ZFS Cleanup
#################
# filesystem.snapshots[filesystem_snapshot_name].delete
# filesystem.delete
# project.snapshots[project_snapshot_name].delete
# project.delete
# pool.delete

info "  Ending test at: #{Time.now}"
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
elapsed_time = end_time - start_time
info "  Elapsed Time: #{elapsed_time} seconds"
info "+###################### END ##########################+"

License & Authors

# MintPress® - Automation and Configuration Management Platform
# Copyright © 2019 LimePoint. All rights reserved.
#
# This program and its contents are confidential and owned by LimePoint.
# Only licenced users are permitted to access and use of this file.
# This program (or any part of it) may not be disclosed, copied or used
# except as expressly permitted in LimePoint’s End User Licence Agreement.
#
# LimePoint® and MintPress® are Registered Trademarks of LimePoint
# For more information contact LimePoint at [http://www.limepoint.com]