knife-proxmox 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+
4
+ class Chef
5
+ class Knife
6
+ class ProxmoxServerDestroy < Knife
7
+ include Knife::ProxmoxBase
8
+
9
+ banner "knife proxmox server destroy (options)"
10
+
11
+ # Options for this action
12
+ option :purge,
13
+ :short => "-P",
14
+ :long => "--purge",
15
+ :boolean => true,
16
+ :default => false,
17
+ :description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the Rackspace node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
18
+
19
+ option :chef_node_name,
20
+ :short => "-H hostname",
21
+ :long => "--hostname hostname",
22
+ :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
23
+
24
+ option :vm_id,
25
+ :short => "-I number",
26
+ :long => "--vmid number",
27
+ :description => "The numeric identifier of the VM"
28
+
29
+ def run
30
+ # Needed
31
+ connection
32
+
33
+ #TODO: must detect which parameter has been used: name or vmid
34
+ vm_id = nil
35
+ if (config[:vm_id].nil? and config[:chef_node_name].nil?) then
36
+ ui.error("You must use -I <id> or -H <Hostname>")
37
+ exit 1
38
+ elsif (!config[:chef_node_name].nil?)
39
+ name = config[:chef_node_name]
40
+ puts "Server to destroy: #{name}"
41
+ vm_id = server_name_to_vmid(name)
42
+ else
43
+ vm_id = config[:vm_id]
44
+ end
45
+
46
+ server_stop(vm_id)
47
+ ui.msg("Preparing the server to delete")
48
+ sleep(5)
49
+ server_destroy(vm_id)
50
+
51
+ #TODO: remove server from chef
52
+ if config[:purge]
53
+ thing_to_delete = config[:chef_node_name] || server_get_data(config[:vm_id],"name")
54
+ destroy_item(Chef::Node, thing_to_delete, "node")
55
+ destroy_item(Chef::ApiClient, thing_to_delete, "client")
56
+ else
57
+ ui.warn("Corresponding node and client for the #{vm_id} server were not deleted and remain registered with the Chef Server")
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,43 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+
4
+ class Chef
5
+ class Knife
6
+ class ProxmoxServerList < Knife
7
+
8
+ include Knife::ProxmoxBase
9
+
10
+ banner "knife proxmox server list (options)"
11
+
12
+ def run
13
+ # Needed
14
+ connection
15
+
16
+ server_list = [
17
+ ui.color('Id' , :bold),
18
+ ui.color('Node', :bold),
19
+ ui.color('Name', :bold),
20
+ ui.color('Type', :bold),
21
+ ui.color('Status',:bold),
22
+ ui.color('IP Address',:bold)
23
+
24
+ ]
25
+ @connection['cluster/resources?type=vm'].get @auth_params do |response, request, result, &block|
26
+ JSON.parse(response.body)['data'].each {|entry|
27
+ vm_id = entry['vmid']
28
+ type = entry['type']
29
+ server_list << vm_id.to_s
30
+ server_list << entry['node']
31
+ server_list << entry['name']
32
+ server_list << type
33
+ status = (entry['uptime'] == 0)?'down':'up'
34
+ server_list << status
35
+ ipaddress = (type.to_s.match('openvz'))?server_get_data(vm_id,'ip'):"Not Available"
36
+ server_list << ipaddress
37
+ }
38
+ end
39
+ puts ui.list(server_list, :uneven_columns_across, 6)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+
4
+ class Chef
5
+ class Knife
6
+ class ProxmoxServerStart < Knife
7
+
8
+ include Knife::ProxmoxBase
9
+
10
+ banner "knife proxmox server start (options)"
11
+
12
+ option :vm_id,
13
+ :short => "-I number",
14
+ :long => "--vmid number",
15
+ :description => "The numeric identifier of the VM"
16
+
17
+ def run
18
+ # Needed
19
+ connection
20
+
21
+ check_config_parameter(:vm_id)
22
+
23
+ server_start(config[:vm_id])
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+
4
+ class Chef
5
+ class Knife
6
+ class ProxmoxServerStop < Knife
7
+
8
+ include Knife::ProxmoxBase
9
+
10
+ banner "knife proxmox server start (options)"
11
+
12
+ option :vm_id,
13
+ :short => "-I number",
14
+ :long => "--vmid number",
15
+ :description => "The numeric identifier of the VM"
16
+
17
+ def run
18
+ # Needed
19
+ connection
20
+
21
+ check_config_parameter(:vm_id)
22
+
23
+ server_stop(config[:vm_id])
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProxmoxTemplateAvailable < Knife
6
+
7
+ include Knife::ProxmoxBase
8
+
9
+ banner "knife proxmox template available (options)"
10
+
11
+ def run
12
+ # Needed
13
+ connection
14
+
15
+ template_list = [
16
+ ui.color('Name', :bold),
17
+ ui.color('Operating System', :bold)
18
+ ]
19
+
20
+ @connection["nodes/#{Chef::Config[:knife][:pve_node_name]}/aplinfo"].get @auth_params do |response, request, result, &block|
21
+ JSON.parse(response.body)['data'].each { |entry|
22
+ template_list << entry['template'].strip
23
+ template_list << entry['os'].strip
24
+ }
25
+ end
26
+
27
+ puts ui.list(template_list, :uneven_columns_across, 2)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'chef/knife/proxmox_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProxmoxTemplateList < Knife
6
+
7
+ include Knife::ProxmoxBase
8
+
9
+ banner "knife proxmox template list (options)"
10
+
11
+ def run
12
+ # Needed to initialize @connection and @auth_params
13
+ connection
14
+
15
+ template_list = [
16
+ ui.color('Id' , :bold),
17
+ ui.color('Name', :bold),
18
+ ui.color('Size', :bold)
19
+ ]
20
+
21
+ @connection["nodes/#{Chef::Config[:knife][:pve_node_name]}/storage/local/content"].get @auth_params do |response, request, result, &block|
22
+ template_index = 0
23
+ JSON.parse(response.body)['data'].each { |entry|
24
+ if entry['content'] == 'vztmpl' then
25
+ template_list << template_index.to_s
26
+ template_list << entry['volid']
27
+ template_list << (entry['size'].to_i/1048576).to_s + " MB"
28
+ template_index+=1
29
+ end
30
+ }
31
+ end
32
+ puts ui.list(template_list, :uneven_columns_across, 3)
33
+ end
34
+ end
35
+ end
36
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module Proxmox
3
+ VERSION = "0.0.12"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-proxmox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.12
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Moratilla
9
+ - Sergio Galvan
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-28 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: chef
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.10.10
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.10.10
31
+ - !ruby/object:Gem::Dependency
32
+ name: rest-client
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.6.7
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.6.7
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.4
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 1.5.4
63
+ description: ProxmoxVE Support for Chef's Knife Command
64
+ email:
65
+ - jorge@moratilla.com
66
+ - sergalma@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files:
70
+ - README
71
+ - LICENSE
72
+ - TODO
73
+ - CHANGELOG
74
+ files:
75
+ - lib/chef/knife/proxmox_server_destroy.rb
76
+ - lib/chef/knife/server.rb
77
+ - lib/chef/knife/proxmox_server_stop.rb
78
+ - lib/chef/knife/proxmox_base.rb
79
+ - lib/chef/knife/proxmox_template_list.rb
80
+ - lib/chef/knife/proxmox_server_start.rb
81
+ - lib/chef/knife/proxmox_server_create.rb
82
+ - lib/chef/knife/template.rb
83
+ - lib/chef/knife/proxmox_template_available.rb
84
+ - lib/chef/knife/connection.rb
85
+ - lib/chef/knife/proxmox_server_list.rb
86
+ - lib/knife-proxmox/version.rb
87
+ - ./Gemfile.lock
88
+ - ./knife-proxmox-0.0.11.gem
89
+ - ./knife-proxmox.gemspec
90
+ - ./Gemfile
91
+ - ./CHANGELOG
92
+ - ./LICENSE
93
+ - ./README
94
+ - ./TODO
95
+ - README
96
+ - LICENSE
97
+ - TODO
98
+ - CHANGELOG
99
+ homepage: http://wiki.opscode.com/display/chef
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: ProxmoxVE Support for Chef's Knife Command
123
+ test_files: []
124
+ has_rdoc: false