Oracle ZFS Storage Appliance Client

Copyright 2014 © LimePoint Pty Ltd. All rights reserved.

Description

The oracle-zfs-client ruby gem provides a ruby client for interacting with the ZFS storage appliance RESTful APIs.

Prerequisites

Gem: mintpress-common

The mintpress-common ruby gem provides license validation utility to verify your MintPress licence. On your provisioning node, please ensure you have a valid MintPress license in the location ~/.mintpress/mintpress.licence

Examples

Examples located in test/test.rb

Build

To Build this gem:

Build GEM gem build ./oracle-zfs.gemspec

Install GEM from local gemfile gem install –local ./oracle-zfs-1.0.1.gem

Usage

require 'oracle-zfs'

Example: Create Client Connection

zfs_api_url = 'https://10.10.10.10:215'
  zfs_username = 'root'
  zfs_password = 'welcome1'
  zfs_verify_ssl = false

  zfs_client = OracleZFS::Client.new(api_url: zfs_api_url, username: zfs_username, password: zfs_password, verify_ssl: zfs_verify_ssl)

Example: Pool Operations

pool_name = 'demo'

  puts "[TEST]: Create Pool"
  result = zfs_client.storage_services.pool_create(pool: pool_name, profile: "mirror")
  puts "Pool Create: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Scrub Pool [Start]"
  result = zfs_client.storage_services.pool_scrub(pool: pool_name)
  puts "Pool Scrub [Stop]: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Scrub Pool [Stop]"
  result = zfs_client.storage_services.pool_scrub_stop(pool: pool_name)
  puts "Pool Scrub [Stop]: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Delete Pool"
  result = zfs_client.storage_services.pool_delete(pool: pool_name)
  puts "Pool Create: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: List Pools"
  pools = zfs_client.storage_services.pools_list
  puts "Pools: " + pools.inspect

  puts "[TEST]: Get Pool by name"
  pool = zfs_client.storage_services.pool_get(pool_name)
  puts "Pool: " + pool.inspect

Example: Project Operations

pool_name = 'demo'
  project_name = 'proj-demo'

  puts "[TEST]: Create Pool"
  result = zfs_client.storage_services.pool_create(pool: pool_name, profile: "mirror")
  puts "Pool Create: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Creating Project"
  # Create (twice to ensure idempotence is tested)
  project_props = { "readonly" => false, "sharenfs" => "on" }
  project = zfs_client.storage_services.project_create(pool: pool_name, project: project_name, props: project_props)

  # Modify
  puts "[TEST]: Modifying Project"
  project_props = { "readonly" => true, "sharenfs" => "on" }
  project = zfs_client.storage_services.project_modify(pool: pool_name, project: project_name, props: project_props)

  # ## Project Tests
  puts "[TEST]: List ALL Projects"
  projects_all = zfs_client.storage_services.projects_listall
  puts "Projects ALL: " + projects_all.inspect

  puts "[TEST]: Project exists?"
  puts zfs_client.storage_services.project_exists?(pool: pool_name, project: project_name).inspect

  puts "[TEST]: List Project by name"
  projects = zfs_client.storage_services.projects_list(pool_name)
  puts "Projects in pool [#{pool_name}]: " + projects.inspect

  puts "[TEST]: Get Project details"
  project_details = zfs_client.storage_services.project_get(pool: pool_name, project: project_name)
  puts "Project Details [#{project_name}] in pool [#{pool_name}]: " + project_details.inspect

  puts "[TEST]: Get Project Properties"
  project_properties = zfs_client.storage_services.project_properties(pool: pool_name, project: project_name)
  puts "Project Properties [#{pool_name},#{project_name}]: " + project_properties.inspect
  puts "Project Properties [#{pool_name},#{project_name}]: " + JSON.pretty_generate(project_properties) unless project_properties.nil?

  puts "[TEST]: Delete Project"
  project = zfs_client.storage_services.project_delete(pool: pool_name, project: project_name)
  project = zfs_client.storage_services.project_delete(pool: pool_name, project: project_name)

Example: Filesystem Operations

