コード例 #1
0
ファイル: __init__.py プロジェクト: robinbowes/mothership
 def _extract_system_by_hostname(self, remote, hostname):
     info = {}
     print 'Extracting cobbler system: %s' % hostname
     system = remote.get_system(hostname)
     if '-xen-' in system['profile']:
         system['virtual'] = True
     else:
         system['virtual'] = False
     info['server'] = [ transkey(system, self.map_server) ] 
     info['hardware'] = [ transkey(system, self.map_hardware) ]
     info['network'] = []
     sysif = system['interfaces']
     for k in sysif.keys():
         if k.startswith('bond'): continue
         sysif[k]['interface'] = k
         if sysif[k]['static_routes']:
             sysif[k]['static_route'] = sysif[k]['static_routes'][0].split(':')[1]
         info['network'].append(transkey(system['interfaces'][k], self.map_network, True))
     return info
コード例 #2
0
ファイル: __init__.py プロジェクト: robinbowes/mothership
 def _extract_system_by_hostname(self, remote, hostname):
     info = {}
     print 'Extracting cobbler system: %s' % hostname
     system = remote.get_system(hostname)
     if '-xen-' in system['profile']:
         system['virtual'] = True
     else:
         system['virtual'] = False
     info['server'] = [transkey(system, self.map_server)]
     info['hardware'] = [transkey(system, self.map_hardware)]
     info['network'] = []
     sysif = system['interfaces']
     for k in sysif.keys():
         if k.startswith('bond'): continue
         sysif[k]['interface'] = k
         if sysif[k]['static_routes']:
             sysif[k]['static_route'] = sysif[k]['static_routes'][0].split(
                 ':')[1]
         info['network'].append(
             transkey(system['interfaces'][k], self.map_network, True))
     return info
コード例 #3
0
ファイル: __init__.py プロジェクト: robinbowes/mothership
    def _add_system(self, cfg, host_dict, remote, token):
        hostname = '%s.%s.%s' % (host_dict['hostname'],
            host_dict['realm'], host_dict['site_id'])
        if not host_dict['cobbler_profile']:
            print '%s has empty profile: system not provisioned for cobbler!' % hostname
            return
        if self.coblive:
            if self._find_system_by_hostname(hostname, remote):
                print 'System already exists: %s' % hostname
                self._delete_system(hostname, remote, token)
            print 'Adding system to %s: %s' % (remote._ServerProxy__host, hostname)
            handle = remote.new_system(token)
        else:
            print 'API: remote.find_system({\'name\':hostname})'
            print 'API: if found: remote.remove_system(hostname, token)'
            print 'API: set new handle = remote.new_system(token)'

        sysdict = transkey(host_dict, self.map_system)
        # Adjust power management values after transkey
        if sysdict['virtual']:
            sysdict['power_user'] = '******'
            sysdict['power_pass'] = ''
        else:
            sysdict['power_user'] = cfg.puser
            sysdict['power_pass'] = cfg.ppass

        if self.coblive:
            for k in sysdict.keys():
                if '-xen-' not in sysdict['profile'] and 'virt_' in k:
                    continue    # do not set cpu,ram,disk for baremetal
                if sysdict[k] is not None:
                    if k == 'virt_ram':
                        # convert mothership GB to cobbler MB
                        sysdict[k] = int(sysdict[k]) * 1024
                    #print 'Modifying %s system values: %s' % (hostname, k)
                    remote.modify_system(handle, k, sysdict[k], token)
        else:
            from pprint import pprint
            print 'API: sysdict = { \'key\':\'value\', }'
            pprint(sysdict, indent=4)
            print 'API: loop through all the cobbler \'system\' values:'
            print 'API:     remote.modify_system(handle, key, sysdict[key], token)'
            print 'API: then loop through all interfaces...'

        ifbond = False
        for k in sorted(host_dict['interfaces'].keys()):
            x = host_dict['interfaces'][k].copy()

            # remove ip if world
            if 'ip' in x and x['ip'] == '0.0.0.0':
                del x['ip']

            # if valid ip, set static to True
            if 'ip' in x:
                x['static'] = 'True'

            # set static_routes
            if x['static_route']:
                x['static_routes'] = [ '0.0.0.0/0:%s' % x['static_route'] ]

            # add appropriate dns_names for each interface
            domain = None
            if x['ip']:
                domain = mothership.network_mapper.remap(cfg, 'dom', nic=x['interface'], siteid=x['site_id'], ip=x['ip'])
            if domain:
                x['dns_name'] = '%s%s' % (host_dict['hostname'], domain)

            # set the bond0 master interface
            if not ifbond and x['bond_options']:
                ifbond = 'bond0'
                ifdict = x.copy()
                ifdict['bonding'] = 'master'
                del ifdict['mac']
                # modify system interface bond0
                if self.coblive:
                    #print 'Modifying %s network values: %s' % (hostname, ifbond)
                    remote.modify_system(handle, 'modify_interface', 
                        self.append_value_to_keyname(cfg, transkey(ifdict,
                        self.map_interface, True), '-'+ifbond), token)
                else:
                    print 'API: since bond_options are set:'
                    print 'API:     remote.modify_system(handle, \'modify_interface\', ifbond-dict-map, token)'
                # if xenserver, then add template for bond0
                if 'xenserver' in sysdict['profile']:
                    if self.coblive:
                        #print 'Modifying %s templates values' % hostname
                        remote.modify_system(handle, 'template_files', cfg.cobconfig['xentemplates'], token)
                    else:
                        print 'API: if \'xenserver\' profile:'
                        print 'API:     remote.modify_system(handle, \'template_files\', {template-path:alias}, token)'

            # set the bond0 slave interfaces
            if x['bond_options']:
                x['bonding'] = 'slave'
                x['bond_master'] = ifbond
                x['ip'] = ifdict['ip']
                del x['bond_options']

            # modify system interface 'k'
            if self.coblive and host_dict['interfaces'][k]['mac']:
                try:
                    remote.modify_system(handle, 'modify_interface', 
                        self.append_value_to_keyname(cfg, transkey(x,
                        self.map_interface, True), '-'+k), token)
                except xmlrpclib.Fault, err:
                    print 'Aborting cobbler add, failed to modify %s %s' % (hostname, k)
                    print '    ' + str(err)
                    return False
            else:
                print 'API: remote.modify_system(handle, \'modify_interface\', %s-dict-map, token)' % k
