Exemplo n.º 1
0
 def boot_params(self):
     params = {}
     params['boot_if'] = None
     params['net_prefix'] = None
     osimage = OsImage(id=self.get('osimage').id, mongo_db=self._mongo_db)
     try:
         params['kernel_file'] = osimage.get('kernfile')
     except:
         params['kernel_file'] = ""
     try:
         params['initrd_file'] = osimage.get('initrdfile')
     except:
         params['initrd_file'] = ""
     try:
         params['kern_opts'] = osimage.get('kernopts')
     except:
         params['kern_opts'] = ""
     try:
         params['boot_if'] = self.get('boot_if')
     except:
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     interfaces = self._get_json()['interfaces']
     try:
         if_params = interfaces[params['boot_if']]
     except:
         self._logger.error(
             "Boot interface '{}' does not present in configured interface list '{}'."
             .format(params['boot_if'], interfaces.keys()))
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     net = None
     try:
         if_net = if_params['network']
         net = Network(id=if_net.id, mongo_db=self._mongo_db)
     except:
         pass
     if not bool(net):
         self._logger.error(
             "Boot interface '{}' has no network configured".format(
                 params['boot_if']))
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     params['net_prefix'] = net.get('PREFIX')
     return params
Exemplo n.º 2
0
    def __init__(self, name = None, mongo_db = None, create = False, id = None,
            prescript = None, bmcsetup = None, bmcnetwork = None,
            partscript = None, osimage = None, interfaces = None, postscript = None, boot_if = None, torrent_if = None):
        """
        prescript   - preinstall script
        bmcsetup    - bmcsetup options
        bmcnetwork  - used for bmc networking
        partscript  - parition script
        osimage     - osimage
        interfaces  - list of the newtork interfaces
        postscript  - postinstall script
        """
        self._logger.debug("Arguments to function '{}".format(self._debug_function()))
        self._collection_name = 'group'
        mongo_doc = self._check_name(name, mongo_db, create, id)
        self._keylist = {'prescript': type(''), 'partscript': type(''), 'postscript': type(''), 'boot_if': type(''), 'torrent_if': type('')}
        if create:
            cluster = Cluster(mongo_db = self._mongo_db)
            (bmcobj, bmcnetobj) = (None, None)
            if bool(bmcsetup):
                bmcobj = BMCSetup(bmcsetup).DBRef
            if bool(bmcnetwork):
                bmcnetobj = Network(bmcnetwork, mongo_db = self._mongo_db).DBRef
            osimageobj = OsImage(osimage)
            if bool(interfaces) and type(interfaces) is not type([]):
                self._logger.error("'interfaces' should be list")
                raise RuntimeError
            if_dict = {}
            if not bool(interfaces):
                interfaces = []
            for interface in interfaces:
                if_dict[interface] = {'network': None, 'params': ''}
            if not bool(partscript):
                partscript = "mount -t tmpfs tmpfs /sysroot"
            if not bool(prescript):
                prescript = ""
            if not bool(postscript):
                postscript = """cat <<EOF>>/sysroot/etc/fstab
tmpfs   /       tmpfs    defaults        0 0
EOF"""
            mongo_doc = {'name': name, 'prescript':  prescript, 'bmcsetup': bmcobj, 'bmcnetwork': bmcnetobj,
                               'partscript': partscript, 'osimage': osimageobj.DBRef, 'interfaces': if_dict,
                               'postscript': postscript, 'boot_if': boot_if, 'torrent_if': torrent_if}
            self._logger.debug("mongo_doc: '{}'".format(mongo_doc))
            self._name = name
            self._id = self._mongo_collection.insert(mongo_doc)
            self._DBRef = DBRef(self._collection_name, self._id)
            self.link(cluster)
            if bmcobj:
                self.link(bmcobj)
            if bmcnetobj:
                self.link(bmcnetobj)
            self.link(osimageobj)
        else:
            self._name = mongo_doc['name']
            self._id = mongo_doc['_id']
            self._DBRef = DBRef(self._collection_name, self._id)
        self._logger = logging.getLogger('group.' + self._name)
