Code Monkey home page Code Monkey logo

knife-xapi's Introduction

Knife Xapi

This plugin gives knife the ability to create guests on a XAPI compatable hyper visor

Installation

This plugin is distributed as a Ruby Gem. To install it, run:

gem install knife-xapi

Configuration

Config options are extendable in the knife.rb the folowing config options can be defined there

  • knife[:xapi_host] The API Host to connect to
  • knife[:xapi_username] The User name to connect to the api with
  • knife[:xapi_password] The Password (if not set will prompt on commandline)
  • knife[:xapi_vm_template] Set a default template to be used when creating Guests
  • knife[:install_repo] The install repo config option to set when using Xen builtin templates
  • knife[:xapi_sr] The Storage Repository to provision from, uses pool/hypervisor default when not set
  • knife[:xapi_disk_size] Default VM disk size (8g if not specified)a
  • knife[:xapi_skip_disk] Skip adding any aditional disk to the vm.
  • knife[:xapi_cpus] The Default CPUs to provision for guests (2 if not specified)
  • knife[:xapi_mem] The Defaul ammount of Memory for guests (1g if not specified)
  • knife[:kernel_params] Optional Boot paramaters to pass to the guest
  • knife[:xapi_ssl_verify] Enable SSL Cert verification. Disabled due to xenserver not having valid certs on xapi

These options Controll xapi guest create bootstrap

  • knife[:domain] Set the domainname for the guest
  • knife[:run_list] Bootstrap Run list comma sepparated.
  • knife[:ssh_user] ssh user to login to the new vm as
  • knife[:ssh_port] ssh port to use
  • knife[:ssh_password] ssh password to use to login to the new vm
  • knife[:identity_file] ssh ident file
  • knife[:chef_node_name] node name to use for new guest chef run
  • knife[:bootstrap_version] version to bootstrap
  • knife[:bootstrap_template] template to use
  • knife[:template_file] path to a different template file you would like to use
  • knife[:environment] chef environment for first run
  • knife[:host_key_verify] true/false Honor hostkey verification or don't
  • knife[:ping_timeout] Seconds to timeout while waiting for an IP to be returned from guest
  • knife[:json_attributes] A JSON string to be added to the first run of chef-client
  • knife[:connect_timeout] Seconds to timeout while trying to connect to a guest

Usage

Note: The commands below when not specifing --host assumes that knife[:xapi_host] is set in ~/.chef/knife.rb

Guest Create

Basic usage to create a VM from existing VM template:

knife xapi guest create "NewBox" "Network 0"  --xapi-vm-template "MyBaseBox"   --host http://sandbox/ 

More verbose example using a kickstart file and booting the Centos 5 default template:

knife xapi guest create "MySpiffyBox" "pub_network" --host http://sandbox/ \
-B "dns=8.8.8.8 ks=http://192.168.6.4/repo/ks/default.ks " \
-R http://192.168.6.5/repo/centos/5/os/x86_64 -C 4 -M 4g -D 5g 
  • -B Boot args where i am assigning all the centos/rhel boot args for kickstart file and dns
  • -R Repo URL used by xenserver to start the net install
  • -C Number of cpus for this guest
  • -M Memory size
  • -D Disk size

Bootstrap

Using the same basic example you can bootstrap into a specific template

 knife xapi guest create "NewBox" "public" --xapi-vm-template "MyBaseBox" --host http://sandbox/ \
   --bootstrap-template centos5-gems --ssh-user root --ssh-password mypass \
   --run-list "role[base],role[spifybox]"

Guest Delete

Delete is pretty simple. When there are multiple vms with a name label you should be prompted to select one

knife xapi guest delete  testing 

If you know the UUID of the VM you can specify --uuid

knife xapi guest delete b461c0d2-d24d-bc02-3231-711101f57b8e --uuid

Guest List

List shows the vm's on the pool/host Ignoring Controll domains and templates. VM State, and Ip adress as reported through the xenapi. If you want to get the OpaqueRef, and UUID add -i or --show-id.