コード例 #4
0
ファイル: __init__.py プロジェクト: robinbowes/mothership
    def _add_system(self, cfg, host_dict, remote, token):
        hostname = '%s.%s.%s' % (host_dict['hostname'], host_dict['realm'],
                                 host_dict['site_id'])
        if not host_dict['cobbler_profile']:
            print '%s has empty profile: system not provisioned for cobbler!' % hostname
            return
        if self.coblive:
            if self._find_system_by_hostname(hostname, remote):
                print 'System already exists: %s' % hostname
                self._delete_system(hostname, remote, token)
            print 'Adding system to %s: %s' % (remote._ServerProxy__host,
                                               hostname)
            handle = remote.new_system(token)
        else:
            print 'API: remote.find_system({\'name\':hostname})'
            print 'API: if found: remote.remove_system(hostname, token)'
            print 'API: set new handle = remote.new_system(token)'

        sysdict = transkey(host_dict, self.map_system)
        # Adjust power management values after transkey
        if sysdict['virtual']:
            sysdict['power_user'] = '******'
            sysdict['power_pass'] = ''
        else:
            sysdict['power_user'] = cfg.puser
            sysdict['power_pass'] = cfg.ppass

        if self.coblive:
            for k in sysdict.keys():
                if '-xen-' not in sysdict['profile'] and 'virt_' in k:
                    continue  # do not set cpu,ram,disk for baremetal
                if sysdict[k] is not None:
                    if k == 'virt_ram':
                        # convert mothership GB to cobbler MB
                        sysdict[k] = int(sysdict[k]) * 1024
                    #print 'Modifying %s system values: %s' % (hostname, k)
                    remote.modify_system(handle, k, sysdict[k], token)
        else:
            from pprint import pprint
            print 'API: sysdict = { \'key\':\'value\', }'
            pprint(sysdict, indent=4)
            print 'API: loop through all the cobbler \'system\' values:'
            print 'API:     remote.modify_system(handle, key, sysdict[key], token)'
            print 'API: then loop through all interfaces...'

        ifbond = False
        for k in sorted(host_dict['interfaces'].keys()):
            x = host_dict['interfaces'][k].copy()

            # remove ip if world
            if 'ip' in x and x['ip'] == '0.0.0.0':
                del x['ip']

            # if valid ip, set static to True
            if 'ip' in x:
                x['static'] = 'True'

            # set static_routes
            if x['static_route']:
                x['static_routes'] = ['0.0.0.0/0:%s' % x['static_route']]

            # add appropriate dns_names for each interface
            domain = None
            if x['ip']:
                domain = mothership.network_mapper.remap(cfg,
                                                         'dom',
                                                         nic=x['interface'],
                                                         siteid=x['site_id'],
                                                         ip=x['ip'])
            if domain:
                x['dns_name'] = '%s%s' % (host_dict['hostname'], domain)

            # set the bond0 master interface
            if not ifbond and x['bond_options']:
                ifbond = 'bond0'
                ifdict = x.copy()
                ifdict['bonding'] = 'master'
                del ifdict['mac']
                # modify system interface bond0
                if self.coblive:
                    #print 'Modifying %s network values: %s' % (hostname, ifbond)
                    remote.modify_system(
                        handle, 'modify_interface',
                        self.append_value_to_keyname(
                            cfg, transkey(ifdict, self.map_interface, True),
                            '-' + ifbond), token)
                else:
                    print 'API: since bond_options are set:'
                    print 'API:     remote.modify_system(handle, \'modify_interface\', ifbond-dict-map, token)'
                # if xenserver, then add template for bond0
                if 'xenserver' in sysdict['profile']:
                    if self.coblive:
                        #print 'Modifying %s templates values' % hostname
                        remote.modify_system(handle, 'template_files',
                                             cfg.cobconfig['xentemplates'],
                                             token)
                    else:
                        print 'API: if \'xenserver\' profile:'
                        print 'API:     remote.modify_system(handle, \'template_files\', {template-path:alias}, token)'

            # set the bond0 slave interfaces
            if x['bond_options']:
                x['bonding'] = 'slave'
                x['bond_master'] = ifbond
                x['ip'] = ifdict['ip']
                del x['bond_options']

            # modify system interface 'k'
            if self.coblive and host_dict['interfaces'][k]['mac']:
                try:
                    remote.modify_system(
                        handle, 'modify_interface',
                        self.append_value_to_keyname(
                            cfg, transkey(x, self.map_interface, True),
                            '-' + k), token)
                except xmlrpclib.Fault, err:
                    print 'Aborting cobbler add, failed to modify %s %s' % (
                        hostname, k)
                    print '    ' + str(err)
                    return False
            else:
                print 'API: remote.modify_system(handle, \'modify_interface\', %s-dict-map, token)' % k