Exemplo n.º 3
0
 def boot_params(self):
     params = {}
     params['boot_if'] = None
     params['net_prefix'] = None
     osimage = OsImage(id = self.get('osimage').id, mongo_db = self._mongo_db)
     try:
         params['kernel_file'] = osimage.get('kernfile')
     except:
         params['kernel_file'] = ""
     try:
         params['initrd_file'] = osimage.get('initrdfile')
     except:
         params['initrd_file'] = ""
     try:
         params['kern_opts'] = osimage.get('kernopts')
     except:
         params['kern_opts'] = ""
     try:
         params['boot_if'] = self.get('boot_if')
     except:
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     interfaces = self._get_json()['interfaces']
     try:
         if_params = interfaces[params['boot_if']]
     except:
         self._logger.error("Boot interface '{}' does not present in configured interface list '{}'.".format(params['boot_if'], interfaces.keys()))
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     net = None
     try:
         if_net = if_params['network']
         net = Network(id = if_net.id, mongo_db = self._mongo_db)
     except:
         pass
     if not bool(net):
         self._logger.error("Boot interface '{}' has no network configured".format(params['boot_if']))
         params['boot_if'] = ""
         params['net_prefix'] = ""
         return params
     params['net_prefix'] = net.get('PREFIX')
     return params
Exemplo n.º 4
0
 def osimage(self, osimage_name):
     if not self._id:
         self._logger.error("Was object deleted?")
         return None
     osimage = OsImage(osimage_name)
     old_dbref = self._get_json()['osimage']
     self.unlink(old_dbref)
     res = self._mongo_collection.update({'_id': self._id}, {'$set': {'osimage': osimage.DBRef}}, multi=False, upsert=False)
     self.link(osimage.DBRef)
     return not res['err']
Exemplo n.º 5
0
    def osimage(self, osimage_name):
        osimage = OsImage(osimage_name, mongo_db=self._mongo_db)

        old_image = self.get('osimage')
        self.unlink(old_image)

        res = self.set('osimage', osimage.DBRef)
        self.link(osimage.DBRef)

        return res
Exemplo n.º 6
0
    def boot_params(self):
        params = {}

        osimage = OsImage(id=self.get('osimage').id, mongo_db=self._mongo_db)
        params['kernel_file'] = osimage.get('kernfile')
        params['initrd_file'] = osimage.get('initrdfile')
        params['kern_opts'] = osimage.get('kernopts')
        params['domain'] = ''
        params['net'] = {}
        domaindbref = self.get('domain')

        if domaindbref:

            domainnet = self._get_network(netid=domaindbref.id)

            params['domain'] = domainnet.name

        if_list = self.list_ifs()
        bootif_uuid = None

        if 'BOOTIF' in if_list:
            bootif_uuid = if_list['BOOTIF']

        if not bootif_uuid:
            return params

        interfaces = self.get('interfaces')

        if not 'network' in interfaces[bootif_uuid]:
            return params

        for ver in ['4', '6']:
            if interfaces[bootif_uuid]['network'][ver]:
                params['net'][ver] = {}
                net_id = interfaces[bootif_uuid]['network'][ver].id
                net = self._get_network(netid=net_id)
                params['net'][ver]['prefix'] = str(net.get('PREFIX'))
                params['net'][ver]['mask'] = str(net.get('NETMASK'))

        if bootif_uuid and not params['net']:
            self.log.warning('No network is configured for BOOTIF')

        return params
