This posting is ~5 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.
I have wrote about the installation of PowerShell Core in Linux Mint 18 yesterday. Today, I want to show you, how to install Visual Studio Code on Linux Mint 18. The installation is really easy:
Download the deb package
Install the deb package
Run Visual Studio Code
You can download the latest packages for Windows, Linux (deb and rpm, if you want even a tar ball), and Mac on the Visual Studio Code download page. Download the deb file. To install the package, open a Terminal window and run dpkg .
[email protected] ~/Downloads
% sudo dpkg -i code_1.17.1-1507645403_amd64.deb
[sudo] password for patrick:
Selecting previously unselected package code.
(Reading database ... 236413 files and directories currently installed.)
Preparing to unpack code_1.17.1-1507645403_amd64.deb ...
Unpacking code (1.17.1-1507645403) ...
Setting up code (1.17.1-1507645403) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22+linuxmint1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
[email protected] ~/Downloads
%
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
sudo might ask you for a password. That’s it! Now you can simply start VS Code.After you have installed your favorite extensions, VS Code is ready to code.
This posting is ~5 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.
Beside my Lenovo X250, which is my primary working machine, I’m using a HP ProBook 6450b. This was my primary working machine from 2010 until 2013. With a 128 GB SSD, 8 GB RAM and the Intel i5 M 450 CPU, it is still a pretty usable machine. I used it mainly during projects, when I needed a second laptop (or the PC Express card with the serial port…). It was running Windows 10, until I decided to try Linux MInt. I used Linux as my primary desktop OS more than a decade ago. It was quite productive, but especially with laptops, there were many things that does not worked out of the box.
Because I use PowerShell quite often, and PowerShell is available for Windows, MacOS and Linux, the installation of PowerShell on this Linux laptop is a must.
How to install PowerShell?
Linux Mint is a based on Ubuntu, and I’m currently using Linux Mint 18.2. Microsoft offers different pre-compiled packages on the PowerShell GitHub repo. For Linux Mint 18, you have to download the Ubuntu 16.04 package. For Linux Mint 17, you will need the 14.04 package. Because you need the shell to install the packages, you can download the deb package from the shell as well. I used wget to download the deb package.
The next step is to install the deb package, and to fix broken dependencies. Make sure that you run dpkg with sudo .
[email protected] ~/Downloads
% sudo dpkg -i powershell_6.0.0-beta.8-1.ubuntu.16.04_amd64.deb
Selecting previously unselected package powershell.
(Reading database ... 235671 files and directories currently installed.)
Preparing to unpack powershell_6.0.0-beta.8-1.ubuntu.16.04_amd64.deb ...
Unpacking powershell (6.0.0-beta.8-1.ubuntu.16.04) ...
dpkg: dependency problems prevent configuration of powershell:
powershell depends on liblttng-ust0; however:
Package liblttng-ust0 is not installed.
dpkg: error processing package powershell (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.7.5-1) ...
Errors were encountered while processing:
powershell
Looks like it failed, because of broken dependencies. But this can be easily fixed. To fix the broken dependencies, run apt-get -f install . Make sure that you run it with sudo !
[email protected] ~/Downloads
% sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
liblttng-ust-ctl2 liblttng-ust0 liburcu4
The following NEW packages will be installed:
liblttng-ust-ctl2 liblttng-ust0 liburcu4
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 247 kB of archives.
After this operation, 1.127 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.netcologne.de/ubuntu xenial/universe amd64 liburcu4 amd64 0.9.1-3 [47,3 kB]
Get:2 http://mirror.netcologne.de/ubuntu xenial/universe amd64 liblttng-ust-ctl2 amd64 2.7.1-1 [72,2 kB]
Get:3 http://mirror.netcologne.de/ubuntu xenial/universe amd64 liblttng-ust0 amd64 2.7.1-1 [127 kB]
Fetched 247 kB in 0s (841 kB/s)
Selecting previously unselected package liburcu4:amd64.
(Reading database ... 236372 files and directories currently installed.)
Preparing to unpack .../liburcu4_0.9.1-3_amd64.deb ...
Unpacking liburcu4:amd64 (0.9.1-3) ...
Selecting previously unselected package liblttng-ust-ctl2:amd64.
Preparing to unpack .../liblttng-ust-ctl2_2.7.1-1_amd64.deb ...
Unpacking liblttng-ust-ctl2:amd64 (2.7.1-1) ...
Selecting previously unselected package liblttng-ust0:amd64.
Preparing to unpack .../liblttng-ust0_2.7.1-1_amd64.deb ...
Unpacking liblttng-ust0:amd64 (2.7.1-1) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Setting up liburcu4:amd64 (0.9.1-3) ...
Setting up liblttng-ust-ctl2:amd64 (2.7.1-1) ...
Setting up liblttng-ust0:amd64 (2.7.1-1) ...
Setting up powershell (6.0.0-beta.8-1.ubuntu.16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
That’s it! PowerShell is now installed.
[email protected] ~/Downloads
% powershell
PowerShell v6.0.0-beta.8
Copyright (C) Microsoft Corporation. All rights reserved.
PS /home/patrick/Downloads> Get-ChildItem /home/patrick
Directory: /home/patrick
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/10/17 10:26 PM Desktop
d----- 10/14/17 8:45 AM Documents
d----- 10/14/17 8:41 AM Downloads
d----- 10/10/17 10:26 PM Music
d----- 10/14/17 8:37 AM Pictures
d----- 10/10/17 10:26 PM Public
d----- 10/10/17 10:26 PM Templates
d----- 10/10/17 10:26 PM Videos
PS /home/patrick/Downloads> exit
[email protected] ~/Downloads
%
Yep, looks like a PowerShell prompt…on Linux. Thank you, Microsoft! :)
This posting is ~7 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.
In December 2013, VMware made an christmas gift to the community by releasing pyVmomi. pyVmomi is a SDK that allows you to manage VMware ESXi and vCenter using Python and the VMware vSphere API. Nearly 18 months are past since then and pyVmomi has developed over time.
You can install the official release of pyVmomi using pip (pip installs packages, a recursive acronym).
pip3 install --upgrade pyvmomi
The latest version is available on GitHub. To get the latest version, use
python setup.py develop
or
python setup.py install
That you can fetch the latest version from GitHub is pretty cool and shows a big benefit: The community can contribute to pyVmomi and it’s more frequently updated. A huge benefit in regard of code quality and features.
pyVmomi 6.0.0.2016.4 and later support 2.7, 3.3 and 3.4
pyVmomi 6.0.0 and later support 2.7, 3.3 and 3.4
pyVmomi 5.5.0-2014.1 and 5.5.0-2014.1.1 support Python 2.6, 2.7, 3.3 and 3.4
pyVmomi 5.5.0 and below support Python 2.6 and 2.7
Interesting fact: pyVmomi version numbers correlate with vSphere releases. pyVmomi 6.0.0 was released with the GA of VMware vSphere 6. pyVmomi supports the corresponding vSphere release and the previous four vSphere releases.
I’m using Python 3 for my examples. I wouldn’t recommend to start with Python 2 these days.
First steps
pyVmomi allows you to manage VMware ESXi and vCenter using Python and the VMware vSphere API. Because of this, the VMware vSphere API Reference Documentation will be your best friend.
First of all, you need a connection to the API. To connect to the vSphere API, we have to import and use the module pyVim, more precise, the pyVim.connect module and the SmartConnect function. pyVim.connect is used for the connection handling (creation, deletion…) to the Virtualization Management Object Management Infrastructure (VMOMI). pyVim is part of pyVmomi and it’s installed automatically.
from pyVim.connect import SmartConnect
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd')
SmartConnect accepts various parameters, but for the beginning it’s sufficient to use three of them: host, user and pwd. You can use “help(SmartConnect)” to get information about the SmartConnect function. “c” is the object (pyVmomi.VmomiSupport.vim.ServiceInstance) which we will use later.
A connection itself is useless. But how can we explore the API? Python doesn’t support typing, so it can be difficult to “explore” an API. That’s why the VMware vSphere API Reference Documentation and the Managed Object Browser (MOB) will be your best friends. The MOB is a web-based interface and represents the vSphere API. It allows you to navigate through the API. Any changes you make through the MOB, by invoking methods, take effect and change the config or will give you an output.
Important note: If you are using VMware vSphere 6 (ESXi 6.0 and vCenter 6.0), you have to enable the MOB. The MOB is disabled by default. Check VMware KB2108405 (The Managed Object Browser is disabled by default in vSphere 6.0) for more details.
Open a browser and open https://ip-or-fqdn/mob. You can use the IP address or the FQDN of an ESXi host or a vCenter Server (Appliance). I use a standalone ESXi 5.5 host in this example.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Our first code
Let’s try something easy. I’ve framed a method in the screenshot above. We will use this method now.
from pyVim.connect import SmartConnect
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd')
print(c.CurrentTime())
This code will connect to the vSphere API, invoke the method “CurrentTime()” and prints the result. What happens if we execute our first lines of Python code? We will get an error…
Python checks SSL certificates in strict mode. Because of this, untrusted certificates will cause trouble. This applies to Python 3, as well as to Python >= 2.7.9 (PEP 0466). Most people use untrusted certificates. To deal with this, we have to create a context for our HTTP connection. This context can be used by the SmartConnect function. To create a context, we have to import the ssl module of Python.
from pyVim.connect import SmartConnect
import ssl
s = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode = ssl.CERT_NONE
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd', sslContext=s)
print(c.CurrentTime())
“s” is the new object (ssl.SSLContext) we will use and the parameter “sslContext=s” will told SmartConnect to use this object.
Save this code into a file (I called it pyvmomitest.py in my example). Navigate to the folder, open a Python REPL and import the file you’ve saved (module) a moment ago.
C:\Users\p.terlisten\Documents\Development\Python\Playground>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvmomitest
2016-05-20 12:29:23.837049+00:00
>>>
Hurray! We used the vSphere API to get the current date and time (CET).
But what if we have deployed valid certificates? And what about housekeeping? We have connected, but we haven’t disconnected from the API? We can use a try-except block to handle this. And because we are nice, we import also the function “Disconnect” from pyVim.connect to disconnect from the vSphere API at the end.
from pyVim.connect import SmartConnect, Disconnect
import ssl
s = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode = ssl.CERT_NONE
try:
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd')
print('Valid certificate')
except:
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd', sslContext=s)
print('Invalid or untrusted certificate')
print(c.CurrentTime())
Disconnect(c)
With this code, we should get the following output.
C:\Users\p.terlisten\Documents\Development\Python\Playground>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvmomitest
Invalid or untrusted certificate
2016-05-20 12:36:28.707876+00:00
>>>
Okay, the vSphere API wasn’t designed to retrieve the current date and time. Let’s look at something more useful. This script will give us the names of all VMs in the datacenter.
from pyVim.connect import SmartConnect, Disconnect
import ssl
s = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode = ssl.CERT_NONE
try:
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd')
print('Valid certificate')
except:
c = SmartConnect(host="192.168.20.1", user="root", pwd='Passw0rd', sslContext=s)
print('Invalid or untrusted certificate')
datacenter = c.content.rootFolder.childEntity[0]
vms = datacenter.vmFolder.childEntity
for i in vms:
print(i.name)
Disconnect(c)
Let’s take this statement and look at everything after the “c”. We will use the MOB to navigate through the API. This will help you to understand, how the Python code and the structure of the vSphere API correlate.
datacenter = c.content.rootFolder.childEntity[0]
Open the MOB. You will easily find the property “content”.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Click on “content” and search for the property “rootFolder”.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Click on the value “ha-folder-root.” The property “childEntity” is an ManagedObjectReference (MOR) and references to all datacenters (the counting starts at 0) known to the ESXi or vCenter. The value “childEntity[0]” will give us the first datacenter.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
If we have the datacenter, the way to get the names of the VMs is the same. You can use the MOB, to verify this.
vms = datacenter.vmFolder.childEntity
Click on the value “ha-datacenter”. At the bottom of the list, you will find the property “vmFolder”.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Click on the value “ha-folder-vm”.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
The MOR “childEntity” references to two VMs. Click on one of the IDs.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
The property “name” includes the name of the VM. Because of this, we can use a simple
for i in vms:
print(i.name)
to get the name for each VM.
Summary
This was only a short introduction into pyVmomi. You should be now able to install pyVmomi, make a connection to the vSphere API and retrieve some basic stuff.
Every day I discover something new. It’s important to understand how the vSphere API works. Play with pyVmomi and with the vSphere API. It looks harder as it is.
This posting is ~7 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.
I’m not a developer. I’m an infrastructure guy. All I ever needed was to write some scripts. Therefore, I never needed more than DOS batches, BASH/ CSH/ KSH, Visual Basic Script and nowadays PowerShell. So why should I learn another programming language?
One to rule them all?
I don’t think that there is a single programming language that is perfect for all use cases. The spread and acceptance of a language shows a positive correlation with the number of available frameworks, tools and libraries. That’s why I love the Microsoft PowerShell. Nearly all vendors offer a PowerShell module for their products (think about VMware PowerCLI, Rubrik, Veeam, DataCore and much more). The downside: The PowerShell code has to run on a Windows box. I think the time of writing DOS batches is over. UNIX shell scripts are still awesome, but focused on UNIX.
Different problems require different tools. I think it’s better to know a few, general-purpose tools well, as every conceivable special tool. Don’t get me wrong: PowerShell is awesome powerful! It’s quite easy to learn and you will have quick success.
Why Python?
Python is easy to learn (I can confirm this, at least for what I’ve seen). Python was developed from scratch by Guido van Rossum in the early 1990s. Python is an interpreted and dynamic programming language, which supports multiple paradigms, like the object-oriented or the functional programming. Python features a dynamic type system and automatic memory management. It uses only 35 keywords, what makes it easy to lern. It’s underlying philosophy is The Zen of Python.
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. …
These rules lead to code with a high legibility, and it is possible to solve problems with fewer lines of code. Python is highly extensible. It comes with a large standard library and you can choose from 72.000 packages, that are available using the official 3rd party repository.
Currently, the stabled releases are 2.7 and 3.5. I recommend to start with the 3.5 release. You can get the latest release from python.org. They offer packages for Windows, MacOS X and Linux/ UNIX. Python comes with an IDE called IDLE (Integrated Development and Learning Environment). Make sure that you take a look into the official documentation! If you want something more comfortable, try JetBrain PyCharm. JetBrains offer a free community edition for Windows, MacOS X and Linux. But it’s not the worst idea to start with IDLE. I use both IDEs, IDLE and PyCharm.
Where can you get help? YouTube is full of videos about Python. If you have a Pluralsight subscription, checkout the courses on Pluralsight. There are many good books out there, as well as some good howtos. Just use Google. It depends on what type of learner you are.
Learn the basics and try to strengthen them during a small project. Buy a Raspberry Pi. Raspberry Pi and Python are the biggest friends. If you are focused on VMware vSphere, take a closer look at the VMware vSphere API Python Bindings. Create yourself a project to learn.
I just started to learn Python, but I think that this wasn’t the worst idea in my life.
This posting is ~7 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.
I’m not a developer. I deal mainly with infrastructe, things like virtualization, storage & backup, networking etc. Sometimes I had to write scripts, primarily PowerShell, batch or Bash. Many years back, I also wrote Csh and Ksh scripts. In the past years, automation was one of the rising trends in the infrastructure segment. And with automation, new challenges came up. Today I have to work with Windows PowerShell, in case of VMware with PowerCLI (which bases on Windows PowerShell), and sometimes I have use with REST APIs. I’m still not a developer. Due to this fact, I need tools that help me getting my work done.
So I was searching for a tool, mainly for PowerShell development, and I’ve tried some tools. Microsoft Visual Studio was to complex. Microsoft Visual Studio Code was light, but offered not the features I needed. The Windows integrated PowerShell ISE was nice, but it also lacked some features. So I asked on Twitter:
Recommendations for a light #PowerShell IDE? Have tried Visual Studio Code with PowerShell extension. Not my favorite… -.-
ISESteroids is not a standalone product. It’s a PowerShell module that extents the built-in PowerShell ISE. That’s nice, because you don’t have to install anything. Simply extract it. You don’t need any special privileges to install it. Load the PowerShell module, done.
ISESteroids offers a broad feature set and transforms the PowerShell ISE into a full-featured PowerShell IDE. Visit the ISESteroids homepage for a full feature list. Nothing I want to copy & paste here.
Why is ISESteroids helpful for me?
As already mentioned: I’m not a developer. Therefore, I’m thankful for all hints and tips to make my scripts better. One of the features that I noticed immediately was the light bulb on the left side of the scripting area. The icon indicates that there is an automatic fix. In my case, this is usually converting double into single quotes.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Another often mentioned fix is the replacement of aliases with the full command names. Another feature I really like is the risk analyzer. Sometimes you use commands and functions, that might not work with future releases, or which involve other risks. The risk analyzer is an easy way to highlight these risky commands and functions.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Green indicates: Everything’s fine. If something risky is found, you will get a explanation why this was marked as a risky element. If you still want to use it, you can add the marked element to a whitelist. Some risks, are not a risk at all. The risk analyzer will mark the usage of the cmdlet Move-VM as a risk. This is because cmdlets with the verb “Move” will move things. IN case of Move-VM, this is intended. That’s something you can certainly whitelists.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
One of my most used cmdlets is Get-Help. Intellisense is nice, but sometimes I have to look up the correct syntax or similar. ISESteroids offers a context sensitive help. Click on the icon with the question mark,
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
and you will see a new add-on tab on the left. Very handy. Click on a command, and the help will appear help add-on tab.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
You might notice another add-on tab in the picture above: Variables. This tab belongs to the Variables monitor, which can be useful to watch the content of variables. I use it frequently in conjunction with the debugging function.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
You can set breakpoints, add variables to the monitor and then watch the content of the variable.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
But you can also take a look at the current content of variables, in this case $VMhostScsiLunPaths.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
The last feature I’d like to show, is the AutoRefactor. Usually, I tend to follow best practices (mostly my own…) to make my scripts more “readable”. The AutoRefactor feature of ISESteroids helps me to make my scripts cleaner and more readable. It’s customizable, so I can tweak it where necessary. You can enable the refactor add-on tab by clicking the small icon with the check mark.
Patrick Terlisten/ www.vcloudnine.de/ Creative Commons CC0
Write down the code and click “Fix Script Now”. Then watch the magic. ;)
Why didn’t I highlight the other cool features, like code signing, file version control, keyboard shortcuts or test arguments? Because I’m still not a developer. The features I mentioned in this blog post are worthy enough to buy a PowerShell ISE license. Check the full feature list, download and install the trial version. I really recommend to take a look at the trial version! I was sceptical until I worked with ISESteroids. It was a great recommendation!
Licensing
ISESteroids is available in two commercial licenses:
Professional
Enterprise
The Professional license is available for 99 €, the Enterprise license costs 249 €. Latter offers more features. For individuals (natural persons), a discounted Enterprise license (99 €) is available. Startups, MVPs, trainers etc. can request a discounted license. Check the order website for more details.
To change your privacy setting, e.g. granting or withdrawing consent, click here:
Settings