pool_name = 'demo'
  project_name = 'proj-demo'
  filesystem_name = 'share-demo'
  project_snapshot_name = 'initial-backup'
  filesystem_snapshot_name = 'initial-fs-backup'

  fs_props = { 
                "readonly" => false,
                "sharenfs" => "sec=sys,rw=@0.0.0.0/0,root=@0.0.0.0/0",
                "quota" => (250*1024*1024*1024).to_f,
                "quota_snap" => false
              }

  project_props = { 
                "aclmode" => "passthrough",
                "aclinherit" => "passthrough",
                "sharenfs" => "off"
              }

  puts "[TEST]: Create Project"
  project = zfs_client.storage_services.project_create(pool: pool_name, project: project_name, props: project_props)
  # project = zfs_client.storage_services.project_modify(pool: pool_name, project: project_name, props: project_props)

  puts "[TEST]: Create Filesystem"
  filesystem = zfs_client.storage_services.filesystem_create(pool: pool_name, project: project_name, filesystem: filesystem_name, props: fs_props)
  filesystem = zfs_client.storage_services.filesystem_modify(pool: pool_name, project: project_name, filesystem: filesystem_name, props: fs_props)

  puts "[TEST]: Get Filesystem Details"
  filesystem_details = zfs_client.storage_services.filesystem_get(pool: pool_name, project: project_name, filesystem: filesystem_name)
  puts "Filesystem Details [#{filesystem_name}] for Project [default] in pool [#{pool_name}]: " + filesystem_details.inspect
  puts "Filesystem Details [#{filesystem_name}] for Project [default] in pool [#{pool_name}]: " + JSON.pretty_generate(filesystem_details) unless filesystem_details.nil?

  puts "[TEST]: Modify Filesystem"
  filesystem_props = { "readonly" => true}
  filesystem = zfs_client.storage_services.filesystem_modify(pool: pool_name, project: project_name, filesystem: filesystem_name, props: filesystem_props)

  puts "[TEST]: Get Filesystem by name"
  filesystem_details = zfs_client.storage_services.filesystem_get(pool: pool_name, project: project_name, filesystem: filesystem_name)
  puts "Filesystem Details [#{filesystem_name}] for Project [default] in Pool [#{pool_name}]: " + filesystem_details.inspect

  puts "[TEST]: Modify Filesystem"
  filesystem_props = { "readonly" => false}
  filesystem = zfs_client.storage_services.filesystem_modify(pool: pool_name, project: project_name, filesystem: filesystem_name, props: filesystem_props)

  puts "[TEST]: Get Filesystem Details"
  filesystem_details = zfs_client.storage_services.filesystem_get(pool: pool_name, project: project_name, filesystem: filesystem_name)
  puts "Filesystem Details [#{filesystem_name}] for Project [default] in Pool [#{pool_name}]: " + filesystem_details.inspect

  puts "[TEST]: List ALL Filesystems"
  filesystems_all = zfs_client.storage_services.filesystems_listall
  puts "Filesystems ALL: " + filesystems_all.inspect

  puts "[TEST]: List Filesystem by name"
  filesystems = zfs_client.storage_services.filesystems_list(pool: pool_name, project: project_name)
  puts "Filesystems for Project [#{pool_name}] in pool [#{project_name}]: " + filesystems.inspect

  puts "[TEST]: Deleting Filesystem"
  zfs_client.storage_services.filesystem_delete(pool: pool_name, project: project_name, filesystem: filesystem_name)

Example: Snapshot Operations