Exemplo n.º 7
0
    def clone(self, name):

        osimage_dbref = self.get('osimage')
        osimage = OsImage(id=osimage_dbref.id, mongo_db=self._mongo_db)
        bmcsetup_name = None
        bmcsetup_dbref = self.get('bmcsetup')

        if bmcsetup_dbref:
            bmcsetup = BMCSetup(id=bmcsetup_dbref.id, mongo_db=self._mongo_db)
            bmcsetup_name = bmcsetup.name

        pre = self.get('prescript')
        post = self.get('postscript')
        part = self.get('partscript')

        comment = self.get('comment')

        if_list = self.list_ifs().keys()

        domain_dbref = self.get('domain')
        domain_name = None
        if domain_dbref:
            domain_net = Network(id=domain_dbref.id, mongo_db=self._mongo_db)
            domain_name = domain_net.name

        torrent_if = self.get('torrent_if')

        if not torrent_if:
            torrent_if = None

        group = Group(
            name=name,
            create=True,
            bmcsetup=bmcsetup_name,
            osimage=osimage.name,
            interfaces=if_list,
            prescript=pre,
            partscript=part,
            postscript=post,
            torrent_if=torrent_if,
            domain=domain_name,
            mongo_db=self._mongo_db,
        )
        group.set('comment', comment)

        for if_name in if_list:
            if_dict = self.show_if(if_name)
            for ver in ['4', '6']:
                if not if_dict['network'][ver]['name']:
                    continue
                group.set_net_to_if(if_name, if_dict['network'][ver]['name'])

        return group
Exemplo n.º 8
0
    def install_params(self):
        params = {}
        params['prescript'] = self.get('prescript')
        params['partscript'] = self.get('partscript')
        params['postscript'] = self.get('postscript')
        try:
            params['boot_if'] = self.get('boot_if')
        except:
            params['boot_if'] = ''
        try:
            params['torrent_if'] = self.get('torrent_if')
        except:
            params['torrent_if'] = ''
        json = self._get_json()
        if bool(params['torrent_if']):
            try:
                net_dbref = json['interfaces'][params['torrent_if']]['network']
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                params['torrent_if_net_prefix'] = str(net.get('PREFIX'))
            except:
                params['torrent_if'] = ''
        try:
            net_dbref = json['interfaces'][self.get('boot_if')]['network']
            net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
            params['domain'] = str(net.name)
        except:
            params['domain'] = ""
        params['interfaces'] = {}
        try:
            interfaces = json['interfaces'].keys()
            for interface in interfaces:
                params['interfaces'][str(interface)] = str(self.get_if_parms(interface))
        except:
            pass
        try:
            interfaces = json['interfaces'].keys()
        except:
            interfaces = []

        for interface in interfaces:
            net_dbref = json['interfaces'][interface]['network']
            try:
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                net_prefix = "\n" + "PREFIX=" + str(net.get('PREFIX'))
            except:
                net_prefix = ""
            params['interfaces'][str(interface)] = params['interfaces'][str(interface)].strip() + net_prefix
        osimage = OsImage(id = self.get('osimage').id, mongo_db = self._mongo_db)
        try:
            params['torrent'] = osimage.get('torrent') + ".torrent"
            params['tarball'] = osimage.get('tarball') + ".tgz"
        except:
            params['torrent'] = ""
            params['tarball'] = ""
        params['kernver'] = osimage.get('kernver')
        params['kernopts'] = osimage.get('kernopts')
        params['bmcsetup'] = {}
        if self.get('bmcsetup'):
            bmcsetup = BMCSetup(id = self.get('bmcsetup').id, mongo_db = self._mongo_db)
            params['bmcsetup']['mgmtchannel'] = bmcsetup.get('mgmtchannel') or 1
            params['bmcsetup']['netchannel'] = bmcsetup.get('netchannel') or 1
            params['bmcsetup']['userid'] = bmcsetup.get('userid') or 3
            params['bmcsetup']['user'] = bmcsetup.get('user') or "ladmin"
            params['bmcsetup']['password'] = bmcsetup.get('password') or "ladmin"
            try:
                net_dbref = json['bmcnetwork']
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                params['bmcsetup']['netmask'] = net.get('NETMASK')
            except:
                params['bmcsetup']['netmask'] = ''
        return params
