当前位置: 首页>>代码示例>>Python>>正文


Python system.System类代码示例

本文整理汇总了Python中mcvirt.system.System的典型用法代码示例。如果您正苦于以下问题:Python System类的具体用法?Python System怎么用?Python System使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了System类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _removeLogicalVolume

    def _removeLogicalVolume(self, name, ignore_non_existent=False,
                             perform_on_nodes=False):
        """Removes a logical volume from the node/cluster"""
        # Create command arguments
        command_args = ['lvremove', '-f', self._getLogicalVolumePath(name)]
        try:
            # Determine if logical volume exists before attempting to remove it
            if (not (ignore_non_existent and
                     not self._checkLogicalVolumeExists(name))):
                System.runCommand(command_args)

            if perform_on_nodes and self._is_cluster_master:
                def remoteCommand(node):
                    remote_disk = self.get_remote_object(remote_node=node, registered=False)
                    remote_disk.removeLogicalVolume(
                        name=name, ignore_non_existent=ignore_non_existent
                    )

                cluster = self._get_registered_object('cluster')
                cluster.run_remote_command(callback_method=remoteCommand,
                                           nodes=self.vm_object._get_remote_nodes())

        except MCVirtCommandException, e:
            raise ExternalStorageCommandErrorException(
                "Error whilst removing disk logical volume:\n" + str(e)
            )
开发者ID:joesingo,项目名称:MCVirt,代码行数:26,代码来源:base.py

示例2: increaseSize

    def increaseSize(self, increase_size):
        """Increases the size of a VM hard drive, given the size to increase the drive by"""
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MODIFY_VM, self.vm_object
        )

        # Ensure disk exists
        self._ensure_exists()

        # Ensure VM is stopped
        from mcvirt.virtual_machine.virtual_machine import PowerStates
        if (self.vm_object._getPowerState() is not PowerStates.STOPPED):
            raise VmAlreadyStartedException('VM must be stopped before increasing disk size')

        # Ensure that VM has not been cloned and is not a clone
        if (self.vm_object.getCloneParent() or self.vm_object.getCloneChildren()):
            raise VmIsCloneException('Cannot increase the disk of a cloned VM or a clone.')

        command_args = ('lvextend', '-L', '+%sM' % increase_size,
                        self._getDiskPath())
        try:
            System.runCommand(command_args)
        except MCVirtCommandException, e:
            raise ExternalStorageCommandErrorException(
                "Error whilst extending logical volume:\n" + str(e)
            )
开发者ID:Adimote,项目名称:MCVirt,代码行数:26,代码来源:local.py

示例3: _zeroLogicalVolume

    def _zeroLogicalVolume(self, name, size, perform_on_nodes=False):
        """Blanks a logical volume by filling it with null data"""
        # Obtain the path of the logical volume
        lv_path = self._getLogicalVolumePath(name)

        # Create command arguments
        command_args = ['dd', 'if=/dev/zero', 'of=%s' % lv_path, 'bs=1M', 'count=%s' % size,
                        'conv=fsync', 'oflag=direct']
        try:
            # Create logical volume on local node
            System.runCommand(command_args)

            if perform_on_nodes and self._is_cluster_master:
                def remoteCommand(node):
                    remote_disk = self.get_remote_object(remote_node=node, registered=False)
                    remote_disk.zeroLogicalVolume(name=name, size=size)

                cluster = self._get_registered_object('cluster')
                cluster.run_remote_command(callback_method=remoteCommand,
                                           nodes=self.vm_object._get_remote_nodes())

        except MCVirtCommandException, e:
            raise ExternalStorageCommandErrorException(
                "Error whilst zeroing logical volume:\n" + str(e)
            )
开发者ID:joesingo,项目名称:MCVirt,代码行数:25,代码来源:base.py

