Exemple #1
0
def backup_cleanup_scripts(sl_storage, containername, score):
    if 'cleanup-scripts' in score:
        for script, args in score['cleanup-scripts'].iteritems():
            scripttext = open(script).read()
            lib.save_state_script(sl_storage, containername, script,
                                  scripttext)
Exemple #2
0
def deploy_group(groupname, groupdef, clustername, score, client, sl_storage,
                 configuration, containername):
    vs_config = groupdef.copy()
    del vs_config['count']
    del vs_config['servertype']

    if 'vlan' in vs_config:
        del vs_config['vlan']

    if 'dependson' in vs_config:
        del vs_config['dependson']

    if 'keyname' in vs_config:
        sshkey_manager = SoftLayer.SshKeyManager(client)
        keys = sshkey_manager.list_keys(vs_config['keyname'])
        if len(keys) == 0:
            raise Exception("Key {} not found".format(vs_config['keyname']))
        vs_config['ssh_keys'] = [keys[0]['id']]
        del vs_config['keyname']

    vs_config['datacenter'] = score['datacenter']['name']

    vs_config.update(normalize(
            score['mappings']['servertypes'][groupdef['servertype']],
            score))

    if 'script' in vs_config or 'userdata' in vs_config:
        vs_config['post_uri'] = "https://gist.githubusercontent.com/suppandi/"\
                "92160b055d74662a1deb/raw/"\
                "5770507d3bb0a3f05acd9a5bb2b03fe65bb00c5d/script.sh"

        newuserdata = ""
        if 'userdata' in vs_config:
            newuserdata = vs_config['userdata']

        if 'script' in vs_config:
            regex = re.compile("^(http|https)://.*")
            result = regex.match(vs_config['script'])
            # if a url, just use it
            if result:
                vs_config['post_uri'] = vs_config['script']
            else:
                scripttext = open(vs_config['script'], "r").read()
                lib.save_state_script(sl_storage, containername,
                                      vs_config['script'],
                                      scripttext)
                newuserdata = newuserdata + \
                    "\nSCRIPTSTARTSCRIPTSTARTSCRIPTSTART\n" + scripttext

            del vs_config['script']

        vs_config['userdata'] = newuserdata

    if 'vlan' in groupdef:
        for vlanname in groupdef['vlan']:
            vlan = score['resources']['vlans'][vlanname]
            if vlan['type'] == 'public':
                vs_config['public_vlan'] = vlan['id']
            else:
                vs_config['private_vlan'] = vlan['id']

    if 'autoscale' in groupdef:
        autoscale_provision_vms(vs_config, groupname, groupdef, clustername,
                                score, client, sl_storage, configuration,
                                containername)
    else:
        manual_provision_vms(vs_config, groupname, groupdef, clustername,
                             score, client, sl_storage, configuration,
                             containername)
    lib.debug(groupdef)