85
Managing VMware Infrastructure using VMware APIs VMworld Barcelona 2012

Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

  • Upload
    lykhanh

  • View
    251

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Managing VMware Infrastructure

using VMware APIs

VMworld Barcelona 2012

Page 2: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

`whoami`

Basics

24h managing a VMware

Infrastructure Real use cases compiled in a day

Page 3: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

`whoami`

Page 4: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Francois Loiseau VCP5

SysAdmin

R&D & Cloud

Page 5: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

OVH Big VMware infrastructures

High automation level

Page 6: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 7: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware Users

Linux / Windows / Solaris / …

Web team

Dev team

Customers

Sysadmins

Page 8: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware Administrator Linux / Windows

VMware world

Storage: Storage Team

Network: Network Team

Security: Security Team (Quality)

VMware administrators to serve the company

Page 9: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware Infrastructures Self provisionned

Internal cloud

Customer provisonned vSphere As A Service

privateCloud hosting

Page 10: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware APIs vSphere

Perl / Java / powerCli

vCloud REST

Several ways to do it

Page 11: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware vSphere SDK for Perl Any platform

Download from: http://www.vmware.com/support/pubs/sdk_pubs.html

Untar and copy: vmware-vsphere-cli-distrib/lib/VMware/share/VMware

To: /usr/local/lib/perl/5.10.0/

Page 12: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Connexion sample #!/usr/bin/perl use strict; use Data::Dumper; use VMware::VIRuntime; # Auth options Opts::set_option('server', ‘myvCenter'); Opts::set_option('username', ‘myUser'); Opts::set_option('password', ‘myPassw0rd!'); print "Connecting \n"; Util::connect(); print "Connected \n"; # # [ We’ll make actions there ] # Util::disconnect(); print "Disconnected \n";

Page 13: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 14: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

9’ AM Network team alerts

Sep 20 08:59:44 sw1.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po30 and port Po31 Sep 20 08:59:44 sw1.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po30 and port Po31 Sep 20 08:59:44 sw1.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po31 and port Po30 Sep 20 08:59:44 sw2.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po31 and port Po30 Sep 20 08:59:44 sw2.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po30 and port Po31 Sep 20 08:59:44 sw1.corp : 2012 Sep 20 08:59:21 CEST: %FWM-6-MAC_MOVE_NOTIFICATION: Host 0050.5612.1234 in vlan 1111 is flapping between port Po31

Page 15: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Quick diagnosis

HA Failure VM powered on 2 hosts

Same mac set on both VMs ? Both VMs ?

Page 16: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Quick diagnosis

Vlan segmentation / CMDB vcenter201

Page 17: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 18: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly my $mac = "00:50:56:12:12:34"; my $DatacenterView = Vim::find_entity_view( 'view_type' => 'Datacenter', 'filter' => { 'name' => 'myDatacenter', } ); my $VMViews = Vim::find_entity_views( 'view_type' => 'VirtualMachine', 'begin_entity' => $DatacenterView, ); foreach my $VMView (@$VMViews) { foreach my $Device (@{$VMView->config->hardware->device}) { if(exists $Device->{'macAddress'} and $Device->{'macAddress'} eq $mac) { print $VMView->summary->config->name . “\n”; } } }

Page 19: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Connecting Connected Getting Datacenter view Got Datacenter View Web001 Web123 Disconnected

Let us find it quickly

Page 20: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 21: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

10’AM Storage maintenance planed

Storage team question : « May I shut this LUN tomorrow ?

I need to rack this SAN somewhere else. »

Page 22: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VM running on this Datastore solved

Page 23: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Next?

Iso from this datastore not used anymore?

Page 24: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Quick diagnosis Storage definition / CMDB

vcenter197

vcenter134

vcenter026

Page 25: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 26: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly my $DatacenterView = Vim::find_entity_view( 'view_type' => 'Datacenter', 'filter' => { 'name' => 'myDatacenter', } ); my $VMViews = Vim::find_entity_views( 'view_type' => 'VirtualMachine', 'begin_entity' => $DatacenterView , 'properties' => [ 'config.hardware.device', 'summary.config.name', ] ); my $datastore = "templates"; foreach my $VMView (@{ $VMViews }) { foreach my $Device (@{$VMView->{'config.hardware.device'}}) { if (ref( $Device ) eq "VirtualCdrom") { if ($Device->deviceInfo->summary =~ /^ISO/ && $Device->deviceInfo->summary =~ $datastore) { print $VMView->{'summary.config.name'} . “ is using “ . $Device->deviceInfo->summary . “\n”;

} } } }