示例4: resize

    def resize(self, size, increase=True, _f=None):
        """Reszie volume"""
        self._get_registered_object('auth').assert_user_type('ClusterUser',
                                                             allow_indirect=True)
        # Ensure volume exists
        self.ensure_exists()

        # Get size of current disk, to be able to roll back to current size
        _f.add_undo_argument(original_size=self.get_size())

        # If increasing disk size, prepend with plus (+)
        if increase:
            size = '+%s' % size

        # Compile arguments for resize
        command_args = ['/sbin/lvresize', '--size', '%sB' % size,
                        self.get_path()]
        try:
            # Create on local node
            System.runCommand(command_args)

        except MCVirtCommandException, exc:
            raise ExternalStorageCommandErrorException(
                "Error whilst resizing disk:\n" + str(exc)
            )
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:25,代码来源:lvm.py

示例5: createBackupSnapshot

    def createBackupSnapshot(self):
        """Creates a snapshot of the logical volume for backing up and locks the VM"""
        self._ensure_exists()
        # Ensure the user has permission to delete snapshot backups
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.BACKUP_VM,
            self.vm_object
        )

        # Ensure VM is registered locally
        self.vm_object.ensureRegisteredLocally()

        # Obtain logical volume names/paths
        backup_volume_path = self._getLogicalVolumePath(
            self._getBackupLogicalVolume())
        snapshot_logical_volume = self._getBackupSnapshotLogicalVolume()

        # Determine if logical volume already exists
        if self._checkLogicalVolumeActive(snapshot_logical_volume):
            raise BackupSnapshotAlreadyExistsException(
                'The backup snapshot for \'%s\' already exists: %s' %
                (backup_volume_path, snapshot_logical_volume)
            )

        # Lock the VM
        self.vm_object._setLockState(LockStates.LOCKED)

        try:
            System.runCommand(['lvcreate', '--snapshot', backup_volume_path,
                               '--name', self._getBackupSnapshotLogicalVolume(),
                               '--size', self.SNAPSHOT_SIZE])
            return self._getLogicalVolumePath(snapshot_logical_volume)
        except:
            self.vm_object._setLockState(LockStates.UNLOCKED)
            raise
开发者ID:joesingo,项目名称:MCVirt,代码行数:35,代码来源:base.py

示例6: wipe

 def wipe(self, _f=None):
     """Wipe the volume"""
     self._get_registered_object('auth').assert_user_type('ClusterUser',
                                                          allow_indirect=True)
     System.perform_dd(source=System.WIPE,
                       destination=self.get_path(),
                       size=self.get_size())
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:7,代码来源:base.py

示例7: _drbdOverwritePeer

 def _drbdOverwritePeer(self):
     """Force Drbd to overwrite the data on the peer"""
     System.runCommand([NodeDrbd.DrbdADM,
                        '--',
                        '--overwrite-data-of-peer',
                        'primary',
                        self.resource_name])
开发者ID:joesingo,项目名称:MCVirt,代码行数:7,代码来源:drbd.py

示例8: _createLogicalVolume

    def _createLogicalVolume(self, name, size, perform_on_nodes=False):
        """Creates a logical volume on the node/cluster"""
        volume_group = self._getVolumeGroup()

        # Create command list
        command_args = ['/sbin/lvcreate', volume_group, '--name', name, '--size', '%sM' % size]
        try:
            # Create on local node
            System.runCommand(command_args)

            if perform_on_nodes and self._is_cluster_master:
                def remoteCommand(node):
                    remote_disk = self.get_remote_object(remote_node=node, registered=False)
                    remote_disk.createLogicalVolume(name=name, size=size)

                cluster = self._get_registered_object('cluster')
                cluster.run_remote_command(callback_method=remoteCommand,
                                           nodes=self.vm_object._get_remote_nodes())

        except MCVirtCommandException, e:
            # Remove any logical volumes that had been created if one of them fails
            self._removeLogicalVolume(
                name,
                ignore_non_existent=True,
                perform_on_nodes=perform_on_nodes)
            raise ExternalStorageCommandErrorException(
                "Error whilst creating disk logical volume:\n" + str(e)
            )
开发者ID:joesingo,项目名称:MCVirt,代码行数:28,代码来源:base.py

