2015.5.4 新版功能.
Author: Nitin Madhok <nmadhok@clemson.edu>
The VMware cloud module allows you to manage VMware ESX, ESXi, and vCenter.
The vmware module for Salt Cloud requires the pyVmomi package, which is
available at PyPI:
https://pypi.python.org/pypi/pyvmomi
This package can be installed using pip or easy_install:
pip install pyvmomi
easy_install pyvmomi
The VMware cloud module needs the vCenter or ESX/ESXi URL, username and password to be
set up in the cloud configuration at
/etc/salt/cloud.providers or /etc/salt/cloud.providers.d/vmware.conf:
my-vmware-config:
driver: vmware
user: 'DOMAIN\user'
password: 'verybadpass'
url: '10.20.30.40'
vcenter01:
driver: vmware
user: 'DOMAIN\user'
password: 'verybadpass'
url: 'vcenter01.domain.com'
protocol: 'https'
port: 443
vcenter02:
driver: vmware
user: 'DOMAIN\user'
password: 'verybadpass'
url: 'vcenter02.domain.com'
protocol: 'http'
port: 80
esx01:
driver: vmware
user: 'admin'
password: 'verybadpass'
url: 'esx01.domain.com'
注解
Optionally, protocol and port can be specified if the vCenter
server is not using the defaults. Default is protocol: https and
port: 443.
注解
在 2015.8.0 版更改.
The provider parameter in cloud provider configuration was renamed to driver.
This change was made to avoid confusion with the provider parameter that is
used in cloud profile configuration. Cloud provider configuration now uses driver
to refer to the salt-cloud driver that provides the underlying functionality to
connect to a cloud provider, while cloud profile configuration continues to use
provider to refer to the cloud provider configuration that you define.
Set up an initial profile at /etc/salt/cloud.profiles or
/etc/salt/cloud.profiles.d/vmware.conf:
vmware-centos6.5:
provider: vcenter01
clonefrom: test-vm
## Optional arguments
num_cpus: 4
memory: 8GB
devices:
cd:
CD/DVD drive 1:
device_type: datastore_iso_file
iso_path: "[nap004-1] vmimages/tools-isoimages/linux.iso"
CD/DVD drive 2:
device_type: client_device
mode: atapi
controller: IDE 2
CD/DVD drive 3:
device_type: client_device
mode: passthrough
controller: IDE 3
disk:
Hard disk 1:
size: 30
Hard disk 2:
size: 20
controller: SCSI controller 2
Hard disk 3:
size: 5
controller: SCSI controller 3
network:
Network adapter 1:
name: 10.20.30-400-Test
switch_type: standard
ip: 10.20.30.123
gateway: [10.20.30.110]
subnet_mask: 255.255.255.128
domain: example.com
Network adapter 2:
name: 10.30.40-500-Dev-DHCP
adapter_type: e1000
switch_type: distributed
Network adapter 3:
name: 10.40.50-600-Prod
adapter_type: vmxnet3
switch_type: distributed
ip: 10.40.50.123
gateway: [10.40.50.110]
subnet_mask: 255.255.255.128
domain: example.com
scsi:
SCSI controller 1:
type: lsilogic
SCSI controller 2:
type: lsilogic_sas
bus_sharing: virtual
SCSI controller 3:
type: paravirtual
bus_sharing: physical
ide:
IDE 2
IDE 3
domain: example.com
dns_servers:
- 123.127.255.240
- 123.127.255.241
- 123.127.255.242
resourcepool: Resources
cluster: Prod
datastore: HUGE-DATASTORE-Cluster
folder: Development
datacenter: DC1
host: c4212n-002.domain.com
template: False
power_on: True
extra_config:
mem.hotadd: 'yes'
guestinfo.foo: bar
guestinfo.domain: foobar.com
guestinfo.customVariable: customValue
deploy: True
customization: True
private_key: /root/.ssh/mykey.pem
ssh_username: cloud-user
password: veryVeryBadPassword
minion:
master: 123.127.193.105
file_map:
/path/to/local/custom/script: /path/to/remote/script
/path/to/local/file: /path/to/remote/file
/srv/salt/yum/epel.repo: /etc/yum.repos.d/epel.repo
hardware_version: 10
image: centos64Guest
#For Windows VM
win_username: Administrator
win_password: administrator
win_organization_name: ABC-Corp
plain_text: True
win_installer: /root/Salt-Minion-2015.8.4-AMD64-Setup.exe
win_user_fullname: Windows User
providerclonefromnum_cpuscores_per_socketBoron 新版功能.
Enter the number of cores per vCPU that you want the VM/template to have. If not specified, this will default to 1. Note that you cannot assign more cores per socket than the total number of vCPUs assigned to the VM.
memorymemory: 8GB or memory: 8192MB.devicesEnter the device specifications here. Currently, the following devices can be created or reconfigured:
Enter the CD/DVD drive specification here. If the CD/DVD drive doesn't exist, it will be created with the specified configuration. If the CD/DVD drive already exists, it will be reconfigured with the specifications. The following options can be specified per CD/DVD drive:
client_device and datastore_iso_file. Default is
device_type: client_devicedevice_type: datastore_iso_file. The syntax to specify this is
iso_path: "[datastoreName] vmimages/tools-isoimages/linux.iso". This
field is ignored if device_type: client_devicedevice_type: client_device. Currently
supported modes are passthrough and atapi. This field is ignored if
device_type: datastore_iso_file. Default is mode: passthroughEnter the disk specification here. If the hard disk doesn't exist, it will be created with the provided size. If the hard disk already exists, it will be expanded if the provided size is greater than the current size of the disk.
thin_provision: False.
.. versionadded:: 2016.3.0Enter the network adapter specification here. If the network adapter doesn't exist, a new network adapter will be created with the specified network name, type and other configuration. If the network adapter already exists, it will be reconfigured with the specifications. The following additional options can be specified per network adapter (See example above):
vmxnet, vmxnet2, vmxnet3, e1000 and e1000e.
If no type is specified, by default vmxnet3 will be used.standard for standard portgroups and distributed for
distributed virtual portgroups.Enter the SCSI controller specification here. If the SCSI controller doesn't exist, a new SCSI controller will be created of the specified type. If the SCSI controller already exists, it will be reconfigured with the specifications. The following additional options can be specified per SCSI controller:
lsilogic, lsilogic_sas and paravirtual. Type must
be specified when creating a new SCSI controller.Specify this if sharing of virtual disks between virtual machines is desired. The following can be specified:
domaindomain is set to the domain from the VM name. Default is local.dns_serversresourcepoolEnter the name of the resourcepool to which the new virtual machine should be attached. This determines what compute resources will be available to the clone.
注解
clusterEnter the name of the cluster whose resource pool the new virtual machine should be attached to.
注解
datastoreEnter the name of the datastore or the datastore cluster where the virtual machine should be located on physical storage. If not specified, the current datastore is used.
注解
folderEnter the name of the folder that will contain the new virtual machine.
注解
datacenterEnter the name of the datacenter that will contain the new virtual machine.
注解
hostEnter the name of the target host where the virtual machine should be registered.
If not specified:
注解
templatetemplate: False.power_ontemplate: True is set, this field is ignored. Default is power_on: True.extra_configdeployTrue
so salt will be installed using the bootstrap script. If template: True or
power_on: False is set, this field is ignored and salt will not be installed.customizationcustomization: False is set, the new virtual machine will not be customized.
Default is customization: True.private_keyssh_usernamerootpasswordprivate_key is
specified, you do not need to specify this.minionmaster as the IP/DNS name of the master.file_maphardware_versionimageSpecify the guest id of the VM. For a full list of supported values see the VMware vSphere documentation:
注解
For a clone operation, this argument is ignored.
win_usernameSpecify windows vm administrator account.
注解
Windows template should have "administrator" account.
win_passwordSpecify windows vm administrator account password.
注解
During network configuration (if network specified), it is used to specify new administrator password for the machine.
win_organization_namewin_user_fullnameplain_textFlag to specify whether or not the password is in plain text, rather than encrypted. VMware vSphere documentation:
win_installerCloning VMs/templates is the easiest and the preferred way to work with VMs using the VMware driver.
注解
Cloning operations are unsupported on standalone ESXi hosts, a vCenter server will be required.
Example of a minimal profile:
my-minimal-clone:
provider: vcenter01
clonefrom: 'test-vm'
When cloning a VM, all the profile configuration parameters are optional and the configuration gets inherited from the clone.
Example to add/resize a disk:
my-disk-example:
provider: vcenter01
clonefrom: 'test-vm'
devices:
disk:
Hard disk 1:
size: 30
Depending on the configuration of the VM that is getting cloned, the disk in the resulting clone will differ.
注解
Example to reconfigure the memory and number of vCPUs:
my-disk-example:
provider: vcenter01
clonefrom: 'test-vm'
memory: 16GB
num_cpus: 8
Cloning a template works similar to cloning a VM except for the fact that a resource pool or cluster must be specified additionally in the profile.
Example of a minimal profile:
my-template-clone:
provider: vcenter01
clonefrom: 'test-template'
cluster: 'Prod'
2016.3.0 新版功能.
Creating a VM from scratch means that more configuration has to be specified in the profile because there is no place to inherit configuration from.
注解
Unlike most cloud drivers that use prepared images, creating VMs using VMware cloud driver needs an installation method that requires no human interaction. For Example: preseeded ISO, kickstart URL or network PXE boot.
Example of a minimal profile:
my-minimal-profile:
provider: esx01
datastore: esx01-datastore
resourcepool: Resources
folder: vm
注解
The example above contains the minimum required configuration needed to create a VM from scratch. The resulting VM will only have 1 VCPU, 32MB of RAM and will not have any storage or networking.
Example of a complete profile:
my-complete-example:
provider: esx01
datastore: esx01-datastore
resourcepool: Resources
folder: vm
num_cpus: 2
memory: 8GB
image: debian7_64Guest
devices:
scsi:
SCSI controller 0:
type: lsilogic_sas
ide:
IDE 0
IDE 1
disk:
Hard disk 0:
controller: 'SCSI controller 0'
size: 20
cd:
CD/DVD drive 0:
controller: 'IDE 0'
device_type: datastore_iso_file
iso_path: '[esx01-datastore] debian-8-with-preseed.iso'
network:
Network adapter 0:
name: 'VM Network'
swith_type: standard
注解
Depending on VMware ESX/ESXi version, an exact match for image might not
be available. In such cases, the closest match to another image should
be used. In the example above, a Debian 8 VM is created using the image
debian7_64Guest which is for a Debian 7 guest.