~ubuntu-branches/ubuntu/saucy/cloud-init/saucy

« back to all changes in this revision

Viewing changes to cloudinit/sources/DataSourceSmartOS.py

  • Committer: Scott Moser
  • Date: 2013-09-21 00:45:57 UTC
  • mfrom: (1.4.6)
  • Revision ID: smoser@ubuntu.com-20130921004557-o8zfowviyrqz02sd
* New upstream snapshot.
  * add 'disk_setup' config module for partitioning disks and
    creating filesystems. (LP: #1218506)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import os.path
36
36
import serial
37
37
 
38
 
DEF_TTY_LOC = '/dev/ttyS1'
39
 
DEF_TTY_TIMEOUT = 60
 
38
 
40
39
LOG = logging.getLogger(__name__)
41
40
 
42
41
SMARTOS_ATTRIB_MAP = {
49
48
    'motd_sys_info': ('motd_sys_info', True),
50
49
}
51
50
 
52
 
# These are values which will never be base64 encoded.
53
 
# They come from the cloud platform, not user
54
 
SMARTOS_NO_BASE64 = ['root_authorized_keys', 'motd_sys_info',
55
 
                     'iptables_disable']
 
51
DS_NAME = 'SmartOS'
 
52
DS_CFG_PATH = ['datasource', DS_NAME]
 
53
# BUILT-IN DATASOURCE CONFIGURATION
 
54
#  The following is the built-in configuration. If the values
 
55
#  are not set via the system configuration, then these default
 
56
#  will be used:
 
57
#    serial_device: which serial device to use for the meta-data
 
58
#    seed_timeout: how long to wait on the device
 
59
#    no_base64_decode: values which are not base64 encoded and
 
60
#            are fetched directly from SmartOS, not meta-data values
 
61
#    base64_keys: meta-data keys that are delivered in base64
 
62
#    base64_all: with the exclusion of no_base64_decode values,
 
63
#            treat all meta-data as base64 encoded
 
64
#    disk_setup: describes how to partition the ephemeral drive
 
65
#    fs_setup: describes how to format the ephemeral drive
 
66
#
 
67
BUILTIN_DS_CONFIG = {
 
68
    'serial_device': '/dev/ttyS1',
 
69
    'seed_timeout': 60,
 
70
    'no_base64_decode': ['root_authorized_keys',
 
71
                         'motd_sys_info',
 
72
                         'iptables_disable'],
 
73
    'base64_keys': [],
 
74
    'base64_all': False,
 
75
    'ephemeral_disk': '/dev/vdb',
 
76
    'disk_setup': {
 
77
        'ephemeral0': {'table_type': 'mbr',
 
78
                       'layout': True,
 
79
                       'overwrite': False}
 
80
         },
 
81
    'fs_setup': [{'label': 'ephemeral0', 'filesystem': 'ext3',
 
82
                  'device': '/dev/xvdb', 'partition': 'auto'}],
 
83
}
56
84
 
57
85
 
58
86
class DataSourceSmartOS(sources.DataSource):
59
87
    def __init__(self, sys_cfg, distro, paths):
60
88
        sources.DataSource.__init__(self, sys_cfg, distro, paths)
61
 
        self.seed_dir = os.path.join(paths.seed_dir, 'sdc')
62
89
        self.is_smartdc = None
63
90
 
64
 
        self.seed = self.ds_cfg.get("serial_device", DEF_TTY_LOC)
65
 
        self.seed_timeout = self.ds_cfg.get("serial_timeout", DEF_TTY_TIMEOUT)
66
 
        self.smartos_no_base64 = self.ds_cfg.get('no_base64_decode',
67
 
                                                 SMARTOS_NO_BASE64)
68
 
        self.b64_keys = self.ds_cfg.get('base64_keys', [])
69
 
        self.b64_all = self.ds_cfg.get('base64_all', False)
 
91
        self.ds_cfg = util.mergemanydict([
 
92
            self.ds_cfg,
 
93
            util.get_cfg_by_path(sys_cfg, DS_CFG_PATH, {}),
 
94
            BUILTIN_DS_CONFIG])
 
95
 
 
96
        self.metadata = {}
 
97
        self.cfg = {}
 
98
        self.cfg['disk_setup'] = self.ds_cfg.get('disk_setup')
 
99
        self.cfg['fs_setup'] = self.ds_cfg.get('fs_setup')
 
100
 
 
101
        self.seed = self.ds_cfg.get("serial_device")
 
102
        self.seed_timeout = self.ds_cfg.get("serial_timeout")
 
103
        self.smartos_no_base64 = self.ds_cfg.get('no_base64_decode')
 
104
        self.b64_keys = self.ds_cfg.get('base64_keys')
 
105
        self.b64_all = self.ds_cfg.get('base64_all')
70
106
 
71
107
    def __str__(self):
72
108
        root = sources.DataSource.__str__(self)
79
115
        if not os.path.exists(self.seed):
80
116
            LOG.debug("Host does not appear to be on SmartOS")
81
117
            return False
82
 
        self.seed = self.seed
83
118
 
84
119
        dmi_info = dmi_data()
85
120
        if dmi_info is False:
114
149
        elif md['user-script']:
115
150
            ud = md['user-script']
116
151
 
117
 
        self.metadata = md
 
152
        self.metadata = util.mergemanydict([md, self.metadata])
118
153
        self.userdata_raw = ud
119
154
        return True
120
155
 
 
156
    def device_name_to_device(self, name):
 
157
        if 'ephemeral0' in name:
 
158
            return self.ds_cfg['ephemeral_disk']
 
159
 
 
160
    def get_config_obj(self):
 
161
        return self.cfg
 
162
 
121
163
    def get_instance_id(self):
122
164
        return self.metadata['instance-id']
123
165