knife-ovirt 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 649ae6404c8fa0028760464ee66e41983e580084
4
+ data.tar.gz: 6f53e3b1579a907e5891495344b1f53e615cacb0
5
+ SHA512:
6
+ metadata.gz: ea2b3ad8ca1bb3d774b9cce16f2ab5e4ab3467d7e7d802e11651dc194ac5f1b17e99647e6a95a9a3708e4d7aaf06913e655475f6c463c1e1f6c980e4f6de59f4
7
+ data.tar.gz: af5c5e95b504675666c31b105a0179d7dc392bbea80b3cf78d5a24bdbc51a50ed3c8cfa80b0c88838078477bb9eeb38260160ec8cd34db524c62619808017d87
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ .bundle
3
+ .rvmrc
4
+ Gemfile.lock
5
+ .autotest
6
+ coverage
7
+ .DS_Store
8
+ pkg
9
+ */tags
10
+
11
+ # RVM and RBENV ruby version files
12
+ .rbenv-version
13
+ .rvmrc
14
+ .ruby-version
15
+
16
+ /*.rb
17
+ .python-version
@@ -0,0 +1,13 @@
1
+ # See http://pre-commit.com for more information
2
+ # See http://pre-commit.com/hooks.html for more hooks
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ sha: v0.7.1
5
+ hooks:
6
+ - id: trailing-whitespace
7
+ - id: end-of-file-fixer
8
+ - id: check-yaml
9
+ - id: check-added-large-files
10
+ - repo: git://github.com/EMSL-MSC/pre-commit-hooks-chef
11
+ sha: 8e9ad15ee7430c7a52d5527d6b9cc5d0a158c974
12
+ hooks:
13
+ - id: check-cookstyle
@@ -0,0 +1,27 @@
1
+ # Change Log
2
+
3
+ ## [0.0.4](https://github.com/EMSL-MSC/knife-ovirt/tree/0.0.4) (2017-12-11)
4
+ [Full Changelog](https://github.com/EMSL-MSC/knife-ovirt/compare/0.0.3...0.0.4)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - need a new version for rubygems [\#3](https://github.com/EMSL-MSC/knife-ovirt/pull/3) ([karcaw](https://github.com/karcaw))
9
+
10
+ ## [0.0.3](https://github.com/EMSL-MSC/knife-ovirt/tree/0.0.3) (2017-12-09)
11
+ [Full Changelog](https://github.com/EMSL-MSC/knife-ovirt/compare/0.0.2...0.0.3)
12
+
13
+ **Merged pull requests:**
14
+
15
+ - Add memory and core options; cleanup code with pre-commit. [\#2](https://github.com/EMSL-MSC/knife-ovirt/pull/2) ([karcaw](https://github.com/karcaw))
16
+
17
+ ## [0.0.2](https://github.com/EMSL-MSC/knife-ovirt/tree/0.0.2) (2017-12-06)
18
+ [Full Changelog](https://github.com/EMSL-MSC/knife-ovirt/compare/0.0.1...0.0.2)
19
+
20
+ **Merged pull requests:**
21
+
22
+ - Updated README - few typos [\#1](https://github.com/EMSL-MSC/knife-ovirt/pull/1) ([mykaul](https://github.com/mykaul))
23
+
24
+ ## [0.0.1](https://github.com/EMSL-MSC/knife-ovirt/tree/0.0.1) (2017-07-26)
25
+
26
+
27
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in knife-ovirt.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright 2017 Battelle Memorial Institute
2
+
3
+ Redistribution and use in source and binary forms, with or without modification,
4
+ are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,126 @@
1
+ # Knife oVirt
2
+
3
+ ## Requirements
4
+ * fog
5
+ * rbovirt
6
+ * chef
7
+ * knife-cloud
8
+
9
+ ## Installation
10
+
11
+ Once you have [ChefDK](https://downloads.chef.io/chefdk) installed you can run:
12
+
13
+ `chef gem install knife-ovirt`
14
+
15
+ ## Configuration
16
+
17
+ You can set the authorization parameters for ovirt in your `knife.rb` file like this:
18
+
19
+ ```ruby
20
+ knife[:ovirt_username]="Your oVirt Username"
21
+ knife[:ovirt_url]="Your oVirt API URL"
22
+ knife[:ovirt_password]="Your OVirt Password"
23
+ ```
24
+ You can also specify these options on the command line as (`--ovirt-username`, `--ovirt-password`, `--ovirt-url`)
25
+
26
+ These parameters are required for all the commands below, and can be specified in a knife.rb config file or on the command line.
27
+
28
+ ## Commands
29
+
30
+ The plugin provides
31
+
32
+ ### `knife ovirt server list (options)`
33
+ List the Virtual Machines that are defined on the oVirt System.
34
+
35
+
36
+ ### `knife ovirt server create (options)`
37
+ Create a new server in the oVirt cluster based off an existing template. One of `--ovirt-template-name` or `--ovirt-template` is required.
38
+
39
+ * `--ovirt-cores <#>` specify the number of cores >=1 for the new VM
40
+
41
+ * `--ovirt-memory <name>` specify the amount of memory for the new VM in bytes
42
+
43
+ * `--ovirt-template <id>` specify a template ID to clone the new VM from
44
+
45
+ * `--ovirt-template-name <name>` specify the name of a template to clone the new VM from
46
+
47
+ * `--ovirt-volumes <list of hashes>` specify the volumes to create or attach to the new VM. for example to create a new volume and attach an existing one:
48
+ ```ruby
49
+ knife[:ovirt_volumes] = [
50
+ {
51
+ size_gb: 2,
52
+ domain_id: 'f7a25cf2-b2d4-43d3-8180-78f8f1c48b7d',
53
+ interface: 'virtio_scsi',
54
+ alias: 'testvol',
55
+ bootable: 'false'
56
+ },
57
+ {
58
+ id: 'd9e995f0-1c2d-4e9f-9cdf-4eb39b619d57',
59
+ interface: 'virtio_scsi',
60
+ }
61
+ ]
62
+ ```
63
+
64
+ * `--ovirt_cloud_init <cloud_init yaml>` specify a yaml string containing the cloud_init data needed to pass to the system. One method is to do it this way in a the knife.rb config:
65
+ ```ruby
66
+ knife[:ovirt_cloud_init] = {
67
+ ssh_authorized_keys: [File.read("#{ENV['HOME']}/.ssh/ovirt.pub")],
68
+ user: knife[:ssh_user],
69
+ ip: knife[:bootstrap_ip_address],
70
+ netmask: '255.255.255.0',
71
+ gateway: '192.168.1.1',
72
+ nicname: 'eth0',
73
+ dns: '192.168.1.1',
74
+ domain: 'example.com',
75
+ hostname: knife[:chef_node_name],
76
+ }.to_yaml
77
+ ```
78
+
79
+ ### `knife ovirt server delete VMID|VMNAME [VMID|VMNAME] (options)`
80
+
81
+ Delete a Virtual Machine or list of Virtual Machines
82
+
83
+ ### `knife ovirt storage list (options)`
84
+
85
+ List the storage domains that are currently defined on the oVirt System
86
+
87
+ ### `knife ovirt volume list (options)`
88
+
89
+ List the volumes that are currently defined on the oVirt System
90
+
91
+ ### `knife ovirt volume create (options)`
92
+
93
+ Create a new volume on the oVirt System
94
+ * `--vm-id <id>` Virtual Machine to attach the volume to
95
+
96
+ * `--volume-alias <alias>` alias for the volume
97
+
98
+ * `--volume-bootable <boolean>` should this volume be bootable
99
+
100
+ * `--volume-domain-id <id>` template to build server from
101
+
102
+ * `--volume-interface <interface>` interface type for volume
103
+
104
+ * `--volume-size <size>` Size of volume in Gigabytes
105
+
106
+ ## License
107
+
108
+ Author:: Evan Felix ([evan.felix@pnnl.gov](mailto:evan.felix@pnnl.gov))
109
+
110
+ Copyright:: Copyright 2017 Battelle Memorial Institute
111
+
112
+ License:: BSD-2
113
+
114
+ ## Disclaimer
115
+
116
+ This material was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any of their employees, nor any jurisdiction or organization that has cooperated in the development of these materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process disclosed, or represents that its use would not infringe privately owned rights.
117
+
118
+ Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or any agency thereof.
119
+
120
+ <center>
121
+ PACIFIC NORTHWEST NATIONAL LABORATORY<br>
122
+ operated by<br>
123
+ BATTELLE<br>
124
+ for the<br>
125
+ UNITED STATES DEPARTMENT OF ENERGY<br>
126
+ under Contract DE-AC05-76RL01830</center>
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'knife-ovirt'
7
+ s.version = '0.0.5'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
11
+ s.authors = ['Evan Felix']
12
+ s.email = ['evan.felix@pnnl.gov']
13
+ s.homepage = 'https://github.com/EMSL-MSC/knife-ovirt'
14
+ s.summary = "A Chef knife plugin for Ovirt VM's."
15
+ s.description = "A Chef knife plugin for Ovirt VM's."
16
+ s.license = 'BSD-2'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+
23
+ s.required_ruby_version = '>= 2.2.2'
24
+
25
+ s.add_dependency 'fog-ovirt', '~> 1.0'
26
+ s.add_dependency 'chef', '~> 12'
27
+ s.add_dependency 'knife-cloud', '~> 1.2'
28
+ s.add_dependency 'rbovirt', '~> 0.1.3'
29
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/server/create_options'
8
+
9
+ class Chef
10
+ class Knife
11
+ class Cloud
12
+ module OvirtServerCreateOptions
13
+ def self.included(includer)
14
+ includer.class_eval do
15
+ include ServerCreateOptions
16
+
17
+ # Ovirt Server create params.
18
+ option :ovirt_volumes,
19
+ long: '--ovirt-volumes <list of hashes>',
20
+ description: 'List of Volumes to use,',
21
+ boolean: false,
22
+ default: []
23
+
24
+ option :ovirt_template,
25
+ long: '--ovirt-template <id>',
26
+ description: 'template to build server from',
27
+ boolean: false,
28
+ default: nil
29
+
30
+ option :ovirt_template_name,
31
+ long: '--ovirt-template-name <name>',
32
+ description: 'template to build server from',
33
+ boolean: false,
34
+ default: nil
35
+
36
+ option :ovirt_cloud_init,
37
+ long: '--ovirt-cloud-init CLOUD_INIT_DATA',
38
+ description: 'Your Ovirt cloud_init data',
39
+ proc: proc { |cloud_init| Chef::Config[:knife][:ovirt_cloud_init] = cloud_init }
40
+
41
+ option :ovirt_memory,
42
+ long: '--ovirt-memory <size>',
43
+ description: 'VM Memory Size in Bytes',
44
+ boolean: false,
45
+ default: nil
46
+
47
+ option :ovirt_cores,
48
+ long: '--ovirt-cores <#>',
49
+ description: 'VM Core Count',
50
+ boolean: false,
51
+ default: nil
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,91 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/fog/service'
8
+
9
+ class Chef
10
+ class Knife
11
+ class Cloud
12
+ class OvirtService < FogService
13
+ def initialize(options = {})
14
+ Chef::Log.debug("ovirt_username #{Chef::Config[:knife][:ovirt_username]}")
15
+
16
+ super(options.merge(auth_params: {
17
+ provider: 'ovirt',
18
+ ovirt_username: Chef::Config[:knife][:ovirt_username],
19
+ ovirt_password: Chef::Config[:knife][:ovirt_password],
20
+ ovirt_url: Chef::Config[:knife][:ovirt_url],
21
+ }))
22
+ end
23
+
24
+ def add_api_endpoint
25
+ @auth_params.merge!(ovirt_url: Chef::Config[:knife][:api_endpoint]) unless Chef::Config[:knife][:api_endpoint].nil?
26
+ end
27
+
28
+ # originally lifted from knife-cloud/lib/chef/knife/cloud/fog/service.rb
29
+ def create_server(options = {})
30
+ begin
31
+ add_custom_attributes(options[:server_def])
32
+ server = connection.servers.create(options[:server_def])
33
+
34
+ print "\nWaiting For Server"
35
+ server.wait_for(Integer(options[:server_create_timeout])) do
36
+ print '.'
37
+ !locked?
38
+ end
39
+
40
+ # attach/or create any volumes.
41
+ options[:server_volumes].each do |voldef|
42
+ Chef::Log.debug("Volume definition: #{voldef}")
43
+ if voldef.key?(:size) || voldef.key?(:size_gb)
44
+ # create a new volume
45
+ result = connection.add_volume(server.id, voldef)
46
+ name = (result / 'disk/name').first.text
47
+ elsif voldef.key? :id
48
+ server.attach_volume(voldef)
49
+ name = voldef[:id]
50
+ else
51
+ raise CloudExceptions::ServerCreateError, "cannot handle volume definition #{voldef}"
52
+ end
53
+
54
+ print "\nAttached #{name} volume"
55
+ end
56
+
57
+ print "\nWaiting For Volumes"
58
+ server.wait_for(Integer(options[:server_create_timeout])) do
59
+ print '.'
60
+ !locked?
61
+ end
62
+ Chef::Log.debug("options: #{options}")
63
+ server.start_with_cloudinit(user_data: options[:cloud_init])
64
+ rescue Excon::Error::BadRequest => e
65
+ response = Chef::JSONCompat.from_json(e.response.body)
66
+ message = if response['badRequest']['code'] == 400
67
+ "Bad request (400): #{response['badRequest']['message']}"
68
+ else
69
+ "Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}"
70
+ end
71
+ ui.fatal(message)
72
+ raise CloudExceptions::ServerCreateError, message
73
+ rescue Fog::Errors::Error => e
74
+ raise CloudExceptions::ServerCreateError, e.message
75
+ end
76
+
77
+ print "\n#{ui.color("Waiting for server [wait time = #{options[:server_create_timeout]}]", :magenta)}"
78
+
79
+ # wait for it to be ready to do stuff
80
+ server.wait_for(Integer(options[:server_create_timeout])) do
81
+ print '.'
82
+ ready?
83
+ end
84
+
85
+ puts("\n")
86
+ server
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/fog/options'
8
+ class Chef
9
+ class Knife
10
+ class Cloud
11
+ module OvirtServiceOptions
12
+ def self.included(includer)
13
+ includer.class_eval do
14
+ include FogOptions
15
+ # Ovirt Connection params.
16
+ option :ovirt_username,
17
+ short: '-A USERNAME',
18
+ long: '--ovirt-username KEY',
19
+ description: 'Your Ovirt Username',
20
+ proc: proc { |key| Chef::Config[:knife][:ovirt_username] = key }
21
+
22
+ option :ovirt_password,
23
+ short: '-K SECRET',
24
+ long: '--ovirt-password SECRET',
25
+ description: 'Your Ovirt Password',
26
+ proc: proc { |key| Chef::Config[:knife][:ovirt_password] = key }
27
+
28
+ option :ovirt_url,
29
+ long: '--ovirt-url URL',
30
+ description: 'Your Ovirt URL',
31
+ proc: proc { |url| Chef::Config[:knife][:ovirt_url] = url }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ class Chef
8
+ class Knife
9
+ class Cloud
10
+ module OvirtVolumeCreateOptions
11
+ def self.included(includer)
12
+ includer.class_eval do
13
+ # Ovirt Volume create params.
14
+ option :vm_id,
15
+ long: '--vm-id <id>',
16
+ description: 'Virtual Machine to attach the volume to',
17
+ boolean: false,
18
+ default: nil
19
+
20
+ option :volume_size,
21
+ long: '--volume-size <size>',
22
+ description: 'Size of volume in Gigabytes',
23
+ boolean: false,
24
+ default: nil
25
+
26
+ option :volume_domain_id,
27
+ long: '--volume-domain-id <id>',
28
+ description: 'template to build server from',
29
+ boolean: false,
30
+ default: nil
31
+
32
+ option :volume_interface,
33
+ long: '--volume-interface <interface>',
34
+ description: 'interface type for volume',
35
+ boolean: false,
36
+ default: 'virtio'
37
+
38
+ option :volume_bootable,
39
+ long: '--volume-bootable <boolean>',
40
+ description: 'should this volume be bootable',
41
+ boolean: false,
42
+ default: 'false'
43
+
44
+ option :volume_alias,
45
+ long: '--volume-alias <alias>',
46
+ description: 'alias for the volume',
47
+ boolean: false,
48
+ default: nil
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/ovirt_service'
8
+
9
+ class Chef
10
+ class Knife
11
+ class Cloud
12
+ module OvirtHelpers
13
+ def create_service_instance
14
+ OvirtService.new
15
+ end
16
+
17
+ def validate!
18
+ super(:ovirt_username, :ovirt_password, :ovirt_url)
19
+ end
20
+
21
+ def humanize(bytes)
22
+ b = bytes.to_i
23
+ suf = %w(B KiB MiB GiB TiB EiB)
24
+ c = suf[0]
25
+ 6.times do |count|
26
+ if b < 1024
27
+ c = suf[count]
28
+ break
29
+ end
30
+ b /= 1024.0
31
+ end
32
+ format('%.2f ', b) + c
33
+ end
34
+
35
+ def volume_ready(vm_id, vol_id)
36
+ # find the volume and chaeck its status
37
+ service.connection.list_vm_volumes(vm_id).select do |vol|
38
+ vol[:id] == vol_id
39
+ end[0][:status] == 'ok'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/server/create_command'
8
+ require 'chef/knife/ovirt_helpers'
9
+ require 'chef/knife/cloud/ovirt_server_create_options'
10
+ require 'chef/knife/cloud/ovirt_service'
11
+ require 'chef/knife/cloud/ovirt_service_options'
12
+ require 'chef/knife/cloud/exceptions'
13
+
14
+ class Chef
15
+ class Knife
16
+ class Cloud
17
+ class OvirtServerCreate < ServerCreateCommand
18
+ include OvirtHelpers
19
+ include OvirtServerCreateOptions
20
+ include OvirtServiceOptions
21
+
22
+ banner 'knife ovirt server create (options)'
23
+
24
+ def before_exec_command
25
+ super
26
+ # setup the create options
27
+ @create_options = {
28
+ server_def: {
29
+ name: config[:chef_node_name],
30
+ os: { boot: ['hd'] },
31
+ },
32
+ cloud_init: config[:ovirt_cloud_init],
33
+ server_create_timeout: locate_config_value(:server_create_timeout),
34
+ }
35
+ @create_options[:server_def][:template] = config[:ovirt_template] if config[:ovirt_template]
36
+ @create_options[:server_def][:template_name] = config[:ovirt_template_name] if config[:ovirt_template_name]
37
+ @create_options[:server_def][:memory] = config[:ovirt_memory] if config[:ovirt_memory]
38
+ @create_options[:server_def][:cores] = config[:ovirt_cores] if config[:ovirt_cores]
39
+
40
+ @create_options[:server_volumes] = config[:ovirt_volumes] if config[:ovirt_volumes]
41
+
42
+ @columns_with_info = [
43
+ { label: 'VM ID', key: 'id' },
44
+ { label: 'Name', key: 'name' },
45
+ { label: 'Cores', key: 'cores' },
46
+ { label: 'Memory', key: 'memory', value_callback: method(:humanize) },
47
+ { label: 'Storage', key: 'storage', value_callback: method(:humanize) },
48
+ { label: 'Status', key: 'status' },
49
+ ]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/server/delete_options'
8
+ require 'chef/knife/cloud/server/delete_command'
9
+ require 'chef/knife/cloud/ovirt_service'
10
+ require 'chef/knife/cloud/ovirt_service_options'
11
+ require 'chef/knife/ovirt_helpers'
12
+
13
+ class Chef
14
+ class Knife
15
+ class Cloud
16
+ class OvirtServerDelete < ServerDeleteCommand
17
+ include ServerDeleteOptions
18
+ include OvirtServiceOptions
19
+ include OvirtHelpers
20
+
21
+ banner 'knife ovirt server delete VMID|VMNAME [VMID|VMNAME] (options)'
22
+ def execute_command
23
+ @name_args.each do |server_name|
24
+ service.delete_server(map_name(server_name))
25
+ delete_from_chef(server_name)
26
+ end
27
+ end
28
+
29
+ # map vm names to ID's so they get deleted
30
+ def map_name(server_name)
31
+ servers = @service.list_servers
32
+ snames = servers.map(&:name)
33
+ names = []
34
+ @name_args.each do |name|
35
+ if snames.include? name
36
+ servers.each do |server|
37
+ names << server.id if server.name == name
38
+ end
39
+ else
40
+ names << name
41
+ end
42
+ end
43
+ if names.length != 1
44
+ raise CloudExceptions::ServerDeleteError, "Too many ID's for #{server_name} => #{names}"
45
+ end
46
+ names[0]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/server/list_command'
8
+ require 'chef/knife/ovirt_helpers'
9
+ require 'chef/knife/cloud/ovirt_service_options'
10
+ require 'chef/knife/cloud/server/list_options'
11
+
12
+ require 'fog'
13
+
14
+ class Chef
15
+ class Knife
16
+ class Cloud
17
+ class OvirtServerList < ServerListCommand
18
+ include OvirtHelpers
19
+ include OvirtServiceOptions
20
+ include ServerListOptions
21
+
22
+ banner 'knife ovirt server list (options)'
23
+
24
+ def before_exec_command
25
+ @columns_with_info = [
26
+ { label: 'VM ID', key: 'id' },
27
+ { label: 'Name', key: 'name' },
28
+ { label: 'Cores', key: 'cores' },
29
+ { label: 'Memory', key: 'memory', value_callback: method(:humanize) },
30
+ { label: 'Storage', key: 'storage', value_callback: method(:humanize) },
31
+ { label: 'Status', key: 'status' },
32
+ ]
33
+ super
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/list_resource_command'
8
+ require 'chef/knife/ovirt_helpers'
9
+ require 'chef/knife/cloud/ovirt_service_options'
10
+
11
+ class Chef
12
+ class Knife
13
+ class Cloud
14
+ class OvirtStorageList < ResourceListCommand
15
+ include OvirtHelpers
16
+ include OvirtServiceOptions
17
+
18
+ banner 'knife ovirt storage list (options)'
19
+
20
+ def query_resource
21
+ @service.connection.storage_domains
22
+ rescue Excon::Errors::BadRequest => e
23
+ response = Chef::JSONCompat.from_json(e.response.body)
24
+ ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
25
+ raise e
26
+ end
27
+
28
+ def storage_domain_name(id)
29
+ @storage_domains.select do |domain|
30
+ puts domain
31
+ domain.id == id
32
+ end[0].name
33
+ end
34
+
35
+ def list(storages)
36
+ storage_list = [
37
+ ui.color('ID', :bold),
38
+ ui.color('Name', :bold),
39
+ ui.color('Used', :bold),
40
+ ui.color('Avail', :bold),
41
+ ui.color('%Used', :bold),
42
+ ui.color('Kind', :bold),
43
+ ui.color('Role', :bold),
44
+ ]
45
+ begin
46
+ storages.each do |storage|
47
+ storage_list << storage.id
48
+ storage_list << storage.name
49
+ storage_list << humanize((storage.used || 0))
50
+ storage_list << humanize(storage.available)
51
+ storage_list << format('%02.1f ', 100 * (storage.used || 0).to_i / (storage.available || 1).to_i)
52
+ storage_list << storage.kind
53
+ storage_list << storage.role
54
+ # There is a description field too, but it doesent seem to be available through fog.
55
+ end
56
+ rescue Excon::Errors::BadRequest => e
57
+ response = Chef::JSONCompat.from_json(e.response.body)
58
+ ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
59
+ raise e
60
+ end
61
+ puts ui.list(storage_list, :uneven_columns_across, 7)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/server/create_command'
8
+ require 'chef/knife/ovirt_helpers'
9
+ require 'chef/knife/cloud/ovirt_service'
10
+ require 'chef/knife/cloud/command'
11
+ require 'chef/knife/cloud/ovirt_service_options'
12
+ require 'chef/knife/cloud/ovirt_volume_create_options'
13
+ require 'chef/knife/cloud/exceptions'
14
+ require 'pry'
15
+
16
+ class Chef
17
+ class Knife
18
+ class Cloud
19
+ class OvirtVolumeCreate < Command
20
+ include OvirtHelpers
21
+ include OvirtVolumeCreateOptions
22
+ include OvirtServiceOptions
23
+
24
+ banner 'knife ovirt volume create (options)'
25
+
26
+ def before_exec_command
27
+ super
28
+ # setup the create options
29
+ @create_options = {
30
+ size_gb: locate_config_value('volume_size'),
31
+ active: 'true',
32
+ }
33
+ [:storage_domain, :interface, :bootable, :alias].each do |opt|
34
+ @create_options[opt] = locate_config_value("volume_#{opt}") if locate_config_value("volume_#{opt}")
35
+ end
36
+ # binding.pry
37
+ @columns_with_info = [
38
+ { label: 'Name', key: 'name' },
39
+ { label: 'Status', key: 'status' },
40
+ ]
41
+ end
42
+
43
+ def execute_command
44
+ result = service.connection.add_volume(locate_config_value(:vm_id), @create_options)
45
+ name = (result / 'disk/name').first.text
46
+ id = (result / 'disk').first['id']
47
+
48
+ print "\nWaiting For Volume(#{name}) to become available"
49
+ Fog.wait_for(120) do
50
+ print '.'
51
+ volume_ready(locate_config_value(:vm_id), id)
52
+ end
53
+ print "\nActivating Volume"
54
+ service.connection.activate_volume(locate_config_value(:vm_id), id: id)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright (C) 2017 Battelle Memorial Institute
2
+ # All rights reserved.
3
+ #
4
+ # This software may be modified and distributed under the terms
5
+ # of the BSD-2 license. See the LICENSE file for details.
6
+ # frozen_string_literal: true
7
+ require 'chef/knife/cloud/list_resource_command'
8
+ require 'chef/knife/ovirt_helpers'
9
+ require 'chef/knife/cloud/ovirt_service_options'
10
+
11
+ class Chef
12
+ class Knife
13
+ class Cloud
14
+ class OvirtVolumeList < ResourceListCommand
15
+ include OvirtHelpers
16
+ include OvirtServiceOptions
17
+
18
+ banner 'knife ovirt volume list (options)'
19
+
20
+ def query_resource
21
+ @storage_domains = @service.connection.storage_domains
22
+ @service.connection.list_volumes
23
+ rescue Excon::Errors::BadRequest => e
24
+ response = Chef::JSONCompat.from_json(e.response.body)
25
+ ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
26
+ raise e
27
+ end
28
+
29
+ def storage_domain_name(id)
30
+ @storage_domains.select { |domain| domain.id == id }[0].name
31
+ end
32
+
33
+ def list(volumes)
34
+ volume_list = [
35
+ ui.color('ID', :bold),
36
+ ui.color('Name', :bold),
37
+ ui.color('Size', :bold),
38
+ ui.color('Status', :bold),
39
+ ui.color('Sparse', :bold),
40
+ ui.color('Format', :bold),
41
+ ui.color('Domain', :bold),
42
+ ]
43
+ begin
44
+ volumes.each do |volume|
45
+ volume_list << volume[:id]
46
+ volume_list << volume[:name]
47
+ volume_list << humanize(volume[:size])
48
+ volume_list << volume[:status]
49
+ volume_list << volume[:sparse]
50
+ volume_list << volume[:format]
51
+ volume_list << storage_domain_name(volume[:storage_domain])
52
+ # There is a description field too, but it doesent seem to be available through fog.
53
+ end
54
+ rescue Excon::Errors::BadRequest => e
55
+ response = Chef::JSONCompat.from_json(e.response.body)
56
+ ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
57
+ raise e
58
+ end
59
+ puts ui.list(volume_list, :uneven_columns_across, 7)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-ovirt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Evan Felix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog-ovirt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: knife-cloud
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rbovirt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.3
69
+ description: A Chef knife plugin for Ovirt VM's.
70
+ email:
71
+ - evan.felix@pnnl.gov
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.md
76
+ - LICENSE
77
+ files:
78
+ - ".gitignore"
79
+ - ".license.header.rb"
80
+ - ".pre-commit-config.yaml"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - knife-ovirt.gemspec
86
+ - lib/chef/knife/cloud/ovirt_server_create_options.rb
87
+ - lib/chef/knife/cloud/ovirt_service.rb
88
+ - lib/chef/knife/cloud/ovirt_service_options.rb
89
+ - lib/chef/knife/cloud/ovirt_volume_create_options.rb
90
+ - lib/chef/knife/ovirt_helpers.rb
91
+ - lib/chef/knife/ovirt_server_create.rb
92
+ - lib/chef/knife/ovirt_server_delete.rb
93
+ - lib/chef/knife/ovirt_server_list.rb
94
+ - lib/chef/knife/ovirt_storage_list.rb
95
+ - lib/chef/knife/ovirt_volume_create.rb
96
+ - lib/chef/knife/ovirt_volume_list.rb
97
+ homepage: https://github.com/EMSL-MSC/knife-ovirt
98
+ licenses:
99
+ - BSD-2
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.2.2
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.11
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A Chef knife plugin for Ovirt VM's.
121
+ test_files: []