Wednesday, February 26, 2014

XenServer Commands

Below is a compilation of XenServer commands that I use and reference on a frequent basis.

VMs

Status of VM
xe vm-list name-label=<Name of VM>

Shutdown VM
xe vm-shutdown vm="Name of VM" 

List of VMs and their UUID
xe vm-list

Obtain the UUID of a particular VM
xe vm-list name-label=<Name of VM> (Name of VM is case sensitive)

Start VM from command line
xe vm-start vm=<name of vm>

Reboot VM from command line
xe vm-reboot name-label=<name of vm>

Resume VM from suspended mode
xe vm-resume vm=<name of VM>

When VMs have disappeared due to a failed XenServer host member
xe vm-reset-powerstate --force –multiple
xe vm-reset-powerstate  name-label=<name of machine>

Check power-state status of virtual machine
xe vm-list name-label=<name of virtual machine>


Host

List of XenServer hosts along with their UUIDs
xe host-list

Check disk space on XenServer host
df –h

Review memory settings
free -m

Remove host from pool using command line
xe pool-eject host-uuid= <UUID of Host>

Emergency Master Server Failure Recovery
xe host-emergency-ha-disable force=true
xe pool-emergency-transition-to-master
pool-designate-new-master host-uuid=<UUID of member XenServer host to become newmaster>
cat /etc/xensource/pool.conf to reflect the name of the new master.
Restarted XAPI service and it back to the pool.

Check if XenServer is a Pool Master
cat /etc/xensource/pool.conf
Output says “master” , slaves output “slave:<master host IP>”

Cancel XenServer Tasks
xe task-list
xe task-cancel uuid=<task uuid>

Identify VMs with an ISO loaded in CD tray
xe vm-cd-list --multiple

List of VMs on a particular XenServer host
xe vm-param-list uuid=<UUID of VM>

or

xe vm-list params name-label=ICORB01

To identify the XenServer host look for the field
resident-on ( RO): <UUID of XenServer Host>

xe host-list UUID=<UUID of XenServer Host>


Sending Host log messages to a central server

To write logs to a remote server


1. Set the syslog_destination parameter to the hostname or IP address of the remote server where you want the logs to be written:
xe host-param-set uuid=<xenserver_host_uuid> logging:syslog_destination=<hostname>


2. Issue the command:
xe host-syslog-reconfigure uuid=<xenserver_host_uuid>


Note: You can also execute this command remotely by specifying the host parameter.



VDIs

List of VDIs on a VM with descriptions and UUIDs
xe vdi-list name-label=<name of VM> params=name-description,uuid

Obtain the VDI UUID of a particular VM
xe-vdi-list name-label=<Name of VM> 

NOTE: If this does not work you must use the name of the actual storage drive connected to the VM (Name is case sensitive)

xe-vdi-list uuid=<UUID of vdi associated with the VM>

Delete VDI
xe vdi-destroy uuid=<UUID of VDI>

You can identify orphaned VDIs by checking the VBD connections for a VDI. If no VBD connections exist than the VDI is not connected to any VM.

Identify VBD connections for a VDI
xe vbd-list vdi-uuid=<UUID of VDI>

*VBD (virtual block devices) represent the mapping between VDIs and VMs. PBDs represent the interface between the physical server and the SR (storage repository)


Command to identify excessive tree of cloned VHDs
vhd-util scan -f -m “VHD-*” -l VG_XenStorage-<UUID of SR> -p


Pool

xe pool-sync-database (run on pool master)

Force the pool database to be synchronized across all hosts in the resource pool. This is not necessary in normal operations since the database is regularly automatically replicated, but can be useful for ensuring changes are rapidly replicated after performing a significant set of CLI operations.

Enable HA
xe pool-ha-enable

Disable HA
xe pool-ha-disable

Designate a new pool master


To change the pool master run the following command:


First disable high availability:
·         xe pool-ha-disable

Now list your XenServer hosts:
·         xe host-list

Using the list above, designate a new pool master by supplying the uuid associated with the desired host:
·         xe pool-designate-new-master host-uuid=<UUID of member XenServer host to become new master>

You’ll probably lose connection to the pool at this point, but that’s normal behavior. Once XenCenter reconnects (this should happen automatically), it’s safe to re-enable high availability:
·         xe pool-ha-enable

Backup Existing Pool State
·         Use PuTTY to connect to the pool master and run the following command
·         xe pool-dump-database file-name=pooldump
·         Use WinSCP to connect to the host and extract the pooldump file


Pool Failures (This info was taken from the XenServer 6.1 Admin Guide)

In the event that your entire resource pool fails, you will need to recreate the pool database from scratch. Be sure to regularly back up your pool-metadata using the xe pool-dump-database CLI command

To restore a completely failed pool

1.       Install a fresh set of hosts. Do not pool them up at this point.
2.       For the host nominated as the master, restore the pool database from your backup using the xe pool-restore database command.
3.       Connect to the master host using XenCenter and ensure that all your shared storage and VMs are available again.

4.       Perform a pool join operation on the remaining freshly installed member hosts, and start up your VMs on the appropriate hosts.


Replacing a failed master with a still running member

If the master is really dead, choose one of the members and run the command
xe pool-emergency-transition-to-master

Once it has become the master, run the command below and the members will now point to the new master

xe pool-recover-slaves


SR

Find UUID of Storage Repository (SR)
xe sr-list

Scan SR
xe sr-scan uuid=<uuid of sr>

Listing of VDI's on SR
xe vdi-list sr-uuid=<UUID of SR>

How to Remove a Storage Repository from XenServer



Logs

View High Availability log file on XenServer. Can use this command to view any log file
tail -f /var/log/xha.log


Snapshots

View a list of snapshots
xe snapshot-list

Use this to identify which vdi is not the snapshot when looking up VMs with VDIs with snapshots
xe vdi-list name-label=<name of vdi> params=all


NOTE: field <is-a-snapshot> will be true if it is a snapshot and false if it is not a snapshot


List of VDIs that have snapshots
xe vdi-list is-a-snapshot=true

Common

Cycle xapi service
xe-toolstack-restart 

List Networks and Attributes
xe network-list

XAPI stack
service xapi status
service xapi restart
xe-toolstack-restart

If it hangs at “Stopping xapi” or “Starting xapi”, you may need to kill the process.

To identify the process ID (PID)
Type: top

To kill the process
Type:  kill <pid>

Network connectivity utilities

Ethtool
Check statistics for eth0
Ethtool –S eth0

Ifconfig

Check time
Ntptime



No comments:

Post a Comment