示例9: _drbdSetPrimary

    def _drbdSetPrimary(self, allow_two_primaries=False):
        """Performs a Drbd 'primary' on the hard drive Drbd resource"""
        local_role_state, remote_role_state = self._drbdGetRole()

        # Check Drbd status
        self._checkDrbdStatus()

        # Ensure that role states are not unknown
        if (local_role_state is DrbdRoleState.UNKNOWN or
            (remote_role_state is DrbdRoleState.UNKNOWN and
             not self._ignore_drbd)):
            raise DrbdStateException('Drbd role is unknown for resource %s' %
                                     self.resource_name)

        # Ensure remote role is secondary
        if (not allow_two_primaries and
            remote_role_state is not DrbdRoleState.SECONDARY and
            not (DrbdRoleState.UNKNOWN and
                 self._ignore_drbd)):
            raise DrbdStateException(
                'Cannot make local Drbd primary if remote Drbd is not secondary: %s' %
                self.resource_name)

        # Set Drbd resource to primary
        System.runCommand([NodeDrbd.DrbdADM, 'primary', self.resource_name])
开发者ID:joesingo,项目名称:MCVirt,代码行数:25,代码来源:drbd.py

示例10: client_key_file

    def client_key_file(self):
        """Obtain the private key for the client key"""
        path = self._get_certificate_path('clientkey.pem')

        if not self._ensure_exists(path, assert_raise=False):
            System.runCommand([self.OPENSSL, 'genrsa', '-out', path, '2048'])

        return path
开发者ID:joesingo,项目名称:MCVirt,代码行数:8,代码来源:certificate_generator.py

示例11: _drbdDown

 def _drbdDown(self):
     """Performs a Drbd 'down' on the hard drive Drbd resource"""
     try:
         System.runCommand([NodeDrbd.DrbdADM, 'down', self.resource_name])
     except MCVirtCommandException:
         # If the Drbd down fails, attempt to wait 5 seconds and try again
         time.sleep(5)
         System.runCommand([NodeDrbd.DrbdADM, 'down', self.resource_name])
开发者ID:joesingo,项目名称:MCVirt,代码行数:8,代码来源:drbd.py

示例12: server_key_file

    def server_key_file(self):
        """Obtain the server private key file"""
        if not self.is_local:
            raise CACertificateNotFoundException('Server key file not available for remote node')

        path = self._get_certificate_path('serverkey.pem')
        if not self._ensure_exists(path, assert_raise=False):
            # Generate new SSL private key
            System.runCommand([self.OPENSSL, 'genrsa', '-out', path, '2048'])
        return path
开发者ID:joesingo,项目名称:MCVirt,代码行数:10,代码来源:certificate_generator.py

示例13: ca_key_file

    def ca_key_file(self):
        """Return/generate the CA prviate key."""
        if not self.is_local:
            raise CACertificateNotFoundException('CA key file not available for remote node')
        path = self._get_certificate_path('capriv.pem')

        if not self._ensure_exists(path, assert_raise=False):
            System.runCommand([self.OPENSSL, 'genrsa', '-out', path, '4096'])

        return path
开发者ID:joesingo,项目名称:MCVirt,代码行数:10,代码来源:certificate_generator.py

示例14: _drbdSetSecondary

 def _drbdSetSecondary(self):
     """Performs a Drbd 'secondary' on the hard drive Drbd resource"""
     # Attempt to set the disk as secondary
     set_secondary_command = [NodeDrbd.DrbdADM, 'secondary',
                              self.resource_name]
     try:
         System.runCommand(set_secondary_command)
     except MCVirtCommandException:
         # If this fails, wait for 5 seconds, and attempt once more
         time.sleep(5)
         System.runCommand(set_secondary_command)
开发者ID:joesingo,项目名称:MCVirt,代码行数:11,代码来源:drbd.py

示例15: dh_params_file

    def dh_params_file(self):
        """Return the path to the DH parameters file, and create it if it does not exist"""
        if not self.is_local:
            raise CACertificateNotFoundException('DH params file not available for remote node')

        path = self._get_certificate_path('dh_params')
        if not self._ensure_exists(path, assert_raise=False):
            # Generate new DH parameters
            Syslogger.logger().info('Generating DH parameters file')
            System.runCommand([self.OPENSSL, 'dhparam', '-out', path, '2048'])
            Syslogger.logger().info('DH parameters file generated')
        return path
开发者ID:joesingo,项目名称:MCVirt,代码行数:12,代码来源:certificate_generator.py


注:本文中的mcvirt.system.System类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。