knife xapi guest list  
Name Label                 State        IP Address      
ks_test.local              Running      10.4.1.163      
dns01.local                Running      10.4.1.149      
dhcp01.local               Running      10.4.1.143      
jn_test.local              Running      10.4.1.162  

Start/Stop Guest

You can start/stop any instance with.. start and stop commands

knife xapi guest stop jn_test.local
knife xapi guest start jn_test.local

VDI Create

Create a disk on the xenserver with the specified size and name

xapi vdi create testing -D 20g 
  • -D is the short option for --xapi-disk-size
  • specify the SR to use with --xapi-sr or -S

VDI Delete

Remove a disk.

xapi vdi delete testing 

Delete has a special cleanup mode that will interactivly prompt you if you want to clean up non attached volumes

xapi vdi delete --interactive  

Delete also accepts a UUID for a disk with --uuid

VDI List

Report on xapi VDI's

knife xapi vdi list
================================================
VDI name: xs-tools.iso
  -UUID: bed2a28e-d68a-43d6-b8a1-2d30730b1561
  -Description: 
    -Type: user
================================================
VDI name: chef-server-root
  -UUID: 159cbeb9-45c6-43e0-8631-b88d7644beae
  -Description: Root disk for chef-server-root created by jnelson with knfie xapi
    -Type: system
      -VM name: chef01.mkd.ktc
      -VM state: Running

Net list

Output info on host/pool networks lists the MTU, the extra info and name of the network.

Name:  vlan1120.stage
  Info:  255.255.255.0 : 10.33.89.1-10.33.89.254
   MTU:  1500
  UUID:  73f6f18f-c1d9-664b-d4bb-7673ea0fc2a1

Help

Every command should accept --help and display arguments that it accepts (as all knife plugins do)

knife xapi --help

knife xapi guest create --help 

knife-xapi's People

Contributors

jkpark0314 avatar lebrinkma avatar seungjin avatar spheromak avatar swiff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

knife-xapi's Issues

VDI Subcommands not working properly with XS 6.2

The "knife xapi vdi" subcommands seem to have issues with XS 6.2.

"vdi list" Example:

