使用terraform创建vSphere资源

terraformvspherevm的Python项目详细描述


terraformvspherevm

此工具在vSphere基础结构上创建和删除带有TerraForm的计算机。

系统要求

  • Python3
  • 地形

安装

pip安装terraformvspherevm

开发

用法

命令行

用法

$ terraformvspherevm --help
usage: terraformvspherevm [-h] --action {create,destroy} --datacenter DATACENTER    
                    --datastore DATASTORE --pool POOL --folder FOLDER
                    --template TEMPLATE --guestid GUESTID --name NAME
                    [--nic NIC][--ip IP][--cidr CIDR][--gateway GATEWAY]   
                    --cpu CPU --ram RAM [--disk DISK][--dns DNS] --esxhost
                    ESXHOST --esxuser ESXUSER --esxpassvar ESXPASSVAR --domain
                    DOMAIN --timezone TIMEZONE [-debug]

Manage vSphere Virtual Machines

optional arguments:
  -h, --help            show this help message and exit
  --action {create,destroy}
                        Action to Execute against vSphere
  --datacenter DATACENTER
                        ESXi Datacenter
  --datastore DATASTORE
                        ESXi Datastore
  --pool POOL           ESXi Resource Pool
  --folder FOLDER       ESXi VM Folder
  --template TEMPLATE   Template Name
  --guestid GUESTID     Guest ID
  --name NAME           Virtual Machine Name
  --nic NIC             Network Interface. Repeat option for several NICs
  --ip IP               NIC IP address. Repeat option for several NICs
  --cidr CIDR           NIC CIDR. Repeat option for several NICs
  --gateway GATEWAY     Default gateway
  --cpu CPU             CPUs
  --ram RAM             Memory
  --disk DISK           Additionnal disk in GB. Repeat option for several
                        disks
  --dns DNS             DNS server
  --esxhost ESXHOST     ESXi host
  --esxuser ESXUSER     ESXi Username
  --esxpassvar ESXPASSVAR
                        Environment variable that contain ESXi password
  --domain DOMAIN       DNS domain
  --timezone TIMEZONE   TimeZone
  -debug                Verbose Output

When you want to destroy a VM, tfstate file is not required

示例

创建虚拟机

terraformvspherevm --name terrascript-test --datacenter "DC" --datastore "MyDatastore"\
--pool "ressource_pool" --template "rhel-7.5-vmw6.0" --guestid "rhel7_64Guest" --nic DvP_Nmae \
--ip 10.0.123.123 --cidr 24 --gateway 10.0.123.1 --cpu 1 --ram 1024 --disk 10 --dns 10.0.123.50 \
--dns 10.0.123.100 --esxhost esxhost.domain.com --esxuser "esxusername" --folder "terraformed"\
--domain my.domaon --timezone "Etc/UTC" --esxpassvar ESXPASS --action create

销毁虚拟机

terraformvspherevm --name terrascript-test --datacenter "DC" --datastore "MyDatastore"\
--pool "ressource_pool" --template "rhel-7.5-vmw6.0" --guestid "rhel7_64Guest" --cpu 1\
--ram 1024 --esxhost esxhost.domain.com --esxuser "esxusername" --folder "terraformed"\
--esxpassvar ESXPASS --action destroy

在python代码中

fromterraformvspherevmimportTerraformVMvmProperties={'name':'myVM',...}tvm=TerraformVM()tvm.addVirtualMachine(vmProperties)tvm.createVM('myVM')tvm.destroyVM('myVM')

开发

virtualenv和依赖关系

python -m venv venv
source ./venv/bin/activate
python -m pip install -r requirements.txt

运行命令

$ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 252019, 22:22:05)[MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license"for more information.
>>> import terraformvm
>>> terraformvm.main(['--help'])

构建

python setup.py sdist bdist_wheel

上传pypi

twine upload dist/*

TODOLIST

  • 代码文档
  • 参数验证
  • 错误管理

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java中ArrayList的超简单问题   Java 8在一段时间后过期   java如何创建具有用户定义维度的矩阵,并使用从上到下、从左到右的递增值填充它?   java从JDBC重启mysql   带有sqlite的java LiveData未更新UI   带有JDialog的java小程序在Mac OSX中未正确隐藏   java ActionListener无法从公共类引用数组?   java Apache Digester:NoSuchMethodException:没有这样的可访问方法   安卓中数据库中的java数据没有以正确的格式检索   java快速排序实现:使用random pivot时几乎排序   安卓 Java:高效的ArrayList过滤?   java如何在单独的文件中制作GUI程序   jasper报告如何从JSP或Java代码在JasperReport中传递参数值?