# vi: ts=4 expandtab # # Copyright (C) 2012 Canonical Ltd. # Copyright (C) 2012 Cosmin Luta # # Author: Cosmin Luta # Author: Scott Moser # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import cloudinit.DataSource as DataSource from cloudinit import seeddir as base_seeddir from cloudinit import log import cloudinit.util as util from socket import inet_ntoa import time import boto.utils as boto_utils from struct import pack class DataSourceCloudStack(DataSource.DataSource): api_ver = 'latest' seeddir = base_seeddir + '/cs' metadata_address = None def __init__(self, sys_cfg=None): DataSource.DataSource.__init__(self, sys_cfg) # Cloudstack has its metadata/userdata URLs located at # http:///latest/ self.metadata_address = "http://%s/" % self.get_default_gateway() def get_default_gateway(self): """ Returns the default gateway ip address in the dotted format """ with open("/proc/net/route", "r") as f: for line in f.readlines(): items = line.split("\t") if items[1] == "00000000": # found the default route, get the gateway gw = inet_ntoa(pack("