زیاد طول کشیده است؟ صفحه بارگذاری را ببندید
شرکت داده پرداز سپهر آسیا

مقالات

Vmware

استفاده از DCLI در Vcenter

Getting started with VMware Datacenter Command-Line Interfaces(DCLI)

By Prigent Nicolas| July 3rd, 2018|0 Comments
  • Datacenter Command-Line Interfaces

Introduction

When it comes to IT automation, there are still worries about scripting because scripting can be a slow, time-consuming process, and it can be difficult for maintenance.

When something goes wrong, nobody knows what happened, who is the guy who wrote those scripts?

And, we have to mention that it’s hard to keep documentation up to date.

On the other hand, we have to admit that there are major advantages of automation that include:

  • easy to learn and use
  • minimum programming knowledge or experience required
  • allow complex tasks to be performed in relatively few steps
  • allow simple creation and editing in a variety of text editors
  • allow the addition of dynamic and interactive activities to web pages
  • editing and running code is fast

Scripting languages are becoming more popular due to the need to automate our day-to-day tasks. Every VMware administrator must automate basic tasks in order to save time. Managing Hyper-V and vSphere with Command-Line Interfaces is essential.

vSphere supports several command‐line interfaces for managing your virtual infrastructure including a set of ESXi Shell commands, PowerCLI commands, and DCLI commands for management of vCenter services. You can run commands locally, from an administration server, or from scripts.

What is vSphere CLI?

vSphere command-line interfaces allow you to administer your VMware virtual environment. vSphere command-line interfaces enable you to automate common tasks that you perform to deploy and support your virtual datacenter such as configuring and managing storage for the ESXi hosts and setting up networking for virtual machines.

Below is an overview of vSphere Command-Line Interfaces from the VMware website:

 

vSphere Command-Line
 

ESXCLI commands: Manage many aspects of an ESXi host. You can run ESXCLI commands remotely or in the ESXi Shell. You can also run ESXCLI commands from the vSphere PowerCLI prompt by using the Get-EsxCli cmdlet.

vCLI package: Install the vCLI package on the server of your choice.

  • ESXi Shell: Run ESXCLI commands in the local ESXi shell to manage that host
  • Vicfg: Allow users to manage hosts remotely. Install the vCLI package on a Windows or Linux system or deploy a vMA virtual machine, and target the ESXi system that you want to manipulate

VMware PowerCLI: VMware vSphere PowerCLI provides a Windows PowerShell interface to the vSphere API. vSphere PowerCLI includes PowerShell cmdlets for administering vSphere components. It also includes many cmdlets and, a set of sample scripts for management and automation. More information about PowerCLI here: Managing vSphere using VMware PowerCL

DCLI commands: Let’s see what is DCLI in the next section.

What is VMware Datacenter CLI?

VMware DCLI means VMware Datacenter Command-Line Interfaces, which is used to manage VMware vCenter. DCLI is a CLI client, a DCLI command talks to a VMware API endpoint to locate relevant information and then executes the command and displays result to the user.

You can run DCLI commands as follows:

vCenter Server Appliance. Run DCLI commands from the vCenter Server Appliance shell.

vCenter Server Windows command prompt. Install vCenter Server on a supported Windows system and run DCLI commands from the command prompt.

Scripts. Use scripts that include DCLI commands and run the scripts as vCLI scripts from the vCenter Server Windows command prompt or from the vCenter Server Appliance shell.

Thanks to VMware DCLI, you can retrieve information about your vCenter infrastructure (Network, storage, VMs, …) and you can also manage your VMware resources (create, delete, …) as you can perform using PowerCLI.

Running DCLI Commands on the vCenter Server Appliance

The first thing to perform is to connect to your vCenter server using the SSH protocol. On a Windows machine, open Putty and then type the root credentials. One thing to notice is the syntax.

Unlike other scripting languages that use a “-” in front of each parameter, VMware DCLI will use ‘+’ instead of ‘-‘.

To start a DCLI session, use the following command:

Command> dcli +interactive

 

Interactive
 

In this example, the interactive shell uses the dcli> prompt which is the default but you can customize the prompt:

dcl> dcli +interactive +prompt VMwareDCLI

 

prompt VMwareDCLI
 

Thanks to the interactive mode, you can autocomplete your command. Type the command and then press the spacebar or TAB, to display the available options:

 

VMwareDCLI
 

If you need more information about a command, use the –help parameter:

 

VMwareDCLI
 

I can easily retrieve information about a specific Virtual Machine. First, I can use the ‘list’ command:

VMwareDCLI> vCenter vm list –names XXXXX

This command returns some basic information such as:

  • VM ID
  • VM Name
  • Power State
  • CPU Count
  • Memory Size

The VM ID is important and can be used with the ‘get’ command:

VMwareDCLI> vCemter vm get –vm YYYYYYY

 

VMwareDCLI
 

Using DCLI with a Credential Store File

To avoid typing the username and password each time you run a DCLI command, you can add the current user and the associated password to a credential store file by using the credstore-add option on the command line.

