import json
import base64
import libxml2
+import re
from urlparse import urlparse
# If ../heat/__init__.py exists, add ../ to Python search path, so that
arch = arguments.pop(0)
instance_type = arguments.pop(0)
- if not arch in ['x86_64', 'i686']:
+ arches = ('x86_64', 'i386', 'amd64')
+ arches_str = " | ".join(arches)
+ instance_types = ('gold', 'cfntools')
+ instances_str = " | ".join(instance_types)
+
+ if not arch in arches:
print 'arch %s not supported' % arch
- print 'try: x86_64 or i686'
+ print 'try: heat jeos_create %s [ %s ]' % (distro, arches_str)
sys.exit(1)
- if not instance_type in ('gold', 'cfntools'):
+ if not instance_type in instance_types:
print 'A JEOS instance type of %s not supported' % instance_type
- print 'try: gold or cfntools'
+ print 'try: heat jeos_create %s %s [ %s ]' % (distro, arch, instances_str)
sys.exit(1)
- iso = None
- if distro == 'F16':
- iso = '/var/lib/libvirt/images/Fedora-16-x86_64-DVD.iso'
- elif distro == 'F15':
- iso = '/var/lib/libvirt/images/Fedora-15-x86_64-DVD.iso'
- elif distro == 'F17':
- iso = '/var/lib/libvirt/images/Fedora-17-x86_64-DVD.iso'
+ fedora_match = re.match('F(1[6-7])', distro)
+ if fedora_match:
+ version = fedora_match.group(1)
+ iso = '/var/lib/libvirt/images/Fedora-%s-%s-DVD.iso' % (version, arch)
elif distro == 'U10':
- iso = '/var/lib/libvirt/images/ubuntu-10.04.3-server-amd64.iso'
+ iso = '/var/lib/libvirt/images/ubuntu-10.04.3-server-%s.iso' % arch
else:
print 'distro %s not supported' % distro
- print 'try: F15, F16, F17 or U10'
+ print 'try: F16, F17 or U10'
sys.exit(1)
- if iso:
- if not os.access(iso, os.R_OK):
- print '*** %s does not exist.' % (iso)
- sys.exit(1)
+ if not os.access(iso, os.R_OK):
+ print '*** %s does not exist.' % (iso)
+ sys.exit(1)
tdl_path = '%s%s-%s-%s-jeos.tdl' % (jeos_path, distro, arch, instance_type)
image_id = o.id
if image_id is None:
+ print "Image %s was not found in glance" % image_name
raise exception.ImageNotFound(image_name=image_name)
flavor_list = self.nova().flavors.list()
--- /dev/null
+<template>
+ <name>F16-i386-cfntools-jeos</name>
+ <os>
+ <name>Fedora</name>
+ <version>16</version>
+ <arch>i386</arch>
+ <install type='iso'>
+ <iso>file:/var/lib/libvirt/images/Fedora-16-i386-DVD.iso</iso>
+ </install>
+ <rootpw>password</rootpw>
+ </os>
+ <description>Fedora 16</description>
+ <commands>
+ <command name='commands'>
+yum -y update --skip-broken;yum -y install cloud-init;cat >> /etc/rc.d/rc.local << EOF;chmod +x /etc/rc.d/rc.local
+#!/bin/bash
+setenforce 0
+while true; do
+gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/Devices/0 | grep "State = 100"
+if [ \$? -eq 0 ]
+then
+break
+fi
+sleep 1
+done
+
+if [ ! -d /root/.ssh ]; then
+ mkdir -p /root/.ssh
+ chmod 700 /root/.ssh
+fi
+
+# Fetch public key using HTTP
+ATTEMPTS=10
+while [ ! -f /root/.ssh/authorized_keys ]; do
+ curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
+ if [ \$? -eq 0 ]; then
+ cat /tmp/aws-key >> /root/.ssh/authorized_keys
+ chmod 0600 /root/.ssh/authorized_keys
+ restorecon /root/.ssh/authorized_keys
+ rm -f /tmp/aws-key
+ echo "Successfully retrieved AWS public key from instance metadata"
+ else
+ FAILED=\$((\$FAILED + 1))
+ if [ \$FAILED -ge \$ATTEMPTS ]; then
+ echo "Failed to retrieve AWS public key after \$FAILED attempts, quitting"
+ break
+ fi
+ echo "Could not retrieve AWS public key (attempt #\$FAILED/\$ATTEMPTS), retrying in 5 seconds..."
+ sleep 5
+ fi
+done
+chmod +x /opt/aws/bin/cfn-*
+EOF
+ </command>
+ </commands>
+ <files>
+ <file name='/opt/aws/bin/cfn-init' type='base64'></file>
+ <file name='/opt/aws/bin/cfn-hup' type='base64'></file>
+ <file name='/opt/aws/bin/cfn-signal' type='base64'></file>
+ </files>
+</template>
--- /dev/null
+<template>
+ <name>F16-i386-gold-jeos</name>
+ <os>
+ <name>Fedora</name>
+ <version>16</version>
+ <arch>i386</arch>
+ <install type='iso'>
+ <iso>file:/var/lib/libvirt/images/Fedora-16-i386-DVD.iso</iso>
+ </install>
+ <rootpw>password</rootpw>
+ </os>
+ <description>Fedora 16</description>
+ <commands>
+ <command name='commands'>
+rm -f /etc/yum.repos.d/fedora-updates*;yum -y install cloud-init;cat >> /etc/rc.d/rc.local << EOF;chmod +x /etc/rc.d/rc.local
+#!/bin/bash
+setenforce 0
+while true; do
+gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/Devices/0 | grep "State = 100"
+if [ \$? -eq 0 ]
+then
+break
+fi
+sleep 1
+done
+
+if [ ! -d /root/.ssh ]; then
+ mkdir -p /root/.ssh
+ chmod 700 /root/.ssh
+fi
+
+# Fetch public key using HTTP
+ATTEMPTS=10
+while [ ! -f /root/.ssh/authorized_keys ]; do
+ curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
+ if [ \$? -eq 0 ]; then
+ cat /tmp/aws-key >> /root/.ssh/authorized_keys
+ chmod 0600 /root/.ssh/authorized_keys
+ restorecon /root/.ssh/authorized_keys
+ rm -f /tmp/aws-key
+ echo "Successfully retrieved AWS public key from instance metadata"
+ else
+ FAILED=\$((\$FAILED + 1))
+ if [ \$FAILED -ge \$ATTEMPTS ]; then
+ echo "Failed to retrieve AWS public key after \$FAILED attempts, quitting"
+ break
+ fi
+ echo "Could not retrieve AWS public key (attempt #\$FAILED/\$ATTEMPTS), retrying in 5 seconds..."
+ sleep 5
+ fi
+done
+while [ ! -f /var/lib/cloud/instance/user-data.txt ]; do
+ sleep 1
+done
+base64 -d /var/lib/cloud/instance/user-data.txt > /tmp/startup
+chmod +x /tmp/startup
+/tmp/startup
+EOF
+ </command>
+ </commands>
+</template>
--- /dev/null
+<template>
+ <name>F17-i386-cfntools-jeos</name>
+ <os>
+ <name>Fedora</name>
+ <version>17</version>
+ <arch>i386</arch>
+ <install type='iso'>
+ <iso>file:/var/lib/libvirt/images/Fedora-17-i386-DVD.iso</iso>
+ </install>
+ <rootpw>password</rootpw>
+ </os>
+ <description>Fedora 17</description>
+ <commands>
+ <command name='commands'>
+yum -y update --skip-broken;yum -y install cloud-init;cat >> /etc/rc.d/rc.local << EOF;chmod +x /etc/rc.d/rc.local
+#!/bin/bash
+setenforce 0
+while true; do
+gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/Devices/0 | grep "State = 100"
+if [ \$? -eq 0 ]
+then
+break
+fi
+sleep 1
+done
+
+if [ ! -d /root/.ssh ]; then
+ mkdir -p /root/.ssh
+ chmod 700 /root/.ssh
+fi
+
+# Fetch public key using HTTP
+ATTEMPTS=10
+while [ ! -f /root/.ssh/authorized_keys ]; do
+ curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
+ if [ \$? -eq 0 ]; then
+ cat /tmp/aws-key >> /root/.ssh/authorized_keys
+ chmod 0600 /root/.ssh/authorized_keys
+ restorecon /root/.ssh/authorized_keys
+ rm -f /tmp/aws-key
+ echo "Successfully retrieved AWS public key from instance metadata"
+ else
+ FAILED=\$((\$FAILED + 1))
+ if [ \$FAILED -ge \$ATTEMPTS ]; then
+ echo "Failed to retrieve AWS public key after \$FAILED attempts, quitting"
+ break
+ fi
+ echo "Could not retrieve AWS public key (attempt #\$FAILED/\$ATTEMPTS), retrying in 5 seconds..."
+ sleep 5
+ fi
+done
+chmod +x /opt/aws/bin/cfn-*
+EOF
+ </command>
+ </commands>
+ <files>
+ <file name='/opt/aws/bin/cfn-init' type='base64'></file>
+ <file name='/opt/aws/bin/cfn-hup' type='base64'></file>
+ <file name='/opt/aws/bin/cfn-signal' type='base64'></file>
+ </files>
+</template>
--- /dev/null
+<template>
+ <name>F17-i386-gold-jeos</name>
+ <os>
+ <name>Fedora</name>
+ <version>17</version>
+ <arch>i386</arch>
+ <install type='iso'>
+ <iso>file:/var/lib/libvirt/images/Fedora-17-i386-DVD.iso</iso>
+ </install>
+ <rootpw>password</rootpw>
+ </os>
+ <description>Fedora 17</description>
+ <commands>
+ <command name='commands'>
+rm -f /etc/yum.repos.d/fedora-updates*;yum -y install cloud-init;cat >> /etc/rc.d/rc.local << EOF;chmod +x /etc/rc.d/rc.local
+#!/bin/bash
+setenforce 0
+while true; do
+gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/Devices/0 | grep "State = 100"
+if [ \$? -eq 0 ]
+then
+break
+fi
+sleep 1
+done
+
+if [ ! -d /root/.ssh ]; then
+ mkdir -p /root/.ssh
+ chmod 700 /root/.ssh
+fi
+
+# Fetch public key using HTTP
+ATTEMPTS=10
+while [ ! -f /root/.ssh/authorized_keys ]; do
+ curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
+ if [ \$? -eq 0 ]; then
+ cat /tmp/aws-key >> /root/.ssh/authorized_keys
+ chmod 0600 /root/.ssh/authorized_keys
+ restorecon /root/.ssh/authorized_keys
+ rm -f /tmp/aws-key
+ echo "Successfully retrieved AWS public key from instance metadata"
+ else
+ FAILED=\$((\$FAILED + 1))
+ if [ \$FAILED -ge \$ATTEMPTS ]; then
+ echo "Failed to retrieve AWS public key after \$FAILED attempts, quitting"
+ break
+ fi
+ echo "Could not retrieve AWS public key (attempt #\$FAILED/\$ATTEMPTS), retrying in 5 seconds..."
+ sleep 5
+ fi
+done
+while [ ! -f /var/lib/cloud/instance/user-data.txt ]; do
+ sleep 1
+done
+base64 -d /var/lib/cloud/instance/user-data.txt > /tmp/startup
+chmod +x /tmp/startup
+/tmp/startup
+EOF
+ </command>
+ </commands>
+</template>
"cc1.4xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
- "F16" : { "32" : "F16-i686", "64" : "F16-x86_64-gold" },
- "F17" : { "32" : "F17-i686", "64" : "F17-x86_64-gold" },
- "U10" : { "32" : "U10-i686", "64" : "U10-x86_64-gold" },
- "RHEL-6.1" : { "32" : "rhel61-i686", "64" : "rhel61-x86_64-gold" },
- "RHEL-6.2" : { "32" : "rhel62-i686", "64" : "rhel62-x86_64-gold" },
- "RHEL-6.3" : { "32" : "rhel63-i686", "64" : "rhel63-x86_64-gold" }
+ "F16" : { "32" : "F16-i386-gold", "64" : "F16-x86_64-gold" },
+ "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" },
+ "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" },
+ "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" },
+ "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" },
+ "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" }
}
},
"cc1.4xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
- "F16" : { "32" : "F16-i686", "64" : "F16-x86_64-gold" },
- "F17" : { "32" : "F17-i686", "64" : "F17-x86_64-gold" },
- "U10" : { "32" : "U10-i686", "64" : "U10-x86_64-gold" },
- "RHEL-6.1" : { "32" : "rhel61-i686", "64" : "rhel61-x86_64-gold" },
- "RHEL-6.2" : { "32" : "rhel62-i686", "64" : "rhel62-x86_64-gold" },
- "RHEL-6.3" : { "32" : "rhel63-i686", "64" : "rhel63-x86_64-gold" }
+ "F16" : { "32" : "F16-i386-gold", "64" : "F16-x86_64-gold" },
+ "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" },
+ "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" },
+ "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" },
+ "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" },
+ "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" }
}
},
"cc1.4xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
- "F16" : { "32" : "F16-i686", "64" : "F16-x86_64-gold" },
- "F17" : { "32" : "F17-i686", "64" : "F17-x86_64-gold" },
- "U10" : { "32" : "U10-i686", "64" : "U10-x86_64-gold" },
- "RHEL-6.1" : { "32" : "rhel61-i686", "64" : "rhel61-x86_64-gold" },
- "RHEL-6.2" : { "32" : "rhel62-i686", "64" : "rhel62-x86_64-gold" },
- "RHEL-6.3" : { "32" : "rhel63-i686", "64" : "rhel63-x86_64-gold" }
+ "F16" : { "32" : "F16-i386-gold", "64" : "F16-x86_64-gold" },
+ "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" },
+ "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" },
+ "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" },
+ "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" },
+ "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" }
}
},
"cc1.4xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
- "F16" : { "32" : "F16-i686", "64" : "F16-x86_64-gold" },
- "F17" : { "32" : "F17-i686", "64" : "F17-x86_64-gold" },
- "U10" : { "32" : "U10-i686", "64" : "U10-x86_64-gold" },
- "RHEL-6.1" : { "32" : "rhel61-i686", "64" : "rhel61-x86_64-gold" },
- "RHEL-6.2" : { "32" : "rhel62-i686", "64" : "rhel62-x86_64-gold" },
- "RHEL-6.3" : { "32" : "rhel63-i686", "64" : "rhel63-x86_64-gold" }
+ "F16" : { "32" : "F16-i386-gold", "64" : "F16-x86_64-gold" },
+ "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" },
+ "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" },
+ "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" },
+ "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" },
+ "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" }
}
},
"cc1.4xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
- "F16" : { "32" : "F16-i686", "64" : "F16-x86_64-cfntools" },
- "F17" : { "32" : "F17-i686", "64" : "F17-x86_64-cfntools" },
- "U10" : { "32" : "U10-i686", "64" : "U10-x86_64-cfntools" },
- "RHEL-6.1" : { "32" : "rhel61-i686", "64" : "rhel61-x86_64-cfntools" },
- "RHEL-6.2" : { "32" : "rhel62-i686", "64" : "rhel62-x86_64-cfntools" },
- "RHEL-6.3" : { "32" : "rhel63-i686", "64" : "rhel63-x86_64-cfntools" }
+ "F16" : { "32" : "F16-i386-cfntools", "64" : "F16-x86_64-cfntools" },
+ "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" },
+ "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" },
+ "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" },
+ "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" },
+ "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" }
}
},