aix-wpar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0f9c9afb07e4ee297f0e0bda903facff874466c
4
+ data.tar.gz: 74d10e4f36ea29ebf139e0843d85e5c8168a3807
5
+ SHA512:
6
+ metadata.gz: caf767f37009262308c1d639f4ce40735b427287e7d73df46fc590ea2db4444022ee5df6e64c5fbe82d32121d1541524641d632c5d79308736c16bd158553213
7
+ data.tar.gz: fb0a588276d549634225ebad1cfcbc67a3b627a6ef0ba03b05c2ac9b81dc28b33db914642b8726d15e3efc16e9f9050113f1cab8d37e0c415de6978311f04f0f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Alain Dejoux (<adejoux@djouxtech.net>)
2
+
3
+ Copyright (C) 2016, Alain Dejoux
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ AX WPAR ruby library
2
+
3
+ ## description
4
+
5
+ This library allows to manage AIX wpars like ruby objects. Most standard operations are supported.
6
+
7
+ ## Installation
8
+
9
+ Standard isntallation with internet access:
10
+ gem install aix-wpar
11
+
12
+ Local installation:
13
+ gem install --local aix-wpar-0.1.0.gem
14
+
15
+ ## Usage
16
+
17
+ ~~~ruby
18
+ require 'wpars'
19
+
20
+ #new wpar named testwpar
21
+ wpar = WPAR::WPAR.new(command: "ssh adxlpar2", name: "testwpar2")
22
+ #live stream output
23
+ wpar.live_stream=STDOUT
24
+
25
+ #set hostname if different
26
+ wpar.general.hostname="testwpar2"
27
+
28
+ #set auto start
29
+ wpar.general.auto="yes"
30
+
31
+ #create wpar
32
+ wpar.create
33
+
34
+ #stop wpar
35
+ wpar.stop(force: true)
36
+
37
+ #start wpar
38
+ wpar.start
39
+ #wpar.update
40
+ wpar.sync
41
+
42
+ #delete
43
+ wpar.destroy(force: true)
44
+ ~~~
45
+
46
+ **live_stream** allows to display the system commands output.
47
+
48
+
49
+ ## <a name="authors"></a> Authors
50
+
51
+ Created and maintained by [Alain Dejoux][author] (<adejoux@djouxtech.net>)
52
+
53
+ ## <a name="license"></a> License
54
+
55
+ Apache 2.0 (see [LICENSE][license])
56
+
57
+
58
+ [author]: https://github.com/adejoux
59
+ [issues]: https://github.com/adejoux/aix-wpar/issues
60
+ [license]: https://github.com/adejoux/aix-wpar/blob/master/LICENSE
61
+ [repo]: https://github.com/adejoux/aix-wpar
data/aix-wpar.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $:.unshift(File.expand_path('../lib/', __FILE__))
2
+ require 'wpars/version'
3
+
4
+ deps = {
5
+ 'mixlib-shellout' => [ '~> 2' ]
6
+ }
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.authors = ["Alain Dejoux"]
10
+ gem.email = ["adejoux@djouxtech.net"]
11
+ gem.description = %q{A wrapper for the AIX WPAR administration.}
12
+ gem.license = "MIT"
13
+ gem.summary = %q{A ruby library wrapper for the AIX WPAR administration.}
14
+ gem.homepage = "https://github.com/adejoux/ruby-aix-wpar"
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "aix-wpar"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = WPAR::VERSION
20
+
21
+ deps.each do |dep, constraints|
22
+ gem.add_runtime_dependency dep, *constraints
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'wpars'
2
+ wpars = WPAR::WPARS.new(command: "ssh adxlpar2")
3
+
4
+ wpars.generals.each do |entry|
5
+ puts entry.inspect
6
+ end
7
+
8
+ #puts wpars['kitchenwpar'].networks.inspect
9
+ #puts wpars['kitchenwpar'].devices.inspect
10
+ #puts wpars['testwpar2'].get_rootvg.inspect
11
+
12
+ #start/stop examples
13
+ #wpars['testwpar2'].start
14
+ #wpars['testwpar2'].stop(force: true)
@@ -0,0 +1,28 @@
1
+ require 'wpars'
2
+
3
+ #new wpar named testwpar
4
+ wpar = WPAR::WPAR.new(command: "ssh adxlpar2", name: "testwpar2")
5
+
6
+ #live stream output
7
+ wpar.live_stream=STDOUT
8
+
9
+ #set hostname if different
10
+ wpar.general.hostname="testwpar2"
11
+
12
+ #set auto start
13
+ wpar.general.auto="yes"
14
+
15
+ #create wpar
16
+ wpar.create
17
+
18
+ #stop wpar
19
+ wpar.stop(force: true)
20
+
21
+ #start wpar
22
+ wpar.start
23
+
24
+ #sync wpar
25
+ wpar.sync
26
+
27
+ #delete
28
+ wpar.destroy(force: true)
data/lib/wpars.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'wpars/external'
2
+ require 'wpars/version'
3
+ require 'wpars/wrapper/lswpar_general'
4
+ require 'wpars/wrapper/lswpar_network'
5
+ require 'wpars/wrapper/lswpar_device'
6
+ require 'wpars/wrapper/lswpar_mountpoint'
7
+ require 'wpars/wrapper/lswpar_resource_control'
8
+ require 'wpars/wrapper/lswpar_security'
9
+ require 'wpars/wpar'
10
+
11
+ module WPAR
12
+ class WPARS
13
+ include Wrapper
14
+ attr_reader :networks, :devices, :mountpoints, :resource_controls
15
+ attr_reader :securities, :generals
16
+
17
+ VALID_OPTIONS = [
18
+ :command,
19
+ :version,
20
+ :debug
21
+ ]
22
+
23
+ def initialize(options={})
24
+ # handy, thanks net-ssh!
25
+ invalid_options = options.keys - VALID_OPTIONS
26
+ if invalid_options.any?
27
+ raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
28
+ end
29
+
30
+ # default to loading attributes for the current version
31
+ options[:version] ||= version
32
+ options[:debug] ||= false
33
+ @command = options[:command]
34
+ @generals = LswparGeneral.new(options).list
35
+ @networks = LswparNetwork.new(options).list
36
+ @devices = LswparDevice.new(options).list
37
+ @mountpoints = LswparMountpoint.new(options).list
38
+ @resource_controls = LswparResourceControl.new(options).list
39
+ @securities = LswparSecurity.new(options).list
40
+ end
41
+
42
+ def [](name)
43
+ if get_generals(name).nil?
44
+ return nil
45
+ end
46
+ wpar = WPAR.new(name: name,
47
+ command: @command,
48
+ general: get_generals(name),
49
+ networks: get_networks(name),
50
+ devices: get_devices(name),
51
+ mountpoints: get_mountpoints(name),
52
+ resource_controls: get_resource_controls(name),
53
+ securities: get_securities(name))
54
+ return wpar
55
+ end
56
+
57
+ def version
58
+ VERSION
59
+ end
60
+
61
+ def get_generals(name)
62
+ begin
63
+ @generals.select {|o| o.name == name}.first
64
+ rescue
65
+ nil
66
+ end
67
+ end
68
+
69
+ def get_networks(name)
70
+ @networks.select {|o| o.name == name}
71
+ end
72
+
73
+ def get_devices(name)
74
+ @devices.select {|o| o.name == name}
75
+ end
76
+
77
+ def get_mountpoints(name)
78
+ @mountpoints.select {|o| o.name == name}
79
+ end
80
+
81
+ def get_resource_controls(name)
82
+ begin
83
+ @resource_controls.select {|o| o.name == name}.first
84
+ rescue
85
+ nil
86
+ end
87
+ end
88
+
89
+ def get_securities(name)
90
+ begin
91
+ @securities.select {|o| o.name == name}.first
92
+ rescue
93
+ nil
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,18 @@
1
+ module WPAR
2
+ class Device
3
+ attr_reader :name, :devname, :devtype, :vdevname, :devstatus
4
+ attr_reader :devid, :rootvg, :adapter
5
+
6
+ def initialize(params)
7
+ @command = params[:command]
8
+ @name = params[:name]
9
+ @devname = params[:devname]
10
+ @devtype = params[:devtype]
11
+ @vdevname = params[:vdevname]
12
+ @devstatus = params[:devstatus]
13
+ @devid = params[:devid]
14
+ @rootvg = params[:rootvg]
15
+ @adapter = params[:adapter]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'mixlib/shellout'
3
+
4
+ module WPAR
5
+ module External
6
+ class ExternalFailure < RuntimeError; end
7
+
8
+ def cmd(cmd: nil, live_stream: nil)
9
+ command = Mixlib::ShellOut.new(cmd)
10
+ command.live_stream=live_stream if live_stream
11
+ command.run_command
12
+ command.error!
13
+ return command.stdout
14
+ end
15
+ module_function :cmd
16
+ end # module External
17
+ end # module WPAR
@@ -0,0 +1,31 @@
1
+ module WPAR
2
+ class General
3
+ attr_reader :name, :state, :type, :rootvgwpar, :routing, :uuid
4
+ attr_reader :vipwpar, :directory, :owner, :script, :privateusr
5
+ attr_reader :checkpointable, :application, :ostype, :xwparipc, :architecture
6
+ attr_accessor :hostname, :auto
7
+
8
+ def initialize(params)
9
+ @command = params[:command]
10
+ @name = params[:name]
11
+ @state = params[:state]
12
+ @type = params[:type]
13
+ @rootvgwpar = params[:rootvgwpar]
14
+ @hostname = params[:hostname]
15
+ @routing = params[:routing]
16
+ @vipwpar = params[:vipwpar]
17
+ @directory = params[:directory]
18
+ @owner = params[:owner]
19
+ @script = params[:script]
20
+ @auto = params[:auto] || "no"
21
+ @privateusr = params[:privateusr]
22
+ @checkpointable = params[:checkpointable]
23
+ @application = params[:application]
24
+ @ostype = params[:ostype]
25
+ @xwparipc = params[:xwparipc]
26
+ @architecture = params[:architecture]
27
+ @uuid = params[:uuid]
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module WPAR
2
+ class Mountpoint
3
+ attr_reader :name, :mountpoint, :device, :vfs, :nodename, :options
4
+
5
+ def initialize(params)
6
+ @command = params[:command]
7
+ @name = params[:name]
8
+ @mountpoint = params[:mountpoint]
9
+ @device = params[:device]
10
+ @vfs = params[:vfs]
11
+ @nodename = params[:nodename]
12
+ @options = params[:options]
13
+ end
14
+ end
15
+ end
data/lib/wpars/name.rb ADDED
@@ -0,0 +1,7 @@
1
+ module WPAR
2
+ module Name
3
+ def [](name)
4
+ select {|o| o.name == name}
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ require 'ostruct'
2
+
3
+ #example of a WPAR network object
4
+ # <WPAR::Network name="kitchenwpar", interface="en0", address="10.10.10.100", mask_prefix="255.255.255.0", broadcast="10.10.10.255">
5
+ module WPAR
6
+ class Network
7
+ attr_reader :name
8
+ attr_accessor :interface, :address, :mask_prefix, :broadcast
9
+
10
+ def initialize(params)
11
+ @name = params[:name]
12
+ @interface = params[:interface]
13
+ @address = params[:address]
14
+ @mask_prefix = params[:mask_prefix]
15
+ @broadcast = params[:broadcast]
16
+ end
17
+
18
+ def empty?
19
+ wpar_attributes.all?{|k,v| self.send(k).nil?}
20
+ end
21
+
22
+ def wpar_attributes
23
+ attrs = Network.instance_methods(false) - [:name, :command, :state, :empty?, :wpar_attributes ]
24
+ attrs - attrs.grep(/=$/)
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ module WPAR
2
+ class ResourceControl
3
+ attr_reader :name, :state, :active, :rset
4
+ attr_reader :procvirtmem, :totalvirtmem, :totalprocesses
5
+ attr_reader :totalptys, :totallargepages, :pct_msgids, :pct_semids
6
+ attr_reader :pct_pinmem, :totalthreads, :pct_shmids
7
+ attr_accessor :shares_cpu, :cpu, :shares_memory, :memory
8
+
9
+ def initialize(params)
10
+ @command = params[:command]
11
+ @name = params[:name]
12
+ @state = params[:state]
13
+ @active = params[:active]
14
+ @rset = params[:rset]
15
+ @shares_cpu = params[:shares_cpu]
16
+ @cpu = params[:cpu]
17
+ @shares_memory = params[:shares_memory]
18
+ @memory = params[:memory]
19
+ @procvirtmem = params[:procvirtmem]
20
+ @totalvirtmem = params[:totalvirtmem]
21
+ @totalprocesses = params[:totalprocesses]
22
+ @totalptys = params[:totalptys]
23
+ @totallargepages = params[:totallargepages]
24
+ @pct_msgids = params[:pct_msgids]
25
+ @pct_semids = params[:pct_semids]
26
+ @pct_pinmem = params[:pct_pinmem]
27
+ @totalthreads = params[:totalthreads]
28
+ @pct_shmids = params[:pct_shmids]
29
+ end
30
+
31
+ def empty?
32
+ wpar_attributes.all?{|k,v| self.send(k).nil?}
33
+ end
34
+
35
+ def wpar_attributes
36
+ attrs = ResourceControl.instance_methods(false) - [:name, :command, :state, :empty?, :wpar_attributes ]
37
+ attrs - attrs.grep(/=$/)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ module WPAR
2
+ class Security
3
+ attr_reader :name, :state, :privs
4
+
5
+ def initialize(params)
6
+ @command = params[:command]
7
+ @name = params[:name]
8
+ @state = params[:state]
9
+ @privs = params[:privs]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module WPAR
2
+ VERSION = '0.1.0'
3
+ end
data/lib/wpars/wpar.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'wpars/external'
2
+ require 'wpars/version'
3
+ require 'wpars/general'
4
+ require 'wpars/network'
5
+ require 'wpars/device'
6
+ require 'wpars/mountpoint'
7
+ require 'wpars/resource_control'
8
+ require 'wpars/security'
9
+ require 'wpars/wrapper/lswpar_general'
10
+ require 'wpars/wrapper/lswpar_network'
11
+ require 'wpars/wrapper/lswpar_device'
12
+ require 'wpars/wrapper/lswpar_mountpoint'
13
+ require 'wpars/wrapper/lswpar_resource_control'
14
+ require 'wpars/wrapper/lswpar_security'
15
+ require 'wpars/wrapper/mkwpar'
16
+ require 'wpars/wrapper/rmwpar'
17
+ require 'wpars/wrapper/stopwpar'
18
+ require 'wpars/wrapper/startwpar'
19
+ require 'wpars/wrapper/syncwpar'
20
+
21
+ module WPAR
22
+ class WPAR
23
+ include Wrapper
24
+
25
+ attr_reader :networks, :devices, :mountpoints, :resource_control
26
+ attr_reader :security, :general, :name
27
+ attr_accessor :live_stream
28
+
29
+ def initialize(options = {})
30
+ @command = options[:command]
31
+ @name = options[:name]
32
+ @general = options[:general] || General.new(name: @name)
33
+ @networks = options[:networks] || Array.new([Network.new(name: @name)])
34
+ @devices = options[:devices] || Array.new([Device.new(name: @name)])
35
+ @mountpoints = options[:mountpoints] || Array.new([Mountpoint.new(name: @name)])
36
+ @resource_control = options[:resource_controls] ||ResourceControl.new(name: @name)
37
+ @security = options[:securities] || Security.new(name: @name)
38
+ end
39
+
40
+ def create(options = {})
41
+ MkWpar.create( name: @name,
42
+ command: @command,
43
+ wpar: self,
44
+ start: options[:start],
45
+ rootvg: options[:rootvg],
46
+ wparvg: options[:wparvg],
47
+ backupimage: options[:backupimage],
48
+ live_stream: @live_stream)
49
+ #update
50
+ update(options)
51
+ end
52
+
53
+ def destroy(force: nil)
54
+ RmWpar.destroy(name: @name, force: force, command: @command, live_stream: @live_stream)
55
+ end
56
+
57
+ def stop(force: nil)
58
+ StopWpar.stop( name: @name, force: force, command: @command, live_stream: @live_stream)
59
+
60
+ #update status
61
+ @general = LswparGeneral.new(command: @command).filter(@name)
62
+ end
63
+
64
+ def start()
65
+ StartWpar.start( name: @name, command: @command, live_stream: @live_stream)
66
+
67
+ #update status
68
+ @general = LswparGeneral.new(command: @command).filter(@name)
69
+ end
70
+
71
+ def sync(directory: nil)
72
+ SyncWpar.sync( name: @name, command: @command, directory: directory, live_stream: @live_stream)
73
+ end
74
+
75
+ def update(options = {})
76
+ options[:command] = @command
77
+ @general = LswparGeneral.new(options).filter(@name)
78
+ @networks = LswparNetwork.new(options).filter(@name)
79
+ @devices = LswparDevice.new(options).filter(@name)
80
+ @mountpoints = LswparMountpoint.new(options).filter(@name)
81
+ @resource_control = LswparResourceControl.new(options).filter(@name)
82
+ @security = LswparSecurity.new(options).filter(@name)
83
+ end
84
+
85
+ def add(address: nil, interface: nil, mask_prefix: nil, broadcast: nil)
86
+ params={}
87
+ params[:name] = @name
88
+ params[:address] = address
89
+ params[:interface] = interface
90
+ params[:mask_prefix] = mask_prefix
91
+ params[:broadcast] = broadcast
92
+
93
+ net = WPARS::Network.new(params)
94
+ @nets += net
95
+ end
96
+
97
+ def get_rootvg
98
+ @devices.select { |o| o.rootvg == "yes"}
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,13 @@
1
+ module WPAR
2
+ module Wrapper
3
+ module Constants
4
+ LSWPAR = '/usr/sbin/lswpar -c'
5
+ MKWPAR = '/usr/sbin/mkwpar'
6
+ RMWPAR = '/usr/sbin/rmwpar'
7
+ CHWPAR = '/usr/sbin/chwpar'
8
+ STOPWPAR = '/usr/sbin/stopwpar'
9
+ STARTWPAR = '/usr/sbin/startwpar'
10
+ SYNCWPAR = '/usr/sbin/syncwpar'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'csv'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ module Converter
6
+ def self.convert(output)
7
+ csv = CSV.new(output,
8
+ :col_sep => ':',
9
+ :headers => true,
10
+ :header_converters => :symbol,
11
+ :converters => :all)
12
+ csv.to_a.map {|row| row.to_hash }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module WPAR
2
+ module Wrapper
3
+ class Lswpar
4
+
5
+ def list
6
+ data = parse(External.cmd(cmd: @command))
7
+
8
+ if block_given?
9
+ return data.each { |obj| yield obj }
10
+ else
11
+ return data
12
+ end
13
+ end
14
+
15
+ def filter(name)
16
+ list.select { |o| o.name == name }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/device'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparDevice < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}D #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ devices = []
19
+ # remove sharp character
20
+ output.slice!(0)
21
+
22
+ Converter.convert(output).each do |dev|
23
+ device = Device.new(dev)
24
+ devices << device
25
+ end
26
+ return devices
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/general'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparGeneral < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}G #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ generals = []
19
+
20
+ # remove sharp character
21
+ output.slice!(0)
22
+
23
+ Converter.convert(output).each do |gen|
24
+ general = General.new(gen)
25
+ generals << general
26
+ end
27
+ return generals
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/mountpoint'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparMountpoint < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}M #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ mountpoints = []
19
+ # remove sharp character
20
+ output.slice!(0)
21
+
22
+ Converter.convert(output).each do |mnt|
23
+ mountpoint = Mountpoint.new(mnt)
24
+ mountpoints << mountpoint
25
+ end
26
+ return mountpoints
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/network'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparNetwork < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}N #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ networks = []
19
+ # remove sharp character
20
+ output.slice!(0)
21
+
22
+ Converter.convert(output).each do |net|
23
+ network = Network.new(net)
24
+ networks << network
25
+ end
26
+ return networks
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/resource_control'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparResourceControl < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}R #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ resources = []
19
+ # remove sharp character
20
+ output.slice!(0)
21
+
22
+ Converter.convert(output).each do |rsc|
23
+ resource = ResourceControl.new(rsc)
24
+ resources << resource
25
+ end
26
+ return resources
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'wpars/wrapper/constants'
2
+ require 'wpars/wrapper/converter'
3
+ require 'wpars/wrapper/lswpar'
4
+ require 'wpars/security'
5
+
6
+ module WPAR
7
+ module Wrapper
8
+ include Constants
9
+ include Converter
10
+ class LswparSecurity < Lswpar
11
+
12
+ def initialize(options)
13
+ @command = "#{options[:command]} #{Constants::LSWPAR}S #{options[:name]}"
14
+ end
15
+
16
+ private
17
+ def parse(output) #:nodoc:
18
+ securities = []
19
+ # remove sharp character
20
+ output.slice!(0)
21
+
22
+ Converter.convert(output).each do |sec|
23
+ security = Security.new(sec)
24
+ securities << security
25
+ end
26
+ return securities
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,91 @@
1
+ require 'wpars/wrapper/constants'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ include Constants
6
+ class MkWpar
7
+
8
+ def self.create(options = {})
9
+ cmd = build_mkwpar_command(options)
10
+ puts "debug: #{cmd}" unless options[:debug].nil?
11
+ External.cmd(cmd: cmd, live_stream: options[:live_stream])
12
+ end
13
+
14
+ private
15
+ def self.build_mkwpar_command(options = {})
16
+ wpar = options[:wpar]
17
+ cmd = "#{options[:command]} #{Constants::MKWPAR} -s -n #{wpar.name}"
18
+
19
+ if options[:start] == "yes"
20
+ cmd += " -a"
21
+ end
22
+
23
+ if wpar.general.auto == "yes"
24
+ cmd += " -A"
25
+ end
26
+
27
+ unless (wpar.general.hostname.nil? or wpar.general.hostname.empty?)
28
+ cmd += " -h #{wpar.general.hostname}"
29
+ end
30
+
31
+ unless options[:backupimage].nil?
32
+ cmd += " -B #{options[:backupimage]}"
33
+ end
34
+
35
+ unless options[:rootvg].nil?
36
+ cmd += " -D rootvg=yes devname=#{options[:rootvg]}"
37
+ end
38
+
39
+ unless options[:wparvg].nil?
40
+ cmd += " -g #{options[:wparvg]}"
41
+ end
42
+
43
+ # NETWORK section
44
+ wpar.networks.each do |net|
45
+ if net.empty?
46
+ next
47
+ end
48
+
49
+ cmd += " -N"
50
+
51
+ unless net.address.nil?
52
+ cmd += " address=#{net.address}"
53
+ end
54
+
55
+ unless net.interface.nil?
56
+ cmd += " interface=#{net.interface}"
57
+ end
58
+
59
+ unless net.mask_prefix.nil?
60
+ cmd += " netmask=#{net.mask_prefix}"
61
+ end
62
+
63
+ unless net.broadcast.nil?
64
+ cmd += " broadcast=#{net.interface}"
65
+ end
66
+ end
67
+
68
+ unless wpar.resource_control.empty?
69
+ cmd += " -R"
70
+ unless wpar.resource_control.cpu.nil?
71
+ cmd += " CPU=#{wpar.resource_control.cpu}"
72
+ end
73
+ unless wpar.resource_control.shares_cpu.nil?
74
+ cmd += " shares_CPU=#{wpar.resource_control.shares_cpu}"
75
+ end
76
+ unless wpar.resource_control.memory.nil?
77
+ cmd += " memory=#{wpar.resource_control.memory}"
78
+ end
79
+ unless wpar.resource_control.shares_memory.nil?
80
+ cmd += " shares_memory=#{wpar.resource_control.shares_memory}"
81
+ end
82
+ unless wpar.resource_control.rset.nil?
83
+ cmd += " rset=#{wpar.resource_control.rset}"
84
+ end
85
+ end
86
+
87
+ cmd
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,19 @@
1
+ require 'wpars/wrapper/constants'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ include Constants
6
+ class RmWpar
7
+ def self.destroy(options = {})
8
+ unless options[:force].nil?
9
+ cmd = "#{options[:command]} #{Constants::RMWPAR} -F #{options[:name]}"
10
+ else
11
+ cmd = "#{options[:command]} #{Constants::RMWPAR} #{options[:name]}"
12
+ end
13
+
14
+ puts "debug: #{cmd}" unless options[:debug].nil?
15
+ External.cmd(cmd: cmd, live_stream: options[:live_stream])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'wpars/wrapper/constants'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ include Constants
6
+ class StartWpar
7
+ def self.start(options = {})
8
+ cmd = "#{options[:command]} #{Constants::STARTWPAR} #{options[:name]}"
9
+
10
+ puts "debug: #{cmd}" unless options[:debug].nil?
11
+ External.cmd(cmd: cmd, live_stream: options[:live_stream])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'wpars/wrapper/constants'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ include Constants
6
+ class StopWpar
7
+ def self.stop(options = {})
8
+ unless options[:force].nil?
9
+ cmd = "#{options[:command]} #{Constants::STOPWPAR} -F #{options[:name]}"
10
+ else
11
+ cmd = "#{options[:command]} #{Constants::STOPWPAR} #{options[:name]}"
12
+ end
13
+
14
+ puts "debug: #{cmd}" unless options[:debug].nil?
15
+ External.cmd(cmd: cmd, live_stream: options[:live_stream])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'wpars/wrapper/constants'
2
+
3
+ module WPAR
4
+ module Wrapper
5
+ include Constants
6
+ class SyncWpar
7
+ def self.sync(options = {})
8
+ if options[:dir].nil?
9
+ cmd = "#{options[:command]} #{Constants::SYNCWPAR} -X #{options[:name]}"
10
+ else
11
+ cmd = "#{options[:command]} #{Constants::SYNCWPAR} -D -d #{options[:dir]} #{options[:name]}"
12
+ end
13
+
14
+ puts "debug: #{cmd}" unless options[:debug].nil?
15
+ External.cmd(cmd: cmd, live_stream: options[:live_stream])
16
+ end
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aix-wpar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alain Dejoux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-shellout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ description: A wrapper for the AIX WPAR administration.
28
+ email:
29
+ - adejoux@djouxtech.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - LICENSE
36
+ - README.md
37
+ - aix-wpar.gemspec
38
+ - examples/list_wpars.rb
39
+ - examples/manage_wpar.rb
40
+ - lib/wpars.rb
41
+ - lib/wpars/device.rb
42
+ - lib/wpars/external.rb
43
+ - lib/wpars/general.rb
44
+ - lib/wpars/mountpoint.rb
45
+ - lib/wpars/name.rb
46
+ - lib/wpars/network.rb
47
+ - lib/wpars/resource_control.rb
48
+ - lib/wpars/security.rb
49
+ - lib/wpars/version.rb
50
+ - lib/wpars/wpar.rb
51
+ - lib/wpars/wrapper/constants.rb
52
+ - lib/wpars/wrapper/converter.rb
53
+ - lib/wpars/wrapper/lswpar.rb
54
+ - lib/wpars/wrapper/lswpar_device.rb
55
+ - lib/wpars/wrapper/lswpar_general.rb
56
+ - lib/wpars/wrapper/lswpar_mountpoint.rb
57
+ - lib/wpars/wrapper/lswpar_network.rb
58
+ - lib/wpars/wrapper/lswpar_resource_control.rb
59
+ - lib/wpars/wrapper/lswpar_security.rb
60
+ - lib/wpars/wrapper/mkwpar.rb
61
+ - lib/wpars/wrapper/rmwpar.rb
62
+ - lib/wpars/wrapper/startwpar.rb
63
+ - lib/wpars/wrapper/stopwpar.rb
64
+ - lib/wpars/wrapper/syncwpar.rb
65
+ homepage: https://github.com/adejoux/ruby-aix-wpar
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.5.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A ruby library wrapper for the AIX WPAR administration.
89
+ test_files: []