List all installed package names in Python

pkgs = lambda : list(__import__(‘pkg_resources’).working_set) pkg_names = lambda : [x.project_name for x in pkgs()] pkg_versions = lambda : [x.project_name + ‘==’ + x.version for x in pkgs()] >>> pkg_names() [‘ansible’, ‘pycrypto’, ‘PyYAML’, ‘Jinja2’, ‘…truncated…’, ‘virt-back’, ‘Werkzeug’, ‘xmltodict’] >>> pkg_versions() [‘ansible==1.7’, ‘pycrypto==2.6.1’, ‘…truncated…’, ‘virt-back==0.1.0’, ‘xmltodict==0.9.2’]

Filtering AWS resources with Boto3

This post will be updated frequently when as I learn more about how to filter AWS resources using Boto3 library. Filtering VPCs by tags In this example we want to filter a particular VPC by the “Name” tag with the value of ‘webapp01’. >>> import boto3 >>> boto3.setup_default_session(profile_name=’project1′) >>> ec2 = boto3.resource(‘ec2′, region_name=’us-west-2’) >>> filters […]

Working with botocore’s ~/.aws/config

I ran into a bug in botocore and this post will serve to document a work around as well as show how to use botocore session object to work with the values stored in ~/.aws/config. Pretend you have an aws config with two accounts for two separate projects, like so: *~/.aws/config:* [profile project1] account_id = […]

My Mentor

The original purpose of this post was to recognize the teachers and mentors which have helped shape me. I planned to write about how Mr. Cassidy, my high school drafting teacher, taught me the importance precision. I prepared to explain how Mr. Mercuri, my college computer science professor, ignited my desire to engineer software. But […]

SmartOS Ubuntu guest, apt-get not working because IPv6

Turns out I don’t have IPv6 setup properly in my network so when apt attempts to connect to the Internet it tries IPv6 and fails. To disable IPv6 on the ubuntu guest, add this to end of /etc/sysctl.conf and restart the guest: sudo vim /etc/sysctl.conf: net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 This […]

A Python script which searches for available interpreters

This post describes how to write a polyglot — in this case a script which runs as valid Bash or Python, to search for available Python interpreters. The script initially runs as Bash but upon finding a first match, the script will call itself again this time using the expected Python interpreter in interactive mode! […]

Migrating libvirt KVM guest to SmartOS KVM guest

The following tutorial documents how to migrate a libvirt/KVM guest from Ubuntu to SmartOS. akuma: Ubuntu Hypervisor guy: SmartOS Hypervisor sagat: guest to migrate These commands were run on akuma: WORKDIR=/KVMROOT/migrate sudo mkdir $WORKDIR cd $WORKDIR # this tool simply stops and tarballs up the qcow and xml for libvirt KVM guest. sudo /usr/local/bin/virt-back –path=$WORKDIR […]

Setting region programmatically in Boto3

At work I’m looking into the possibility of porting parts of our AWS automation codebase from Boto2 to Boto3. We desire this port because Boto2’s pagination of records and results appear fundamentally defective. Like normal when I first start playing with a new library I like to poke around with it using the Interactive Python […]

Securely publish Jenkins build artifacts on Salt Master

Do you want a secure setup for publishing and staging build artifacts from a Jenkins build server to a Salt Master? This guide describes my fully automated pipeline to transport binaries using Salt’s encrypted “bus”. We start off with some Salt States to stand up a Jenkins build server “client”: jenkins/client.sls: # # manage […]

Set postgres user password on PostgreSQL SmartOS Zone

Connect to zone and determine the auto generated password for postgres user: cat /var/svc/log/system-zoneinit\:default.log | grep PGSQL_PW document the result and log into postgres with the following command, entering the password when prompted: [root@psql ~]# psql –user postgres Alter the postgres role’s password: postgres=# ALTER ROLE postgres UNENCRYPTED PASSWORD ‘new-password’; Now exit (\q) then try […]