项目作者: jmoratilla

项目描述 :
A chef knife plugin to manage Proxmox using API
高级语言: Perl
项目地址: git://github.com/jmoratilla/knife-proxmox.git
创建时间: 2020-05-01T17:42:29Z
项目社区:https://github.com/jmoratilla/knife-proxmox

开源协议:Apache License 2.0

下载


Chef::Knife::Proxmox

Authors: Jorge Moratilla, Sergio Galvan
Date: 2012-10-07

Gem Version

Description

This knife plugin allows to access Proxmox Virtualization Environment (Proxmox VE or PVE) through its API.
It allows you to lists templates installed on the server/cluster (like images or amis), create a server or
destroy it.

Currently it only supports management of openVZ instances, but KVM instances will be able in a future.

Requirements

  • zlib (zlib1g-dev)
  • openssl (libopenssl-ruby, libssl-dev)

Then install your ruby language (recommended ruby-1.9.3-xxx)

(See installation instructions beneath)

Actions implemented

  • proxmox server list
  • proxmox server info
  • proxmox server create
  • proxmox server start
  • proxmox server stop
  • proxmox server destroy
  • proxmox template available
  • proxmox template list

Some Examples

List servers

  1. $ knife proxmox server list
  2. Id Node Name Type Status
  3. 102 node-1 test qemu down
  4. 104 node-1 tetatet.example.com openvz down
  5. 202 node-2 chef-client1 openvz down
  6. 470 node-2 sg-node1.example.com openvz up

Get info for a server

  1. $ knife proxmox server info -H tetatet.example.com -P ip
  2. 192.168.1.1
  3. $ knife proxmox server info -H tetatet.example.com
  4. knife proxmox server info -H tetatet.example.com -P ip
  5. cpu: 0.00281876923420022
  6. cpus: 2
  7. disk: 5833015296
  8. diskread: 316895232
  9. diskwrite: 3805184
  10. failcnt: 0
  11. ha: 0
  12. ip: 192.168.42.200
  13. maxdisk: 8589934592
  14. maxmem: 4294967296
  15. maxswap: 536870912
  16. mem: 1145778176
  17. name: tetatet.example.com
  18. netin: 27888604
  19. netout: 2829601
  20. nproc: 140
  21. status: running
  22. swap: 54460416
  23. type: openvz
  24. uptime: 61018

List templates installed

  1. $ knife proxmox template list -U https://localhost:8006/api2/json/ -n localhost -u test -p test123 -R pve -VV
  2. DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
  3. Id Name Size
  4. 0 local:vztmpl/debian-6.0-request-tracker_3.8.8-2_i386.tar.gz 171 MB
  5. 1 local:vztmpl/old_ubuntu-11.10-x86_64.tar.gz 124 MB
  6. 2 local:vztmpl/ubuntu-10.04-standard_10.04-4_i386.tar.gz 135 MB
  7. 3 local:vztmpl/ubuntu-11.10-x86_64-jorge1-.tar.gz 124 MB
  8. 4 local:vztmpl/ubuntu-11.10-x86_64-jorge2-.tar.gz 154 MB

List templates available to download

  1. $ knife proxmox template available -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -VV
  2. DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
  3. Name Operating System
  4. debian-6-turnkey-concrete5_12.0-1_i386.tar.gz debian-6
  5. ubuntu-10.04-turnkey-prestashop_11.3-1_i386.tar.gz ubuntu-10.04
  6. debian-6-turnkey-joomla25_12.0-1_i386.tar.gz debian-6
  7. debian-6-turnkey-tomcat-apache_12.0-1_i386.tar.gz debian-6
  8. debian-6.0-wordpress_3.4.2-1_i386.tar.gz debian-6.0 .....

Create a server (read the note at the end of the document. It’s about obtaining the IPAddress)

  1. $ knife proxmox server create -n ankh -r "recipe[java]" -C 2 -M 1024 -H example-server -P test123 -T 4
  2. Creating VM 473...
  3. ..............OK
  4. Preparing the server to start
  5. Starting VM 473 on node ankh....
  6. ..OK
  7. New Server 473 has IP Address: 10.0.2.19
  8. done
  9. Bootstrapping Chef on 10.0.2.19
  10. 10.0.2.19 --2013-01-23 01:27:20-- http://opscode.com/chef/install.sh
  11. 10.0.2.19 Resolving opscode.com...
  12. 10.0.2.19 184.106.28.83
  13. 10.0.2.19 Connecting to opscode.com|184.106.28.83|:80...
  14. 10.0.2.19 connected.
  15. 10.0.2.19 HTTP request sent, awaiting response...
  16. 10.0.2.19 301 Moved Permanently
  17. 10.0.2.19 Location: http://www.opscode.com/chef/install.sh [following]
  18. 10.0.2.19 --2013-01-23 01:27:21-- http://www.opscode.com/chef/install.sh
  19. 10.0.2.19 Resolving www.opscode.com...
  20. 10.0.2.19 184.106.28.83
  21. 10.0.2.19 Reusing existing connection to opscode.com:80.
  22. 10.0.2.19 HTTP request sent, awaiting response...
  23. 10.0.2.19 200 OK

Starting a server

  1. $ knife proxmox server start --vmid 401
  2. Starting VM 401....
  3. Result: 200

Stopping a server

  1. $ knife proxmox server stop --vmid 103
  2. Stoping VM 103....
  3. Result: 200

Destroy a server

  1. $ knife proxmox server destroy -U https://localhost:8006/api2/json/ -u test -p test123 -n localhost -R pve -N vm-node1 -VV -P
  2. DEBUG: Using configuration from /home/jorge/workspace/chef-repo/.chef/knife.rb
  3. node to destroy: vm-node1 [vmid: 200]
  4. Continue? (Y/N) y
  5. Stopping VM 303....
  6. Result: 200
  7. ..............................
  8. Result: 200
  9. WARNING: Deleted node vm-node1
  10. WARNING: Deleted client vm-node1

Installation

This gem must be installed on your system using the command

  1. $ gem install knife-proxmox

If you want to read values from the environment variables modify your knife.rb:

  1. knife[:pve_cluster_url] ||= "#{ENV['PVE_CLUSTER_URL']}"
  2. knife[:pve_user_name] ||= "#{ENV['PVE_USER_NAME']}"
  3. knife[:pve_node_name] ||= "#{ENV['PVE_NODE_NAME']}"
  4. knife[:pve_user_realm] ||= "#{ENV['PVE_USER_REALM']}"

However I don’t recommend to have the user password as a environment variable.
knife[:pve_user_password] = “#{ENV[‘PVE_CLUSTER_URL’]}”

Environment Variables

  1. PVE_CLUSTER_URL = https://<proxmox_server>:8006/api2/json/
  2. PVE_USER_NAME = <user>
  3. PVE_PASSWORD_NAME = <password>
  4. PVE_USER_REALM = <pam|pve|others>
  5. PVE_NODE_NAME = <nodename>

If you want to alter some variable by command line then you can use the following options:
-n —node If in a cluster, this argument will specify which node of the cluster will do the action
-U —pve_cluster_url http://localhost... Will change the cluster to access to
-u —username Same for user
-p —password Same for password
-r —realm Same for the realm used to authenticate

There is a script in extra/set_environment_variables.sh that creates the
set of variables needed for knife-proxmox. Just answer the questions and
paste the output into your profile file.

ABOUT CHEF AND PROXMOX

To bootstrap a newly created VM, you should apply the patch inside the extra directory. Otherwise you must
specify the IP address in the knife proxmox server create —ipaddress argument.