Beispiel #1
0
    def computerPrepareImagingDirectory(self, uuid, imagingData=False):
        """
        Prepare a full imaging folder for client <uuid>

        if imagingData is False, ask the mmc agent for additional
        parameters (not yet done).

        @param mac : The mac address of the client
        @type menus: MAC Address
        @param imagingData : The data to use for image creation
        @type imagingData: ????
        """
        target_folder = os.path.join(
            PackageServerConfig().imaging_api['base_folder'],
            PackageServerConfig().imaging_api['computers_folder'], uuid)
        if os.path.isdir(target_folder):
            self.logger.debug(
                'Imaging: folder %s for client %s : It already exists !' %
                (target_folder, uuid))
            return True
        if os.path.exists(target_folder):
            self.logger.warn(
                'Imaging: folder %s for client %s : It already exists, but is not a folder !'
                % (target_folder, uuid))
            return False
        try:
            os.mkdir(target_folder)
            self.logger.debug('Imaging: folder %s for client %s was created' %
                              (target_folder, uuid))
        except Exception, e:
            self.logger.error(
                'Imaging: I was not able to create folder %s for client %s : %s'
                % (target_folder, uuid, e))
            return False
Beispiel #2
0
 def _getXMLRPCClient(self):
     """
     @return: a XML-RPC client allowing to connect to the agent
     @rtype: ImagingXMLRPCClient
     """
     url, _ = makeURL(PackageServerConfig().mmc_agent)
     return ImagingXMLRPCClient(
         '', url,
         PackageServerConfig().mmc_agent['verifypeer'],
         PackageServerConfig().mmc_agent['cacert'],
         PackageServerConfig().mmc_agent['localcert'])
Beispiel #3
0
 def init(self):
     """
     Initialize object, and the RPCStore object.
     """
     self.logger = logging.getLogger('imaging')
     self.logger.debug('Initializing imaging RPC replay manager')
     self.timer = PackageServerConfig().imaging_api['rpc_loop_timer']
     self.count = PackageServerConfig().imaging_api['rpc_count']
     self.interval = PackageServerConfig().imaging_api['rpc_interval']
     self._replaying = False
     self._delayedCall = None
     self.store = RPCStore()
     self.store.init()
     reactor.addSystemEventTrigger('before', 'shutdown', self.cancelLoop)
Beispiel #4
0
    def computerUpdate(self, MACAddress):
        """
        Method to update the menu a computer.

        @raise TypeError: if MACAddress is malformed
        @return: a deferred object resulting to 1 if update was
                 successful, else 0.
        @rtype: int
        """
        def onSuccess(result):
            # TODO : add menu re-generation here
            return 1

        if not isMACAddress(MACAddress):
            raise TypeError

        url, credentials = makeURL(PackageServerConfig().mmc_agent)

        self.logger.info('Imaging: Starting menu update for %s' % (MACAddress))
        client = self._getXMLRPCClient()
        func = 'imaging.getMenu'
        args = (MACAddress)
        d = client.callRemote(func, *args)
        d.addCallbacks(onSuccess, client.onError, errbackArgs=(func, args, 0))
        return d
Beispiel #5
0
 def init(self):
     """
     Initialize object.
     """
     self.logger = logging.getLogger('imaging')
     self.logger.debug('Initializing imaging RPC replay file')
     self.filename = PackageServerConfig().imaging_api['rpc_replay_file']
     try:
         self._initStateFile()
     except Exception, e:
         self.logger.error('Can\'t initialize the RPC store file: %s. If the file looks corrupted, just delete it and restart the service.' % self.filename)
         raise e
Beispiel #6
0
    def computerCreateImageDirectory(self, mac):
        """
        Create an image folder for client <mac>

        This is quiet different as for the LRS, where the UUID was given
        in revosavedir (kernel command line) : folder is now generated
        real-time, if no generation has been done backup is dropped
        client-side

        @param mac : The mac address of the client
        @type mac: MAC Address

        @return: True if the folder
        @rtype: bool
        """
        def _onSuccess(result):
            if type(result) != list and len(result) != 2:
                self.logger.error(
                    'Imaging: Couldn\'t register on the MMC agent the image with UUID %s : %s'
                    % (image_uuid, str(result)))
                ret = False
            elif not result[0]:
                self.logger.error(
                    'Imaging: Couldn\'t register on the MMC agent the image with UUID %s : %s'
                    % (image_uuid, result[1]))
                ret = False
            else:
                image_path = os.path.join(
                    self.config.imaging_api['base_folder'],
                    self.config.imaging_api['masters_folder'], image_uuid)
                self.logger.debug(
                    'Imaging: Successfully registered disk image to %s' %
                    image_path)
                ret = image_uuid
            return ret

        def _gotMAC(result):
            """
            Process result return by getComputerByMac, BTW should be either False or the required info
            """
            if not result:
                self.logger.error(
                    "Can't get computer UUID for MAC address %s" % (mac))
                os.rmdir(os.path.join(target_folder, image_uuid))
                return False
            else:  # start gathering details about our image
                c_uuid = result['uuid']
                isMaster = False  # by default, an image is private
                path = os.path.join(self.config.imaging_api['base_folder'],
                                    self.config.imaging_api['masters_folder'],
                                    image_uuid)
                size = 0
                creationDate = tuple(gmtime())
                name = "Backup of %s" % result['shortname']
                desc = "In Progress"
                creator = ""
                state = "EMPTY"  # FIXME : define and use consts

                client = self._getXMLRPCClient()
                func = 'imaging.imageRegister'
                args = (self.config.imaging_api['uuid'], c_uuid, image_uuid,
                        isMaster, name, desc, path, size, creationDate,
                        creator, state)
                d = client.callRemote(func, *args)
                d.addCallbacks(_onSuccess,
                               RPCReplay().onError,
                               errbackArgs=(func, args, False))
                return image_uuid

        shortname = self.getClientShortname(mac)
        if shortname:
            self.logger.info(
                'Imaging: Client %s (%s) is creating a disk image' %
                (shortname, mac))
        else:
            self.logger.info('Imaging: Client %s is creating a disk image' %
                             (mac))

        if not isMACAddress(mac):
            raise TypeError

        target_folder = os.path.join(
            PackageServerConfig().imaging_api['base_folder'],
            PackageServerConfig().imaging_api['masters_folder'])
        # compute our future UUID, using the MAC address as node
        # according the doc, the node is a 48 bits (= 6 bytes) integer
        attempts = 10
        while attempts:
            image_uuid = str(uuid.uuid1(macToNode(mac)))
            if not os.path.exists(os.path.join(target_folder, image_uuid)):
                break
            attempts -= 1
        if not attempts:
            self.logger.warn(
                'Imaging: I was not able to create a folder for client %s' %
                (mac))
            return maybeDeferred(lambda x: x, False)

        try:
            os.mkdir(os.path.join(target_folder, image_uuid))
        except Exception, e:
            self.logger.warn(
                'Imaging: I was not able to create folder %s for client %s : %s'
                % (os.path.join(target_folder, image_uuid), mac, e))
            return maybeDeferred(lambda x: x, False)
Beispiel #7
0
 def _success(params):
     PackageServerConfig().pxe_password = params['pxe_password']
     PackageServerConfig().pxe_keymap = params['pxe_keymap']
     if callback: callback.__call__(*args, **kw)