knife xapi vdi list -VV -h http://dlaghv321
VDI Name: vdi_dlagapp32t1_home
UUID: fb24324c-65d1-4517-bdf0-c6ffc54ef522
Description: VDI_dlagapp32t1_home
Type: user
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_base.rb:465:in print_vdi_info': undefined methodbytes' for 10737418240:Fixnum (NoMethodError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_vdi_list.rb:61:in block in run' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_vdi_list.rb:60:ineach'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_vdi_list.rb:60:in run' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/knife.rb:466:inrun_with_pretty_exceptions'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/knife.rb:173:in run' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/application/knife.rb:123:inrun'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/bin/knife:25:in <top (required)>' from /usr/bin/knife:23:inload'
from /usr/bin/knife:23:in `

'

"vdi create" Example:

knife xapi vdi create -VV -h http://dlaghv321 -D 20g -S sata vdi_dlagdbs321_backup
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/xenapi/xenapi/client.rb:378:in _do_call': ["FIELD_TYPE_ERROR", "self"] (XenApi::Errors::GenericError) from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/xenapi/xenapi/client.rb:257:in_call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/xenapi/xenapi/dispatcher.rb:45:in method_missing' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_base.rb:299:inget_sr_by_name'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-xapi-0.5.4/lib/chef/knife/xapi_vdi_create.rb:54:in run' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/knife.rb:466:inrun_with_pretty_exceptions'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/knife.rb:173:in run' from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/application/knife.rb:123:inrun'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/bin/knife:25:in <top (required)>' from /usr/bin/knife:23:inload'
from /usr/bin/knife:23:in `

'

Unable to bootstrap in version 0.6.1

I am attempting to clone a vm from an existing template (which works fine without the bootstrap) and then have it run the default chef-full bootstrap on the node. This doesn't work. The knife xapi call exits as soon as the vm comes up - similar to a previous issue noted here. Here is my call, please let me know if I am doing this incorrectly.

knife xapi guest create "node01-test" "Bond 4+5" --xapi-vm-template "BKFD-Ubuntu-14.04-Template-Vol07" --xapi-skip-disk --bootstrap-template chef-full --ssh-user someuser --ssh-password somepass --host http://ipaddresshere/ -C 2

Thanks.

Create two virtual disk when create a new VM

When I create a VM using a existed template with this command

knife xapi guest create "test05" "Pool-wide network associated with eth0" -c test-xapi.rb -VV

There are two virtual disks were created, one named as template disk name, and another is named with "test05-root", so there is an error logged in xensource.log

[20120618T05:09:47.706Z|debug|fred-227|3418|Async.VBD.create R:930bd64e4414|dispatcher] Server_helpers.exec exception_handler: Got exception DEVICE_ALREADY_EXISTS: [ 0 ]
and failed to create the guest VM with latest knife-xapi gem

after I comment one line of code in xapi_guest_create.rb
line 288 #cleanup(vm_ref) unless vbd_ref
it's ok to create the VM.

Cloud you have a look why this happen? Thanks

Can't Bootstrap...

I am able to create/destroy vm's on XenServer but I can't get the vm to bootstrap chef. I have been trying with a few different vm's OEL, CentOS, Ubuntu.... As soon as the vm starts (before it finishes booting) the knife command completes successfully.

braden@braden-desktop:~/chef-repo$ knife xapi guest create "ubuntu" "Private" --xapi-vm-template "Ubuntu 12.04" --xapi-skip-disk --bootstrap-template chef-full --ssh-user hwa --ssh-password w4rr4nty --run-list "recipe[git]"
Waiting on Template Clone
success
Provisioning new Guest: ubuntu
Boot Args: graphical utf8 hostname=ubuntu domain= dnsdomain=
Install Repo: http://isoredirect.centos.org/centos/6/os/x86_64/
Memory: 1g
CPUs: 1
Disk:
Starting new Guest
OK!

I have been playing with Chef for a little while (and feel fairly comfortable) but have always manually created vm's and the used the knife bootstrap command.... so I may be missing something basic. Any help would be appreciated (the plugin looks really nice)

Unable to select SR to build VM on when using knife xapi guest create

I have a pool of xenservers, there is one master and 2 slaves.

I want to be able to build a VM on a specific host in the pool even though the host is a slave vs a pool master.

I figured if I use the --xapi-sr command I would be able to select the slave host local storage SR and then the VM would be created on that host....

I cannot find an example anywhere of how to use the --xapi-sr command...

Basically what i am doing now is the below not sure that is correct...

--xapi-sr {SR UUID} --host http://{pool master}

remote_directory preserve permissions for files and dirs as well as preserve symlinks

I am having an issue with remote_directory when it comes to file permissions. So as an example the remote directory that I want to pull down from the cookbook has a file that is set to 755 but when it gets pulled its get set to 644.

I do not want to use files_mode 755 because that will change all files to 755 even files in other directories that should be set to 644. So is there a way to just preserve the file permissions based on what it is set in the cookbook? The directory has many files with different permissions set would be hard for me to tackle each file individually so that I can specifically set the right permission.

Also symlinks they are not preserved is there a setting to preserve symlinks?

Create VM error with no nic found

I have some issues by this knife plugin, version 0.3.2
command line

knife xapi guest create "test" "Network 0" --xapi-vm-template "CentOS54T" -C 1 -M 512m --host http://172.16.233.227 -VV

Error message:

Network 0
WARNING: Network 0 not found, moving on

After the VM was created, there is no network, so it always report
.VM.get_guest_metrics
OpaqueRef:2550f8c8-348d-38ad-2900-726e37117843
OpaqueRef:58c7e0ad-d15d-6f06-fd68-0f668d5842bb

And failed with
.Timeout waiting for XAPI to report IP address
ip seems wrong using host+domain name instead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.