lost and found ( for me ? )

Showing posts with label ESXi. Show all posts
Showing posts with label ESXi. Show all posts

ESX 5 : how to use API over http instead of https

By default , SDK port is tcp 443 ( https://vcenter IP/sdk )
Here’s an explanation of how to enable both http and https access.
When evaluating SDK , it is useful to use http instead of https to debug.

1.
access to the vCenter server

2.

go to <Drive name>:\Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter” directory

3.
edit proxy.xml file.

from

   <e id="9">
     <_type>vim.ProxyService.LocalServiceSpec</_type>
     <accessMode>httpsWithRedirect</accessMode>
     <port>8085</port>
     <serverNamespace>/sdk</serverNamespace>
   </e>


to
   <e id="9">
     <_type>vim.ProxyService.LocalServiceSpec</_type>
     <accessMode>httpAndHttps</accessMode>
     <port>8085</port>
     <serverNamespace>/sdk</serverNamespace>
   </e>


4.
restart vCenter service

5. access to http://vCenter IP/sdk

over http
root@ubuntu1204-vm1:~# python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysphere import VIServer
>>> server = VIServer()
>>> server.connect("http://1.1.1.10/sdk","username",".password.")
>>> server.get_server_type()
'VMware vCenter Server'
>>> server.get_api_version()
'5.1'
>>> server.disconnect


over https
>>> server.connect("http://1.1.1.10/sdk","username",".password.")
>>> server.get_server_type()
'VMware vCenter Server'
>>> server.disconnect

pysphere : vSphere SDK for python

http://code.google.com/p/pysphere/

[ install pysphere on Ubuntu 12.04 LTS ]


# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"

# uname -ri
3.2.0-37-virtual x86_64


the installation is very easy , just type
# easy_install -U pysphere


[ sample usage ]

connect to the ESXi not vCenter
# python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysphere import VIServer
>>> server = VIServer()
>>> server.connect("192.168.0.1","user",".Password.")


get the ESXi info
>>> print server.get_server_type()
VMware ESXi
>>> print server.get_api_version()
4.1

>>> vmlist = server.get_registered_vms()
>>> print vmlist[0]
[datastore1] CentOS6-1-32bit/CentOS6-1-32bit.vmx


retrieve VMs
>>> server.get_vm_by_name("CentOS6-1-32bit")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python2.7/dist-packages/pysphere-0.1.7-py2.7.egg/pysphere/vi_server.py", line 323, in get_vm_by_name
   FaultTypes.OBJECT_NOT_FOUND)
pysphere.resources.vi_exception.VIException: [Object Not Found]: Could not find a VM named 'CentOS6-1-32bit'


if you see the above error , connect to the ESXi again.
>>> server.connect("192.168.0.1","user",".Password.")

>>> server.get_vm_by_path("[datastore1] CentOS6-1-32bit/CentOS6-1-32bit.vmx")
<pysphere.vi_virtual_machine.VIVirtualMachine instance at 0x3cffd88>