Page 27: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly vCenter134 Connecting Connected Getting Datacenter view Got Datacenter View vpn-upgrade is using ISO [templates] iso/RIPLinux-11.3-non-X.iso share is using ISO [templates] iso/gparted-live-0.7.1-1.iso Oracle-11g-1b is using ISO [templates] iso/oracleLinux32.iso Disconnected

vCenter197 Connecting Connected Getting Datacenter view Got Datacenter View Disconnected

vCenter026 Connecting Connected Getting Datacenter view Got Datacenter View Disconnected

Page 28: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Win

\o/

Page 29: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

2’ PM

Security team email : « Dear administrators,

We are suspecting unauthorized access

to our infrastructures last 3 months.

Could you please send us

all authentifications / login on VMware

front based on this template:

Date ; User ; IP From.»

Page 30: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Database retention policy

Page 31: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly

# Getting Event Manager my $EventManager = Vim::get_view('mo_ref' => Vim::get_service_content()->eventManager); my $EventFilterSpecByEntity = EventFilterSpecByEntity->new( 'entity' => Vim::get_service_content()->rootFolder(), 'recursion' => EventFilterSpecRecursionOption->new('all'), ); my $EventFilterSpec = EventFilterSpec->new( 'entity' => $EventFilterSpecByEntity, ); my $EventHistoryCollector = $EventManager->CreateCollectorForEvents('filter' => $EventFilterSpec);

Page 32: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly

my $biggestEventChainId = 0 ; while(1) { my $EventHistoryCollectorView = Vim::get_view('mo_ref' => $EventHistoryCollector); my @latestPage = @{ $EventHistoryCollectorView->latestPage }; for (my $eventId = scalar @latestPage ; $eventId >= 0 ; $eventId--) { my $createdTime = exists ( $latestPage[$eventId]->{'createdTime'} ) ? getDate($latestPage[$eventId]->createdTime) : "X"; my $username = exists ( $latestPage[$eventId]->{'userName'}) ? $latestPage[$eventId]->userName : "X"; my $fullFormattedMsg = exists ( $latestPage[$eventId]->{'fullFormattedMessage'} ) ? encode('UTF8' ,$latestPage[$eventId]->fullFormattedMessage) : "X"; my $task = exists ( $latestPage[$eventId]->{'info'}->{'task'}->{'value'} ) ? $latestPage[$eventId]->info->task->value : "X"; my $status = exists ( $latestPage[$eventId]->{'info'}->{'state'}->{'val'}) ? $latestPage[$eventId]->info->state->val : "X"; my $eventChainId = exists ( $latestPage[$eventId]->{'chainId'} ) ? $latestPage[$eventId]->chainId : "X"; if ($eventChainId > $biggestEventChainId) { chomp($fullFormattedMsg); print $createdTime . "|" . $fullFormattedMsg . "|" . $task . "|" . $username . "|" . $status . "\n" ; $biggestEventChainId = $eventChainId; } } }

Page 33: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

On Syslog

Fri Sep 12 11:22:42 2012|vcenter012|Fri Sep 12 11:22:42 2012|User John logged out|X|John|X Fri Sep 12 11:23:52 2012|vcenter012|Fri Sep 12 11:23:52 2012|User [email protected] logged in|X|John|X Fri Sep 12 11:23:52 2012|vcenter012|Fri Sep 12 11:23:52 2012|User John logged out|X|John|X Fri Sep 12 11:25:33 2012|vcenter012|Fri Sep 12 11:25:33 2012|User Corp\[email protected] logged in|X|vscope|X Fri Sep 12 11:25:59 2012|vcenter012|Fri Sep 12 11:25:59 2012|User [email protected] logged in|X|Franck|X Fri Sep 12 11:26:02 2012|vcenter012|Fri Sep 12 11:26:02 2012|User [email protected] logged in|X|John|X Fri Sep 12 11:26:02 2012|vcenter012|Fri Sep 12 11:26:02 2012|User John logged out|X|John|X

