Archive

Posts Tagged ‘sysadmin’

CloudForms VMware Tools Upgrade method

May 14th, 2015 No comments

I wrote a method a while back to allow me to upgrade VMware tools from within the CloudForms interface. I thought I would share it. I usually create a VM button to call the method, but it could probably be used elsewhere with some tweaking.

For the button, create it with System/Process/Request, Message create and Request upgrade_vmware_tools.

Screen Shot 2015-05-14 at 10.31.33 AM

Next, create an instance under /System/Process/Request called upgrade_vmware_tools that has a relationship field pointing to the location of your method. In my case, I chose /Infrastructure/VM/Operations/Methods/upgrade_vmware_tools

Screen Shot 2015-05-14 at 10.32.56 AM

Finally, you can create your instance and method.

Screen Shot 2015-05-14 at 10.33.32 AM

Here’s the code for what I wrote:

###################################
#
# CFME Automate Method: upgrade_vmware_tools
#
# Inputs: $evm.root['vm']
#
###################################
begin
  # Method for logging
  def log(level, message)
    @method = 'upgrade_vmware_tools'
    $evm.log(level, "#{@method} - #{message}")
  end
 
  def dump_attributes(my_object, my_object_name)
    $evm.log(:info, "Begin #{my_object_name}.attributes")
    my_object.attributes.sort.each { |k, v| $evm.log(:info, "#{my_object_name} Attribute - #{k}: #{v}")}
    $evm.log(:info, "End #{my_object_name}.attributes")
    $evm.log(:info, "")
  end
 
  def dump_associations(my_object, my_object_name)
    $evm.log(:info, "Begin #{my_object_name}.associations")
    my_object.associations.sort.each { |a| $evm.log(:info, "#{my_object_name} Association - #{a}")}
    $evm.log(:info, "End #{my_object_name}.associations")
    $evm.log(:info, "")
  end
 
  def dump_virtual_columns(my_object, my_object_name)
    $evm.log(:info, "Begin #{my_object_name}.virtual_columns")
    my_object.virtual_column_names.sort.each { |vcn| $evm.log(:info, "#{my_object_name} Virtual Column - #{vcn}")}
    $evm.log(:info, "End #{my_object_name}.virtual_columns")
    $evm.log(:info, "")
  end
 
  log(:info, "CFME Automate Method Started")
 
  # Log information 
  #dump_attributes($evm.root, "$evm.root")
  #dump_associations($evm.root['vm'], "vm")
  #dump_virtual_columns($evm.root, "$evm.root")
 
  def find_vm(dc, name)
    vm = {}
    dc.datastoreFolder.childEntity.collect do |datastore|
      vm[:instance] = datastore.vm.find { |x| x.name == name }
      if vm[:instance]
        vm[:datastore] = datastore.name
        break
      end
    end
    vm
  end
 
  def upg_tools(vm)
    if vm[:instance][:guest][:guestFamily] == 'windowsGuest'
      instopts = '/s /v "/qn REBOOT=ReallySuppress"'
    else
      instopts = nil
    end
 
    $evm.log(:info, "Upgrading VMware Tools on #{vm[:instance][:name]}")
    upgtask = vm[:instance].UpgradeTools_Task(:installerOptions => instopts).wait_for_completion
  end
 
  require 'rbvmomi'
 
  VIM = RbVmomi::VIM
  rvm  = $evm.root['vm']
  ems = rvm.ext_management_system()
 
  credentials = { :host => ems['hostname'], :user => ems.authentication_userid(), :password => ems.authentication_password(), :insecure => true }
  vim = VIM.connect credentials
 
  dc = vim.serviceInstance.find_datacenter
  vm = find_vm(dc, rvm.name)
  rc = upg_tools(vm)
 
  # Exit method
  log(:info, "CFME Automate Method Ended")
  exit MIQ_OK
 
  # Ruby rescue 
rescue => err
  log(:error, "[#{err}]\n#{err.backtrace.join("\n")}")
  exit MIQ_ABORT
end

Quick Script to join content hosts to Satellite 6

April 23rd, 2015 No comments

I wrote this for $DAYJOB to move machines registered with RHN or CentOS machines not registered to anything over to our Satellite 6 server.

I presume you have created activation keys titled organization-${DISTRO}${MAJ_REL}-development for all combinations of DISTRO (rhel, centos) and MAJ_REL (6, 7).

#!/bin/sh
 
# Prepare to register with Satellite
# Make sure lsb_release is installed  
rpm -q redhat-lsb-core 2>&1 >/dev/null
if [ $? -ne 0 ]; then
  yum -y install redhat-lsb-core
fi
 
# Which version are we running
RELEASE=`lsb_release -r -s`
MAJ_REL=${RELEASE:0:1}
 
# Are we on CentOS or RHEL?
if [ -f /etc/centos-release ]; then
  DISTRO="centos"
 
  # Get the copr release of RHSM for CentOS
  if [ ! -f /etc/yum.repos.d/dgoodwin-subscription-manager.repo ]; then
    wget -O /etc/yum.repos.d/dgoodwin-subscription-manager.repo http://copr-fe.cloud.fedoraproject.org/coprs/dgoodwin/subscription-manager/repo/epel-${MAJ_REL}/dgoodwin-subscription-manager-epel-${MAJ_REL}.repo
  fi
else
  DISTRO="rhel"
fi
 
# Install the certificates - will pull in subscription-manager
yum -y install http://satellite.example.com/pub/katello-ca-consumer-latest.noarch.rpm
 
# Install additional useful packages
yum -y install katello-agent
/sbin/service goferd start
 
# Register with Satellite
subscription-manager register --org="Example" --activationkey="example-${DISTRO}${MAJ_REL}-development"

2 TB Virtual Disks in VMware

July 17th, 2013 No comments

When creating a 2TB disk in VMware, if you want to take snapshots do not configure the disk as 2TB, but rather 2032GB to account for the overhead. See http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1012384

Time conversion gymnastics in Python

February 5th, 2013 No comments

I was recently working with a sqlite3 database using the DATETIME(‘now’) SQL construct to save the time a row was updated. This results in a format of e.g. 2013-02-05 17:50:42, which is in UTC. In order to display this in local time, I did the following gymnastics:


import calendar,time
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(calendar.timegm(time.strptime(thetimefromdb, "%Y-%m-%d %H:%M:%S"))))

Is there a better way?

CentOS 6 Kickstart Encrypted Password

January 21st, 2013 No comments

To create the SHA256 encrypted password for a CentOS 6 kickstart file:

python -c 'import crypt; print(crypt.crypt("Password", "$6$Salt"))'

Juniper Network Connect on CentOS 6

January 15th, 2013 No comments

The best method for making this work seems to be a 32-bit firefox (even on 64-bit CentOS/RHEL). The trick is that the NC installer launches xterm directly to prompt for a root password – so the following RPMs should be installed before launching the SSL VPN site:

* xterm
* firefox.i686
* libXtst.i686
* libcurl.i686
* gtk2-engines.i686
* alsa-plugins-pulseaudio.i686
* PackageKit-gtk-module.i686