>>> vm1 = server.get_vm_by_path("[datastore1] CentOS6-1-32bit/CentOS6-1-32bit.vm
x")

>>> vmlist[1]
'[datastore1] CentOS6-1-64bit/CentOS6-1-64bit.vmx'
>>> vm2 = server.get_vm_by_name("CentOS6-1-64bit")


check the status of the VM
>>> print vm1.get_status(basic_status=True)
POWERED OFF

>>> print vm1.is_powering_on()
False

>>> vm1.get_properties()
{'files': {0: {'type': 'diskDescriptor', 'name': '[datastore1] CentOS6-1-32bit/CentOS6-1-32bit.vmdk', 'key': 0, 'size': 499}, 1: {'type': 'diskExtent', 'name': '[datastore1] CentOS6-1-32bit/CentOS6-1-32bit-flat.vmdk', 'key': 1, 'size': 10737418240}, 2: {'type': 'log', 'name': '[datastore1] CentOS6-1-32bit/vmware-1.log'
<snip>

>>> print vm1.get_property('guest_id')
rhel6Guest


power on the VM
>>> vm1.get_status()
'POWERED OFF'

>>> vm1.power_on()

>>> vm1.get_status()
'POWERED ON'


suspend / shutdown the VM
>>> vm1.get_status()
'POWERED ON'
>>> vm1.suspend()
>>> vm1.get_status()
'SUSPENDED'
>>> vm1.power_on()
>>> vm1.get_status()
'POWERED ON'
>>> vm1.power_off()
>>> vm1.get_status()
'POWERED OFF'


disconnect
>>> server.disconnect()

How to have Solaris 10 x86 VM running within ESXi recognize vNICs

I’ve installed Solaris 10 on ESXi as a virtual machine.
# uname –a
SunOS unknown 5.10 Generic_147441-01 i86pc i386 i86pc

After finishing the installation , I added two additional vNICs to the VM.
However Solaris VM does not seem to recognize vNICs I added to the VM.

The VM has totally three vNICs ( driver is e1000 )
e1000g0 is the vNIC I added when installing Solaris.
# ifconfig  e1000g0
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2
       inet 192.168.11.215 netmask ffffff00 broadcast 192.168.11.255
       ether aa:aa

There are no two vNICs I added to the VM after the installation
bash-3.2# ifconfig  e1000g1
ifconfig: status: SIOCGLIFFLAGS: e1000g1: no such interface
bash-3.2# ifconfig  e1000g2
ifconfig: status: SIOCGLIFFLAGS: e1000g2: no such interface

dmesg
bash-3.2# dmesg | grep e1000g | grep register
Dec 26 22:37:06 unknown mac: [ID 469746 kern.info] NOTICE: e1000g0 registered
Dec 26 22:37:37 unknown mac: [ID 469746 kern.info] NOTICE: e1000g1 registered
Dec 26 22:37:37 unknown mac: [ID 469746 kern.info] NOTICE: e1000g2 registered
Dec 26 22:37:59 unknown mac: [ID 736570 kern.info] NOTICE: e1000g1 unregistered
Dec 26 22:37:59 unknown mac: [ID 736570 kern.info] NOTICE: e1000g2 unregistered

check “/etc/path_to_inst” file
bash-3.2# egrep e1000 /etc/path_to_inst
"/pci@0,0/pci15ad,790@11/pci15ad,750@0" 0 "e1000g"
"/pci@0,0/pci15ad,790@11/pci15ad,750@2" 1 "e1000g"
"/pci@0,0/pci15ad,790@11/pci15ad,750@3" 2 "e1000g"

Seen from the logs , the VM seems to recognize vNICs at the hardware level.

enable e1000g1 and e1000g2 with ifconfig.
bash-3.2# ifconfig e1000g1 plumb
bash-3.2# ifconfig e1000g2 plumb

The VM has recognized all vNICs
bash-3.2# ifconfig e1000g1
e1000g1: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
       inet 0.0.0.0 netmask 0
       ether zz:zz

bash-3.2# ifconfig e1000g2
e1000g2: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
       inet 0.0.0.0 netmask 0
       ether zz:zz


Seen from the man of “ifconfig” , it describes :
    plumb

        Open the device associated with the  physical  interface
        name  and  set  up  the streams needed for IP to use the
        device. When used with a logical  interface  name,  this
        command  is  used  to  create  a  specific named logical
        interface. An interface must be separately  plumbed  for
        use  by IPv4 and IPv6. The address_family parameter con-
        trols whether the ifconfig command applies  to  IPv4  or
        IPv6.

        Before an interface has been plumbed, the interface will
        not show up in the output of the ifconfig -a command.

ESXi : install CentOS automatically with kickstart


[ prepare kickstart file ]

I made a kickstart file using system-config-kickstart.

install system-config-kickstart via yum.
# yum install –y system-config-kickstart.noarch

make a kickstart file with system-config-kickstart
# system-config-kickstart

GUI will appear like this:

configure installation settings step by step with system-config-kickstart.

Here’s an example ks file of CentOS5.6 which I created with system-config-kickstart.
# cat centos5-6.ks.cfg
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --append="console=ttyS0,115200n8 console=tty0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard jp106
# System language
lang ja_JP
# Installation logging level
logging --level=info
# Use CDROM installation media
cdrom
# Network information
network --bootproto=static --device=eth0 --gateway=192.168.11.254 --ip=192.168.11.160 --nameserver=192.168.11.15 --netmask=255.255.255.0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$3QEuw1wV$VUKWhr1WZ1SAUXNVFv7Jk.

# SELinux configuration
selinux --disabled
# System timezone
timezone --isUtc Asia/Tokyo
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig  --defaultdesktop=GNOME --depth=8 --resolution=640x480
# Disk partitioning information
part / --bytes-per-inode=4096 --fstype="ext3" --size=5000
part swap --bytes-per-inode=4096 --fstype="swap" --size=512

%packages
@development-libs
@development-tools
@editors


[ make an ISO image including a ks file ]

mount original CentOS ISO.
# mount -t iso9660 -o loop CentOS-5.6-x86_64-bin-DVD-1of2.iso /media/cdrom/

copy ISO files to an another directory.( /root/CentOS.5.6_Custom )
# cd /media/cdrom/
# mkdir /root/CentOS5.6_Custom

# pwd
/media/cdrom
# tar cf - . | (cd /root/CentOS5.6_Custom; tar xfp -)

copy ks file ( name a ks file you made “ks.cfg” )
# cp /root/centos5-6.ks.cfg /root/CentOS5.6_Custom/ks.cfg

build a customized ISO.
# pwd
/root/CentOS5.6_Custom

# mkisofs -o /root/CentOS5.6_x86_64_custom.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "CetnOS 5.6 Custom ISO"

# file /root/CentOS5.6_x86_64_custom.iso
/root/CentOS5.6_x86_64_custom.iso: # ISO 9660 CD-ROM filesystem data 'CDROM                          ' (bootable)

confirm you can mount customized ISO and confirm there’s ks.cfg into that ISO.
# mount -t iso9660 -o loop CentOS5.6_x86_64_custom.iso /root/aaa

# head -5 /root/aaa/ks.cfg
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --append="console=ttyS0,115200n8 console=tty0" --location=mbr

[ install CentOS as a VM using customized ISO on ESXi ]

start a VM from CentOS5.6_x86_64_custom.iso and then specify “linux ks=cdrom:/ks.cfg” as below.

installation has been processed automatically.

With this ks file , after finishing the installation , rebooting system automatically.

I could install CentOS automatically :)