puts "[TEST]: Create Project snapshot"
  result = zfs_client.storage_services.project_snapshot_create(pool: pool_name, project: project_name, snapshot: project_snapshot_name)
  puts "Project Snapshot Created: " + result.inspect

  puts "[TEST]: Create Filesystem snapshot"
  result = zfs_client.storage_services.filesystem_snapshot_create(pool: pool_name, project: project_name, filesystem: filesystem_name, snapshot: filesystem_snapshot_name)
  puts "Filesystem Snapshot Created: " + result.inspect

  puts "[TEST]: List ALL snapshots"
  result = zfs_client.storage_services.snapshots_listall
  puts "All Local Snapshots: " + result.inspect

  puts "[TEST]: List snapshots for Project"
  result = zfs_client.storage_services.project_snapshots_list(pool: pool_name, project: project_name)
  puts "All Project Snapshots [#{project_name}]: " + result.inspect

  puts "[TEST]: List snapshots for Filesystem"
  result = zfs_client.storage_services.filesystem_snapshots_list(pool: pool_name, project: project_name, filesystem: filesystem_name)
  puts "All Filesystem Snapshots [#{project_name}]: " + result.inspect

  puts "[TEST]: Get Project snapshot"
  result = zfs_client.storage_services.project_snapshot_get(pool: pool_name, project: project_name, snapshot: project_snapshot_name)
  puts "Project Snapshot Details: " + result.inspect

  puts "[TEST]: Get Filesystem snapshot"
  result = zfs_client.storage_services.filesystem_snapshot_get(pool: pool_name, project: project_name, filesystem: filesystem_name, snapshot: filesystem_snapshot_name)
  puts "Filesystem Snapshot Details: " + result.inspect

  puts "[TEST]: List Project Snapshot Schedule"
  result = zfs_client.storage_services.project_snapshot_schedule_list(pool: pool_name, project: project_name)
  puts "Project Snapshot Schedule Details: " + result.inspect

  puts "[TEST]: List Project Snapshot Schedule List"
  result = zfs_client.storage_services.project_snapshot_schedule_list(pool: pool_name, project: project_name)
  puts "Project Snapshot Schedule List: " + JSON.pretty_generate(result)

  puts "[TEST]: Get Project Snapshot Schedule Details"
  result = zfs_client.storage_services.project_snapshot_schedule_get(pool: pool_name, project: project_name, snapshot_schedule: "automatic-000")
  puts "Project Snapshot Schedule Details: " + JSON.pretty_generate(result)

  puts "[TEST]: List Filesystem Snapshot Schedule"
  result = zfs_client.storage_services.filesystem_snapshot_schedule_list(pool: pool_name, project: project_name, filesystem: filesystem_name)
  puts "Filesystem Snapshot Schedule Details: " + JSON.pretty_generate(result)

Example: Replication Operations

puts "[TEST]: Replication Service Status"
  result = zfs_client.replication_services.replication_state
  puts "Replication Services: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Enabled?"
  result = zfs_client.replication_services.replication_enabled?
  puts "Replication Enabled?: " + result.inspect unless result.nil?

  puts "[TEST]: Replication Service - Enable"
  result = zfs_client.replication_services.replication_enable
  puts "Replication Services (Enable): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Service - Disable"
  result = zfs_client.replication_services.replication_disable
  puts "Replication Services (Disable): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Targets (ALL)"
  result = zfs_client.replication_services.replication_targets
  puts "Replication Targets (ALL): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Targets (zfs_remote)"
  result = zfs_client.replication_services.replication_target_get("zfs_remote")
  puts "Replication Targets (zfs_remote): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Delete Replication Target (zfs_remote)"
  result = zfs_client.replication_services.replication_target_delete(name: "zfs_remote")
  puts "Delete Replication Target (zfs_remote): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  remote_replication_url="192.168.1.63"
  puts "[TEST]: Create Replication Target (zfs_remote)"
  result = zfs_client.replication_services.replication_target_create(name: "zfs_remote", hostname: remote_replication_url, password: "welcome1")
  puts "Create Replication Target (zfs_remote): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: List Replication Actions (ALL)"
  result = zfs_client.replication_services.replication_actions
  puts "List Replication Actions (ALL): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  replication_id = "bf9a1a0f-3bc4-64f8-9c11-aceb71020d4a"
  puts "[TEST]: Get Replication Action Details (#{replication_id})"
  result = zfs_client.replication_services.replication_action_get(replication_id)
  puts "Get Replication Action Details(#{replication_id}): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  source_pool = pool_name
  source_project = project_name
  source_filesystem = filesystem_name
  replication_target = "zfs_remote"
  target_pool = "replication"

  puts "[TEST]: Delete Replication Action"
  result = zfs_client.replication_services.replication_action_delete(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem)
  puts "Delete Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Create Replication Action"
  ## Note: If source_filesystem is nil, replication action is created at project level, otherwise if source_filesystem is specified, it is created at the filesystem level.
  result = zfs_client.replication_services.replication_action_create(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem, target_pool: target_pool)
  # result = zfs_client.replication_services.replication_action_create(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem, target_pool: target_pool, enabled: true, continuous: false, include_snaps: false, max_bandwidth: "unlimited", use_ssl: true, compression: true, include_clone_origin_as_data: false, retain_user_snaps_on_target: false)
  puts "Create Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Modify Replication Action"
  result = zfs_client.replication_services.replication_action_modify(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem, target_pool: target_pool, enabled: true)
  puts "Modify Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Send Update to Replication Action"
  result = zfs_client.replication_services.replication_action_sendupdate(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem)
  puts "Send Update to Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Cancel Update to Replication Action"
  result = zfs_client.replication_services.replication_action_cancelupdate(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem)
  puts "Cancel Update to Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Delete Replication Action"
  result = zfs_client.replication_services.replication_action_delete(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: source_filesystem)
  puts "Delete Replication Action: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Action Schedules"
  result = zfs_client.replication_services.replication_action_schedules(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: nil)
  puts "Replication Action Schedules: " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

  puts "[TEST]: Replication Action Schedule Exists?"
  result = zfs_client.replication_services.replication_action_schedule_exists?(replication_target: replication_target, source_pool: source_pool, source_project: source_project, source_filesystem: nil, frequency: "halfhour", minute: "30")
  puts "Replication Action Schedule Exists?: " + result.inspect unless result.nil?

  puts "[TEST]: Replication Sources (ALL)"
  result = zfs_client.replication_services.replication_sources
  puts "Replication Sources (ALL): " + result.inspect unless result.nil?
  puts JSON.pretty_generate(result) unless result.nil?