Page 34: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly

# Getting Task Manager my $TaskManagerView = Vim::get_view('mo_ref' => Vim::get_service_content()->taskManager); my $TaskFilterSpecByEntity = TaskFilterSpecByEntity->new( 'entity' => Vim::get_service_content()->rootFolder(), 'recursion' => TaskFilterSpecRecursionOption->new('all'), ); my $TaskFilterSpec = TaskFilterSpec->new( 'entity' => $TaskFilterSpecByEntity, ); my $TaskHistoryCollector = $TaskManagerView->CreateCollectorForTasks( 'filter' => $TaskFilterSpec );

Page 35: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly my $biggestTaskChainId = 0 ; while (1) { my $TaskHistoryCollectorView = Vim::get_view('mo_ref' => $TaskHistoryCollector); my @latestPage = @{ $TaskHistoryCollectorView->latestPage }; for (my $taskId = scalar @latestPage ; $taskId >= 0 ; $taskId--) { my $startTime = exists ( $latestPage[$taskId]->{'startTime'} ) ? getDate($latestPage[$taskId]->startTime) : "X"; my $completeTime = exists ( $latestPage[$taskId]->{'completeTime'} ) ? getDate($latestPage[$taskId]->completeTime) : "X"; my $entityName = exists ( $latestPage[$taskId]->{'entityName'} ) ? $latestPage[$taskId]->entityName : "X"; my $eventChainId = exists ( $latestPage[$taskId]->{'eventChainId'} ) ? $latestPage[$taskId]->eventChainId : "X"; my $task = exists ( $latestPage[$taskId]->{'task'}->{'value'} ) ? $latestPage[$taskId]->task->value : "X"; my $name = exists ( $latestPage[$taskId]->{'name'}) ? $latestPage[$taskId]->name : "X"; my $descriptionId = exists ( $latestPage[$taskId]->{'descriptionId'} ) ? $latestPage[$taskId]->descriptionId : "X"; my $username = exists ( $latestPage[$taskId]->{'reason'}->{'userName'}) ? $latestPage[$taskId]->reason->userName : "X"; my $status = exists ( $latestPage[$taskId]->{'state'}->{'val'}) ? $latestPage[$taskId]->state->val : "X"; if ($eventChainId > $biggestTaskChainId) { print $startTime . "|" . $completeTime . "|" . $task . "|" . $entityName . "|" . $name . "|" . $descriptionId . "|" . $username . "|" . $status . "\n" ; $biggestTaskChainId = $eventChainId; }

} }

Page 36: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

On Syslog

Fri Sep 12 06:51:05 2012|vcenter012|Fri Sep 12 06:51:05 2012|Fri Sep 12 06:51:06 2012|task-13515|Centres de données|X|com.vmware.vcIntegrity.CheckNotificationTask|X|success Fri Sep 12 07:01:19 2012|vcenter012|Fri Sep 12 07:01:19 2012|Fri Sep 12 07:01:28 2012|task-13516|nas-001223|RefreshDatastoreStorageInfo|Datastore.refreshStorageInfo|Franck|success Fri Sep 12 07:10:55 2012|vcenter012|Fri Sep 12 07:10:55 2012|Fri Sep 12 07:10:57 2012|task-13517|nas-000268|RefreshDatastoreStorageInfo|Datastore.refreshStorageInfo|Franck|success Fri Sep 12 11:26:16 2012|vcenter012|Fri Sep 12 11:26:16 2012|Fri Sep 12 11:26:16 2012|task-13525|Datacenter-RBX|PowerOnMultiVM_Task|Datacenter.powerOnVm|John|success Fri Sep 12 11:26:24 2012|vcenter012|Fri Sep 12 11:26:24 2012|Task: Reconfigure virtual machine|task-13527|John|queued Fri Sep 12 11:26:24 2012|vcenter012|Fri Sep 12 11:26:24 2012|X|task-13527|NFS-99|ReconfigVM_Task|VirtualMachine.reconfigure|John|running Fri Sep 12 11:26:39 2012|vcenter012|Fri Sep 12 11:26:39 2012|X|task-13528|Oracle12-1b|PowerOffVM_Task|VirtualMachine.powerOff|John|running Fri Sep 12 11:26:59 2012|vcenter012|Fri Sep 12 11:26:59 2012|X|task-13529|Oracle12-1b|Destroy_Task|VirtualMachine.destroy|John|running