Exemplo n.º 9
0
    def __init__(self, name=None, mongo_db=None, create=False,
                 id=None, prescript='', bmcsetup=None,
                 partscript='', osimage=None, interfaces=[],
                 postscript='', torrent_if=None, domain=None,
                 comment=''):
        """
        prescript   - preinstall script
        bmcsetup    - bmcsetup options
        partscript  - parition script
        osimage     - osimage
        interfaces  - list of the newtork interfaces
        postscript  - postinstall script
        """

        self.log.debug("function args {}".format(self._debug_function()))

        # Define the schema used to represent group objects

        self._collection_name = 'group'
        self._keylist = {
            'prescript': type(''),
            'partscript': type(''),
            'postscript': type(''),
            'torrent_if': type(''),
            'comment': type(''),
        }

        # Check if this group is already present in the datastore
        # Read it if that is the case

        group = self._get_object(name, mongo_db, create, id)

        if create:
            cluster = Cluster(mongo_db=self._mongo_db)
            osimageobj = OsImage(osimage, mongo_db=self._mongo_db)

            (bmcobj, domainobj) = (None, None)
            if bmcsetup:
                bmcobj = BMCSetup(bmcsetup, mongo_db=self._mongo_db).DBRef

            if domain:
                domainobj = Network(domain, mongo_db=self._mongo_db).DBRef

            if interfaces and type(interfaces) is not list:
                err_msg = "'interfaces' should be list"
                self.log.error(err_msg)
                raise RuntimeError, err_msg

            if not interfaces:
                interfaces = []

            if_dict = {}
            for interface in interfaces:
                if_dict[uuid.uuid4().hex] = {
                    'name': interface,
                    'network': {
                        '4': None,
                        '6': None
                    },
                    'params': ''
                }

            if not partscript:
                partscript = "mount -t tmpfs tmpfs /sysroot"

            if not postscript:
                postscript = ("cat << EOF >> /sysroot/etc/fstab\n"
                              "tmpfs   /       tmpfs    defaults        0 0\n"
                              "EOF")

            # Store the new group in the datastore

            group = {
                'name': name, 'prescript':  prescript,
                'bmcsetup': bmcobj, 'partscript': partscript,
                'osimage': osimageobj.DBRef, 'interfaces': if_dict,
                'postscript': postscript, 'domain': domainobj,
                'torrent_if': torrent_if, 'comment': comment,
            }

            self.log.debug("Saving group '{}' to the datastore".format(group))

            self.store(group)

            # Link this group to its dependencies and the current cluster

            self.link(cluster)

            if bmcobj:
                self.link(bmcobj)

            if domainobj:
                self.link(domainobj)

            self.link(osimageobj)

        self.log = logging.getLogger('group.' + self._name)
        self._networks = {}
Exemplo n.º 10
0
    def install_params(self):
        params = {}
        params['prescript'] = self.get('prescript')
        params['partscript'] = self.get('partscript')
        params['postscript'] = self.get('postscript')
        params['torrent_if'] = self.get('torrent_if')
        params['domain'] = ''

        domaindbref = self.get('domain')

        if domaindbref:
            domainnet = self._get_network(netid=domaindbref.id)

            params['domain'] = domainnet.name

        interfaces = self.get('interfaces')
        if_list = self.list_ifs()

        # now find torrent_if name and net prefix

        if params['torrent_if'] and not params['torrent_if'] in if_list.keys():

            self.log.error(
                ('No such interface {}. Unable to ' +
                 'set torrent_if').format(params['torrent_if'])
            )

            params['torrent_if'] = ''

        params['interfaces'] = {}

        for nic_uuid in interfaces:
            nic_name = interfaces[nic_uuid]['name']

            params['interfaces'][nic_name] = {}

            nicopts = self.get_if_params(nic_name).strip()

            params['interfaces'][nic_name]['options'] = nicopts

            for ver in ['4', '6']:
                params['interfaces'][nic_name][ver] = {
                    'prefix': '',
                    'netmask': '',
                    'ip': '',
                }
                if 'network' in interfaces[nic_uuid]:

                    net_prefix = ""
                    net_mask = ""

                    if not interfaces[nic_uuid]['network'][ver]:
                        continue

                    net_id = interfaces[nic_uuid]['network'][ver].id

                    net = self._get_network(netid=net_id)

                    net_prefix = str(net.get('PREFIX'))
                    net_mask = str(net.get('NETMASK'))

                    params['interfaces'][nic_name][ver]['prefix'] = net_prefix
                    params['interfaces'][nic_name][ver]['netmask'] = net_mask

        osimage = OsImage(id=self.get('osimage').id, mongo_db=self._mongo_db)

        params['kernver'] = osimage.get('kernver')
        params['kernopts'] = osimage.get('kernopts')
        params['torrent'] = osimage.get('torrent')
        params['tarball'] = osimage.get('tarball')

        if params['torrent']:
            params['torrent'] += ".torrent"
        else:
            params['torrent'] = ''

        if params['tarball']:
            params['tarball'] += ".tgz"
        else:
            params['tarball'] = ''

        params['bmcsetup'] = {}
        if self.get('bmcsetup'):

            bmc = BMCSetup(id=self.get('bmcsetup').id, mongo_db=self._mongo_db)
            params['bmcsetup']['mgmtchannel'] = bmc.get('mgmtchannel') or 1
            params['bmcsetup']['netchannel'] = bmc.get('netchannel') or 1
            params['bmcsetup']['userid'] = bmc.get('userid') or 3
            params['bmcsetup']['user'] = bmc.get('user') or "ladmin"
            params['bmcsetup']['password'] = bmc.get('password') or "ladmin"

        return params