In the following example, I can list the current credential store file using:

Command> dcli +credstore-list

 

VMwareDCLI
 

Now, let’s run the ‘credstore-add’ command from a Windows machine to add a new credential store entry.

 

VMwareDCLI
 

dcli com vmware cis tagging tag list +credstore-add +username user1

 

VMwareDCLI
 

DCLI History File

DCLI maintains a history file for each DCLI client that runs in interactive mode, which is located in the following directory:

%Appdata%\Roaming\VMware\vapi

 

VMwareDCLI
 

The file stores information on a per‐user basis and not on a per‐client basis.

Running DCLI Commands from a Windows Machine

The first thing to do is to install the vSphere CLI package. So download the package from the VMware website:

 

VMwareDCLI
 

As you can notice, the package was released in 2016. A few days ago, the VMware team has released the latest version

https://blogs.vmware.com/vsphere/2018/06/new-release-dcli-2-9-1.html, which is no longer available in the vSphere CLI package.

You must install Python and PyPI: https://pypi.org/project/dcli/ to install DCLI. PyPI is the official 3rd party public repository for Python. PyPI will download and install DCLI onto your local system:

 

VMwareDCLI
 

Let’s confirm if Python and PIP are installed:

 

VMwareDCLI
 

Then you can run the installation process using the following command:

> pip install dcli

 

VMwareDCLI
 

You can still work with DCLI using the vSphere CLI package, but using this way, DCLI will be released on a more regular cadence. So you should use ‘pip’ to work with the latest version.

In my current lab, I will use the vSphere CLI package. First, use the following command to connect to your vCenter server:

> dcli.exe +server https://vCenter/api +interactive +prompt dcli> +skip-server-verification

 

VMwareDCLI
 

Below are some basic examples.

    1. List the Virtual Machines in a specific Power State:

 

VMwareDCLI
 

    1. Retrieve CPU information for a specific VM:

 

VMwareDCLI
 

    1. Show the system time:

 

VMwareDCLI
 

Here is the list of DCLI Commands:

  • cis session
  • cis tagging tag
  • cis tagging tagassociation
  • cis tagging category
  • cis data legacy resourcemodel
  • content locallibrary
  • content configuration
  • content library
  • content type
  • content subscribedlibrary
  • content library subscribeditem
  • content library item
  • content library item storage
  • content library item downloadsession
  • content library item file
  • content library item updatesession
  • content library item updatesession file
  • content library item downloadsession file
  • appliance monitoring
  • appliance vmon service
  • appliance networking interfaces
  • appliance networking dns servers
  • appliance networking dns hostname
  • appliance networking dns domains
  • appliance health load
  • appliance health system
  • appliance health storage
  • appliance health softwarepackages
  • appliance health mem
  • appliance health swap
  • appliance health databasestorage
  • appliance health applmgmt
  • appliance access shell
  • appliance access ssh
  • appliance access consolecli
  • appliance access dcui
  • appliance techpreview shutdown
  • appliance techpreview timesync
  • appliance techpreview ntp
  • appliance techpreview services
  • appliance techpreview networking routes
  • appliance techpreview networking ipv6
  • appliance techpreview networking ipv4
  • appliance techpreview networking proxy
  • appliance techpreview networking firewall addr inbound
  • appliance techpreview services status
  • appliance techpreview localaccounts user
  • appliance techpreview monitoring snmp
  • appliance techpreview ntp server
  • appliance techpreview system update
  • appliance recovery backup
  • appliance recovery restore
  • appliance recovery backup parts
  • appliance recovery backup job
  • appliance recovery restore job
  • appliance system storage
  • appliance system uptime
  • appliance system version
  • appliance system time
  • vcenter datacenter
  • vcenter network
  • vcenter folder
  • vcenter host
  • vcenter vm
  • vcenter datastore
  • vcenter resourcepool
  • vcenter cluster
  • vcenter iso image
  • vcenter inventory network
  • vcenter inventory datastore
  • vcenter vm hardware
  • vcenter vm power
  • vcenter vm hardware boot
  • vcenter vm hardware serial
  • vcenter vm hardware ethernet
  • vcenter vm hardware cdrom
  • vcenter vm hardware disk
  • vcenter vm hardware floppy
  • vcenter vm hardware memory
  • vcenter vm hardware parallel
  • vcenter vm hardware cpu
  • vcenter vm hardware adapter sata
  • vcenter vm hardware adapter scsi
  • vcenter vm hardware boot device
  • vcenter ovf exportflag
  • vcenter ovf libraryitem
  • vcenter ovf importflag

You can get more information about these commands here: https://pubs.vmware.com/vsphere-6-5/index.jsp?topic=%2Fcom.vmware.dcli.cmdref.doc%2Fintro.html

 

نوشته های مرتبط

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

متخصصین داده پرداز سپهر آسیا

جهت مشاوره تخصصی با متخصصین ما در ارتباط باشید

منو
سایدبار