Page 37: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Win

\o/

Page 38: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

4’ PM

Web team post-production challenges All VMs with snapshots

Page 39: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Quick diagnosis Storage definitions / CMDB

vCenter definitions vcenter201

vcenter035

vcenter138

Page 40: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

My tought Get on all web team Filers vmdk & date

List all VMs

find /directory-* |grep .vmdk|grep 0000 |nawk '{FS="\n" ; print $1}' |xargs -i ls -al {}

Page 41: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 42: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly my $DatacenterView = Vim::find_entity_view( 'view_type' => 'Datacenter', 'filter' => { 'name' => 'myDatacenter', } ); my $VMViews = Vim::find_entity_views( 'view_type' => 'VirtualMachine', 'begin_entity' => $DatacenterView , ); my $listVm; my $snapshots; my $ret; foreach my $VMView (@$VMViews) { # Checking if VM got at least 1 snapshot if ($VMView->snapshot) { foreach my $snap (@{$VMView->snapshot->rootSnapshotList}) { $ret = _getAllSnapshots( 'snap' => $snap , 'snapshots' => $snapshots ); $listVm->{$VMView->name} = $ret; } } } print Dumper $listVm;

Page 43: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

# Recursive Sub to list all snaps sub _getAllSnapshots { my %params = @_; my $snap = $params{'snap'}; my $snapshots = $params{'snapshots'}; my ($date1,$date2)= split /T/, $snap->createTime; my ($year,$mon,$day) = split /-/, $date1; my ($hrs,$min,$sec ) = split /:/, $date2; my $createdTime = timegm($sec, $min, $hrs, $day, $mon-1, $year-1900); # filling result my $snapHash = { 'name' => $snap->name , 'date' => $createdTime, 'desc' => $snap->description }; push @$snapshots , $snapHash; # and go on if ($snap->childSnapshotList) { foreach my $snapChild (@{$snap->childSnapshotList}) { my $ret = _getAllSnapshots('snap' => $snapChild , 'snapshots' => $snapshots);

} } return $snapshots; }

Page 44: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let us find it quickly Connecting Connected Getting Datacenter view Got Datacenter View $VAR1 = { ‘Web142' => [ { 'desc' => ‘Before Uprgade', 'date' => 1317970514, 'name' => ‘snap1' }, ], ‘Web212' => [ { 'desc' => ‘Before Uprgade', 'date' => 1317970632, 'name' => ‘snap1' }, ], ‘Web123' => [ { 'desc' => ‘Before Uprgade', 'date' => 1317970312, 'name' => ‘snap1' }, ], }; Disconnected

Page 45: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Win

\o/

Page 46: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

5’ PM Customer request

« Notify me on what’s going on my infrastructure »

Page 47: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Solutions

Send email ?

Syslog ?

Page 48: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let do this

my $msg = ‘User John created on this vCenter. Access has been granted to this Datacenter. We are going to log everything’; my $EventManager = Vim::get_view( 'mo_ref' => Vim::get_service_content()->eventManager ); $EventManager->LogUserEvent( 'entity' => $DatacenterView, 'msg' => $msg );

Page 49: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 50: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Win

\o/

Page 51: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

11’ PM Host Failure

Page 52: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 53: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 54: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 55: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Host 192.168.2.51 pings Failed to ping HARDWARE DRS TRIGGERED Getting Host spare Adding VMKernel Adding Host to inventory Adding networks Adding filers Done

Page 56: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 57: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

my $host = "192.168.2.51"; eval { my $ping = 1; while ($ping) { `/bin/ping -c 1 $host`; if ($? != 0) { $ping = 0; last; } sleep 1; print "Host $host pings\n"; } alarm(0); }; print "Failed to ping\n"; print "Getting Hosts spare \n ";

Detection

Howto ?

Page 58: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Adding IP to Host

Howto ?

my $vmkernelIp = "192.168.2.53"; my $vmkernelNetmask = "255.255.254.0"; my $vlanId = "1234"; my $HostSystemView = Vim::find_entity_view( 'view_type' => 'HostSystem' ); my $NetworkSystemView = Vim::get_view( 'mo_ref' => $HostSystemView->configManager->networkSystem ); my $HostPortGroupSpec = HostPortGroupSpec->new( 'name' => "VMKernel", 'vlanId' => $vlanId, 'vswitchName' => "vSwitch0", 'policy' => HostNetworkPolicy->new(), ); $NetworkSystemView->AddPortGroup( 'portgrp' => $HostPortGroupSpec );

Page 59: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Adding IP to Host

Howto ?

my $HostIpConfig = HostIpConfig->new( 'dhcp' => 'false', 'ipAddress' => $vmkernelIp, 'subnetMask' => $vmkernelNetmask ); my $HostVirtualNicSpec = HostVirtualNicSpec->new( 'ip' => $HostIpConfig, ); my $vnic = $NetworkSystemView->AddVirtualNic( 'portgroup' => "VMKernel", 'nic' => $HostVirtualNicSpec ); my $HostVirtualNicManager = Vim::get_view( 'mo_ref' => $HostSystemView->configManager->virtualNicManager ); $HostVirtualNicManager->SelectVnicForNicType( 'nicType' => 'vmotion', 'device' => $vnic );

Page 60: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

my $DatacenterView = Vim::find_entity_view( 'view_type' => 'Datacenter', 'filter' => { 'name' => "Rbx" } ); my $ClusterView = Vim::find_entity_view( 'view_type' => 'ClusterComputeResource', 'begin_entity‘ => $DatacenterView, 'filter' => { 'name' => "Cluster001" } ); $hostConnectSpec = HostConnectSpec->new( 'force' => 1, 'hostName' => $vmkernelIp, 'userName' => $hostUsername, 'password' => $hostPassword, 'sslThumbprint' => $thumbprint, ); $ClusterView->AddHost_Task( 'spec' => $hostConnectSpec, 'asConnected' => 1, 'license' => $licenseKey );

Adding Host

Howto ?

Page 61: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

my $HostViews = Vim::find_entity_views( 'view_type' => 'HostSystem', 'begin_entity' => $DatacenterView ); my $DatastoreSystemView = Vim::get_view( 'mo_ref' => $HostView->configManager->datastoreSystem, ); my $HostNasVolumeSpec = HostNasVolumeSpec->new( 'accessMode' => 'readWrite', 'localPath' => nas-000357, 'remoteHost' => '192.168.2.10', 'remotePath' => ‘/share/nas-000357', 'type' => 'NFS' ); $DatastoreSystemView->CreateNasDatastore( 'spec' => $HostNasVolumeSpec );

Adding storage

Howto ?

Page 62: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

my $HostSystemView = Vim::find_entity_view( 'view_type' => 'HostSystem', 'filter' => {'name' => "192.168.2.53",}, ); my $HostSystemView = Vim::find_entity_view( 'view_type' => 'HostSystem' ); my $NetworkSystemView = Vim::get_view( 'mo_ref' => $HostSystemView->configManager->networkSystem, ); my $HostPortGroupSpec = HostPortGroupSpec->new( 'name' => "vlanXXX", 'vlanId' => 1234, 'vswitchName' => "vSwitch0", 'policy' => HostNetworkPolicy->new(), ); $NetworkSystemView->AddPortGroup( 'portgrp' => $HostPortGroupSpec );

Adding vlans

Howto ?

Page 63: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Win

\o/

Page 64: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

2’ AM vCenter crash

Alert received

Page 65: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

vCenter logs

Quick diagnosis

Panic: Win32 exception: Access Violation (0xc0000005) Read (0) at address 0000000000000098 Panic: Assert Failed: "openedInfo._activations == 0" @ d:/build/ob/bora-340981/bora/vim/lib/vimutil/view/multiContainerView.cpp:123 Backtrace: backtrace[00] rip 000000018010a8aa Vmacore::System::Stacktrace::CaptureWork backtrace[01] rip 00000001800e8008 Vmacore::System::SystemFactoryImpl::CreateFileWriter backtrace[02] rip 00000001800e84fe Vmacore::System::SystemFactoryImpl::CreateQuickBacktrace backtrace[03] rip 0000000180129ba5 Vmacore::PanicExit backtrace[04] rip 0000000180129cb1 Vmacore::PanicExit backtrace[05] rip 000000018007669e Vmacore::RunTimeFailure backtrace[06] rip 000000013fddd883 (no symbol) backtrace[07] rip 000000013fdcae13 (no symbol) backtrace[08] rip 0000000000eef1e1 Vim::View::ListView::_GetType backtrace[09] rip 0000000000358d9c Vmomi::RuntimeFault::_GetDataType backtrace[10] rip 000000014044cf6f (no symbol) backtrace[11] rip 000000014042a672 (no symbol) backtrace[12] rip 0000000140430a08 (no symbol) backtrace[13] rip 000000018011f68d Vmacore::System::IsEnlisted backtrace[14] rip 0000000180120a6f Vmacore::System::IsEnlisted backtrace[15] rip 0000000180119df5 Vmacore::System::ThisThreadExists backtrace[16] rip 0000000073562fdf endthreadex backtrace[17] rip 0000000073563080 endthreadex backtrace[18] rip 00000000777bf56d BaseThreadInitThunk backtrace[19] rip 00000000779f3281 RtlUserThreadStart [2012-04-13 02:35:32.385 05324 panic 'App' opID=50E97826-00000154] Assert Failed: "openedInfo._activations == 0" @ d:/build/ob/bora-340981/bora/vim/lib/vimutil/view/multiContainerView.cpp:123

Page 66: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

More verbose ?

Quick diagnosis

C:\Users\All Users\VMware\VMware VirtualCenter\vpxd.cfg <log> <level>trivia</level> </log>

Page 67: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Looks better ... :)

Quick diagnosis

Panic: Win32 exception: Access Violation (0xc0000005) Read (0) at address 0000000000000098 Panic: Assert Failed: "openedInfo._activations == 0" @ d:/build/ob/bora-340981/bora/vim/lib/vimutil/view/multiContainerView.cpp:123 Backtrace: backtrace[00] rip 000000018010a8aa Vmacore::System::Stacktrace::CaptureWork backtrace[01] rip 00000001800e8008 Vmacore::System::SystemFactoryImpl::CreateFileWriter backtrace[02] rip 00000001800e84fe Vmacore::System::SystemFactoryImpl::CreateQuickBacktrace backtrace[03] rip 0000000180129ba5 Vmacore::PanicExit backtrace[04] rip 0000000180129cb1 Vmacore::PanicExit backtrace[05] rip 000000018007669e Vmacore::RunTimeFailure backtrace[06] rip 000000013fddd883 (no symbol) backtrace[07] rip 000000013fdcae13 (no symbol) backtrace[08] rip 0000000000eef1e1 Vim::View::ListView::_GetType backtrace[09] rip 0000000000358d9c Vmomi::RuntimeFault::_GetDataType backtrace[10] rip 000000014044cf6f (no symbol) backtrace[11] rip 000000014042a672 (no symbol) backtrace[12] rip 0000000140430a08 (no symbol) backtrace[13] rip 000000018011f68d Vmacore::System::IsEnlisted backtrace[14] rip 0000000180120a6f Vmacore::System::IsEnlisted backtrace[15] rip 0000000180119df5 Vmacore::System::ThisThreadExists backtrace[16] rip 0000000073562fdf endthreadex backtrace[17] rip 0000000073563080 endthreadex backtrace[18] rip 00000000777bf56d BaseThreadInitThunk backtrace[19] rip 00000000779f3281 RtlUserThreadStart [2012-04-13 02:42:32.385 05324 panic 'App' opID=50E97826-00000154] Assert Failed: "openedInfo._activations == 0" @ d:/build/ob/bora-340981/bora/vim/lib/vimutil/view/multiContainerView.cpp:123

Page 68: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Help ? Google

kb.vmware.com

=> S/R my.vmware.com

Page 69: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Solution Quick, easy and efficient

vpxd.exe -b

Page 70: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Cool?

Page 71: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Quick diagnosis CMDB

Storage definitions

vCenter defintions

Hosts definitions

Page 72: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let’s do it

Page 73: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 74: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 75: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 76: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 77: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 78: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Let’s do it I got Redis that is a Folder Working on vmAndTemplates we are on a root context Entity is neither host neither vm neither datastore - _whatToDoWithContextAndPathForThisEntity I have to create a container (Folder) named Redis in vmAndTemplates (root) -> vmAndTemplates –

_whatToDoWithContextAndPathForThisEntity Directly creating Folder in vmAndTemplates Finding view of entity Folder, named Redis beginning from vm done Applying alarms No alarms on this entity, skipping Now, looking at what's inside Folder Redis I got, from this at root, 4 direct entity I have to move a vm named redis100 in Redis (Folder) in path vmAndTemplates/Redis

moving vm into Redis context is Folder Task to move redis100 into Redis (vmAndTemplates/Redis) started Applying alarms No alarms on this entity, skipping VM moved I have to move a vm named redis101 in Redis (Folder) in path vmAndTemplates/Redis moving vm into Redis context is Folder Task to move redis101 into Redis (vmAndTemplates/Redis) started Applying alarms No alarms on this entity, skipping VM moved I have to move a vm named redis102 in Redis (Folder) in path vmAndTemplates/Redis

moving vm into Redis context is Folder Task to move redis102 into Redis (vmAndTemplates/Redis) started Applying alarms No alarms on this entity, skipping VM moved I have to move a vm named redis103 in Redis (Folder) in path vmAndTemplates/Redis

moving vm into Redis context is Folder Task to move redis103 into Redis (vmAndTemplates/Redis) started Applying alarms No alarms on this entity, skipping VM moved I got SMTP that is a Folder

Page 79: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Finding view of entity ResourcePool, named prod beginning from Web done Applying alarms No alarms on this entity, skipping Now, looking at what's inside ResourcePool prod I got, from this at root, 2 direct entity Entity is neither host neither vm neither datastore - _whatToDoWithContextAndPathForThisEntity I have to create a container (ResourcePool) named Front in prod (ResourcePool) -> hostsAndClusters/Cluster001/Web/prod - _whatToDoWithContextAndPathForThisEntity

Using Pool prod I have to move a vm named web1057 in Front (ResourcePool) in path hostsAndClusters/Cluster001/Web/prod/Front I have to move a vm named web1058 in Front (ResourcePool) in path hostsAndClusters/Cluster001/Web/prod/Front moving vm into Front context is ResourcePool Task to move web1058 into Front (hostsAndClusters/Cluster001/Web/prod/Front) started Applying alarms No alarms on this entity, skipping VM moved I have to move a vm named web1055 in Front (ResourcePool) in path hostsAndClusters/Cluster001/Web/prod/Front moving vm into Front context is ResourcePool Task to move web1055 into Front (hostsAndClusters/Cluster001/Web/prod/Front) started Applying alarms No alarms on this entity, skipping VM moved I have to move a vm named web1040 in Front (ResourcePool) in path hostsAndClusters/Cluster001/Web/prod/Front moving vm into Front context is ResourcePool Task to move web1040 into Front (hostsAndClusters/Cluster001/Web/prod/Front) started Applying alarms No alarms on this entity, skipping

Page 80: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 81: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)
Page 82: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Snapshot vCenter

Takes alarms set up on entities

Takes config of Pools / Clusters / vApps

Inventory hierarchy Folder / Clusters / Pools / vApps

All entities

Page 83: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Snapshot vCenter - alarms: [] config: !!perl/hash:ResourceConfigSpec cpuAllocation: !!perl/hash:ResourceAllocationInfo expandableReservation: 1 limit: -1 reservation: 1125 shares: !!perl/hash:SharesInfo level: !!perl/hash:SharesLevel val: normal shares: 4000 memoryAllocation: !!perl/hash:ResourceAllocationInfo expandableReservation: 1 limit: -1 reservation: 125 shares: !!perl/hash:SharesInfo level: !!perl/hash:SharesLevel val: normal shares: 163840 name: Internal type: ResourcePool childs: - alarms: [] config: vmx: '[nas-000357] web100/web100.vmx' name: web100 type: vm values: [] - alarms: [] config: vmx: '[nas-000357] web101/web101.vmx' name: web101 type: vm values: []

Page 84: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

VMware Solution

My own experience

Bring added value

Page 85: Managing VMware Infrastructure using VMware APIs - … · VMware Administrator Linux / Windows VMware world Storage: Storage Team Network: Network Team Security: Security Team (Quality)

Questions ?

Download this presentation on www.ovh.com/vmworld