Example: System Commands

puts "[TEST]: List Version"
  result = zfs_client.system_commands.version
  puts "Version: " + JSON.pretty_generate(result)

  puts "[TEST]: List Memory"
  result = zfs_client.system_commands.memory
  puts "Memory: " + JSON.pretty_generate(result)

  puts "[TEST]: List Disks"
  result = zfs_client.system_commands.disks
  puts "Disks: " + JSON.pretty_generate(result)

  puts "[TEST]: List Disks Properties for disk [disk-000]"
  result = zfs_client.system_commands.disk_get("disk-000")
  puts "Disk [disk-000]: " + JSON.pretty_generate(result)

  puts "[TEST]: Restarting the management interface"
  result = zfs_client.system_commands.restart

  puts "[TEST]: Rebooting the appliance"
  result = zfs_client.system_commands.reboot

  puts "[TEST]: Poweroff the appliance"
  result = zfs_client.system_commands.poweroff

Example: User Operations

puts "[TEST]: List Users"
  result = zfs_client.user_services.users
  puts "Users: " + JSON.pretty_generate(result)

  puts "[TEST]: List User [root]"
  result = zfs_client.user_services.user_get("root")
  puts "User [root]: " + JSON.pretty_generate(result)

  puts "[TEST]: List User Preferences [root]"
  result = zfs_client.user_services.user_prefs_get("root")
  puts "User Preferences [root]: " + JSON.pretty_generate(result)

Example: Hardware Operations

result = zfs_client.hardware_services.chassis
  puts "Chassis Details: " + result.inspect
  puts "Chassis Details: " + JSON.pretty_generate(result)

  result = zfs_client.hardware_services.chassis_get(chassis: "chassis-000")
  puts "Chassis Details [chassis-000]: " + result.inspect
  puts "Chassis Details [chassis-000]: " + JSON.pretty_generate(result)

  result = zfs_client.hardware_services.chassis_components(chassis: "chassis-000", component_type: "cpu")
  puts "Chassis Details [chassis-000] for Component [CPU]: " + result.inspect
  puts "Chassis Details [chassis-000] for Component [CPU]: " + JSON.pretty_generate(result)

  result = zfs_client.hardware_services.chassis_components(chassis: "chassis-000", component_type: "disk")
  puts "Chassis Details [chassis-000] for Component [DISK]: " + result.inspect
  puts "Chassis Details [chassis-000] for Component [DISK]: " + JSON.pretty_generate(result)

  puts "[TEST]: Get Cluster Properties"
  result = zfs_client.hardware_services.cluster
  puts "Cluster Details: " + result.inspect
  puts "Cluster Details: " + JSON.pretty_generate(result)

  puts "[TEST]: Get Cluster Links Details"
  result = zfs_client.hardware_services.cluster_links
  puts "Cluster Links Details: " + result.inspect
  puts "Cluster Links Details: " + JSON.pretty_generate(result)

License & Authors

  • Author:: Goran Stankovski (gstankovski@limepoint.com)

# 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]