• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python system.System类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: snapshot

 def snapshot(self, destination_volume, size):
     """Snapshot volume"""
     # Ensure volume exists
     self.ensure_exists()
     try:
         System.runCommand(['lvcreate', '--snapshot', self.get_path(),
                            '--name', destination_volume.name,
                            '--size', str(size)])
     except MCVirtCommandException, exc:
         raise ExternalStorageCommandErrorException(
             "Error whilst snapshotting disk:\n" + str(exc)
         )
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:12,代码来源:lvm.py


示例17: _sign_csr

    def _sign_csr(self, csr):
        self.client_csr = csr
        cert_gen_factory = self._get_registered_object('certificate_generator_factory')
        local_server = cert_gen_factory.get_cert_generator('localhost')
        System.runCommand(['openssl', 'x509', '-req', '-extensions', 'usr_cert',
                           '-in', self.client_csr, '-CA', local_server.ca_pub_file,
                           '-CAkey', local_server.ca_key_file, '-CAcreateserial',
                           '-out', self.client_pub_file, '-outform', 'PEM', '-days', '10240',
                           '-sha256'])

        # Regenerate libvirtd configuration, allowing access to this certificate
        if self.is_local:
            self._get_registered_object('libvirt_config').hard_restart = True
        self._get_registered_object('libvirt_config').generate_config()
        return self._read_file(self.client_pub_file)
开发者ID:joesingo,项目名称:MCVirt,代码行数:15,代码来源:certificate_generator.py


示例18: test_verify

    def test_verify(self):
        """Test the Drbd verification for both in-sync and out-of-sync Drbd volumes"""
        # Create Virtual machine
        test_vm_object = self.create_vm('TEST_VM_1', 'Drbd')
        self.assertTrue(self.vm_factory.check_exists(self.test_vms['TEST_VM_1']['name']))

        # Wait for 10 seconds after creation to ensure that Drbd
        # goes into connection -> Resyncing state
        time.sleep(10)

        # Wait until the Drbd resource is synced
        for disk_object in test_vm_object.getHardDriveObjects():
            self.rpc.annotate_object(disk_object)
            wait_timeout = 6
            while disk_object.drbdGetConnectionState() != DrbdConnectionState.CONNECTED:
                # If the Drbd volume has not connected within 1 minute, throw an exception
                if not wait_timeout:
                    raise DrbdVolumeNotInSyncException('Wait for Drbd connection timed out')

                time.sleep(10)
                wait_timeout -= 1

        # Perform verification on VM, using the argument parser
        self.parser.parse_arguments('verify %s' % self.test_vms['TEST_VM_1']['name'])

        # Ensure the disks are in-sync
        for disk_object in test_vm_object.getHardDriveObjects():
            self.rpc_annotate_object(disk_object)
            self.assertTrue(disk_object._isInSync())

        # Obtain the Drbd raw volume for the VM and write random data to it
        for disk_object in test_vm_object.getHardDriveObjects():
            self.rpc.annotate_object(disk_object)
            drbd_raw_suffix = disk_object.Drbd_RAW_SUFFIX
            raw_logical_volume_name = disk_object._getLogicalVolumeName(drbd_raw_suffix)
            raw_logical_volume_path = disk_object._getLogicalVolumePath(raw_logical_volume_name)
            System.runCommand(['dd', 'if=/dev/urandom',
                               'of=%s' % raw_logical_volume_path,
                               'bs=1M', 'count=8'])
            System.runCommand(['sync'])

        # Perform another verification and ensure that an exception is raised
        with self.assertRaises(DrbdVolumeNotInSyncException):
            self.parser.parse_arguments('verify %s' % self.test_vms['TEST_VM_1']['name'])

        # Attempt to start the VM, ensuring an exception is raised
        with self.assertRaises(DrbdVolumeNotInSyncException):
            test_vm_object.start()
开发者ID:Adimote,项目名称:MCVirt,代码行数:48,代码来源:drbd_tests.py


示例19: activate

    def activate(self, _f=None):
        """Activate volume"""
        self._get_registered_object('auth').assert_user_type('ClusterUser',
                                                             allow_indirect=True)
        # Ensure volume exists
        self.ensure_exists()
        # Create command arguments
        command_args = ['lvchange', '-a', 'y', '--yes', self.get_path()]
        try:
            # Run on the local node
            System.runCommand(command_args)

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


示例20: authenticate_username_password

 def authenticate_username_password(self, args, ignore_cluster):
     """Authenticate using username and password"""
     # Check if user/password have been passed. Else, ask for them.
     username = args.username if args.username else System.getUserInput(
         'Username: '
     ).rstrip()
     if args.password:
         password = args.password
     else:
         password = System.getUserInput(
             'Password: ', password=True
         ).rstrip()
     self.rpc = Connection(username=username, password=password,
                           ignore_cluster=ignore_cluster)
     self.session_id = self.rpc.session_id
     self.username = self.rpc.username
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:16,代码来源:parser.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_hostname函数代码示例发布时间:2022-05-27
下一篇:
Python syslogger.Syslogger类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap