bootstrap-vz/providers/ec2/tasks/host.py

36 lines
977 B
Python
Raw Normal View History

2013-06-09 16:25:59 +02:00
from base import Task
from common import phases
from common.exceptions import TaskError
2013-07-01 22:06:42 +02:00
from common.tools import log_check_call
2013-06-23 17:54:25 +02:00
import packages
2013-07-01 22:06:42 +02:00
import logging
log = logging.getLogger(__name__)
2013-05-02 19:13:35 +02:00
2013-06-26 20:14:37 +02:00
class CheckPackages(Task):
description = 'Checking installed host packages'
2013-06-23 22:12:29 +02:00
phase = phases.preparation
after = [packages.HostPackages, packages.ImagePackages]
2013-06-09 20:29:54 +02:00
2013-05-02 19:13:35 +02:00
def run(self, info):
import subprocess
for package in info.host_packages:
try:
2013-07-01 22:06:42 +02:00
log_check_call(['/usr/bin/dpkg', '-s', package], log)
except subprocess.CalledProcessError:
msg = "The package ``{0}\'\' is not installed".format(package)
raise TaskError(msg)
2013-05-02 19:13:35 +02:00
class GetInfo(Task):
description = 'Retrieving instance metadata'
2013-06-23 22:12:29 +02:00
phase = phases.preparation
2013-06-09 20:29:54 +02:00
2013-05-02 19:13:35 +02:00
def run(self, info):
import urllib2
import json
metadata_url = 'http://169.254.169.254/latest/dynamic/instance-identity/document'
response = urllib2.urlopen(url=metadata_url, timeout=5)
info.host = json.load(response)
return info