Exemplo n.º 11
0
    def install_params(self):
        params = {}
        params['prescript'] = self.get('prescript')
        params['partscript'] = self.get('partscript')
        params['postscript'] = self.get('postscript')
        try:
            params['boot_if'] = self.get('boot_if')
        except:
            params['boot_if'] = ''
        try:
            params['torrent_if'] = self.get('torrent_if')
        except:
            params['torrent_if'] = ''
        json = self._get_json()
        if bool(params['torrent_if']):
            try:
                net_dbref = json['interfaces'][params['torrent_if']]['network']
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                params['torrent_if_net_prefix'] = str(net.get('PREFIX'))
            except:
                params['torrent_if'] = ''
        try:
            net_dbref = json['interfaces'][self.get('boot_if')]['network']
            net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
            params['domain'] = str(net.name)
        except:
            params['domain'] = ""
        params['interfaces'] = {}
        try:
            interfaces = json['interfaces'].keys()
            for interface in interfaces:
                params['interfaces'][str(interface)] = str(self.get_if_parms(interface))
        except:
            pass
        try:
            interfaces = json['interfaces'].keys()
        except:
            interfaces = []

        for interface in interfaces:
            net_dbref = json['interfaces'][interface]['network']
            try:
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                net_prefix = "\n" + "PREFIX=" + str(net.get('PREFIX'))
            except:
                net_prefix = ""
            params['interfaces'][str(interface)] = params['interfaces'][str(interface)].strip() + net_prefix
        osimage = OsImage(id = self.get('osimage').id, mongo_db = self._mongo_db)
        try:
            params['torrent'] = osimage.get('torrent') + ".torrent"
            params['tarball'] = osimage.get('tarball') + ".tgz"
        except:
            params['torrent'] = ""
            params['tarball'] = ""
        params['kernver'] = osimage.get('kernver')
        params['kernopts'] = osimage.get('kernopts')
        params['bmcsetup'] = {}
        if self.get('bmcsetup'):
            bmcsetup = BMCSetup(id = self.get('bmcsetup').id, mongo_db = self._mongo_db)
            params['bmcsetup']['mgmtchannel'] = bmcsetup.get('mgmtchannel') or 1
            params['bmcsetup']['netchannel'] = bmcsetup.get('netchannel') or 1
            params['bmcsetup']['userid'] = bmcsetup.get('userid') or 3
            params['bmcsetup']['user'] = bmcsetup.get('user') or "ladmin"
            params['bmcsetup']['password'] = bmcsetup.get('password') or "ladmin"
            try:
                net_dbref = json['bmcnetwork']
                net = Network(id = net_dbref.id, mongo_db = self._mongo_db)
                params['bmcsetup']['netmask'] = net.get('NETMASK')
            except:
                params['bmcsetup']['netmask'] = ''
        return params