Commit Graph

59 Commits

Author SHA1 Message Date
Radostin Stoyanov
95c695d774 Convert long to int
- Python 2 only
k = 9223372036854775808L

- Python 2 and 3:
k = 9223372036854775808

See http://python-future.org/compatible_idioms.html#long-integers
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
6712261510 Python 2/3 division compatability
In Python 2 the classic devision of integers returns an integer
but in Python 3 it might return float.

Example:
- Python 2:          - Python 3:
    >>> 9 / 4            >>> 9 / 4
    2                    2.25
    >>> 9 // 4           >>> 9 // 4
    2                    2
    >>> 9 / 4.0          >>> 9 / 4.0
    2.25                 2.25
    >>> 9 // 4.0         >>> 9 // 4.0
    2.0                  2.0

For more info see: https://www.python.org/dev/peps/pep-0238/
2018-01-27 15:30:17 -05:00
Radostin Stoyanov
dff00d4fc0 Remove deprecated statvfs module
The statvfs module has been removed in Python 3. [1]
It is replaced by os.statvfs which is also available in Pyhton 2.

[1] https://docs.python.org/2/library/statvfs.html#module-statvfs
[2] https://docs.python.org/3/library/os.html#os.statvfs
2017-10-20 11:49:14 -04:00
Pavel Hrdina
6e6f59e7ab diskbackend: get a proper size of existing block device while cloning
We cannot use os.statvfs() if the clone disk is a block device because
it gets stats about filesystem which in this case is "devtmpfs" mounted
as "/dev".

As a workaround we can seek to the end of the block device to get
the actual size.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1450908

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 09:12:05 +02:00
Pavel Hrdina
e73abe5a3a diskbackend: convert to long the calculated size
If we convert to long the disk size, it may end up "0".  The size is
in GiB so it can be "0.1".

Introduced by commit <fab55c128ff3f092039bb950ecfd337568d2a9a8>.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 09:06:44 +02:00
Chen Hanxiao
c92aade081 pycodestyle: fix all E203 warnings
Fix all E203 whitespace before ':'
   Also remove E203 ignore option of pycodestyle

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2017-08-11 00:01:38 +08:00
Radostin Stoyanov
b93cc3bbc9 pycodestyle: Do not use bare 'except:'
A bare 'except:' catches all exceptions [1], including SystemExit,
KeyboardInterrupt, and GeneratorExit (which is not an error and should
not normally be caught by user code). In situations where you need to
catch all “normal” errors, you can catch the base class for all normal
exceptions, Exception [2].

[1] https://docs.python.org/2/howto/doanddont.html#except
[2] https://docs.python.org/2/library/exceptions.html#Exception
2017-08-02 13:57:43 -04:00
Cole Robinson
a9903ae0e0 connection: Remove clear_cache callback
It doesn't actually accomplish what we want for the virt-manager case,
and cache_new_pool should cover our needs now
2017-07-20 17:30:37 -04:00
Pavel Hrdina
713e07d4a2 virtinst.diskbackend: set pool after creating StorageVolume
The _pool_xml in StorageVolume is used unconditionally, we need to
set it right away.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1450311

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-05-17 18:35:54 +02:00
Cole Robinson
fab55c128f Drop use of python2 long() syntax
Plus one more python3 syntax issue
2017-05-05 14:54:35 -04:00
Cole Robinson
a90d675394 Switch deprecating log.warn to log.warning
Same semantics, but the alias is deprecated
2017-05-05 14:53:28 -04:00
Cole Robinson
34c193108c Use python3 compatible octal notation 2017-05-05 14:52:11 -04:00
Cole Robinson
62feeb02a8 Switch to python3 style 'except X as Y' notation
Which also works with python2.7
2017-05-05 14:52:11 -04:00
Cole Robinson
9c8ffe51da storage: Move alloc/cap validation to validate()
Doing this at property set time is overly noisy. Follow the same
pattern of VirtualDisk and only do this in the validate() function.

https://bugzilla.redhat.com/show_bug.cgi?id=1433239
2017-03-17 12:14:05 -04:00
Pavel Hrdina
82eaf4742e virtinst.storage: improve detection of disk type
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-03-06 14:31:42 -05:00
Pavel Hrdina
af60c860d1 virtinst.diskbackend: unify how we get disk type
Both StorageCreator and StorageBackend should use the same logic
to detect the disk type.  Now if the target is block device we will
detect it correctly.

The check for block type doesn't make sense because that code is
executed only for local cloning without Libvirt help which is the
only way how we can clone some block disks.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1420187

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-03-06 14:31:42 -05:00
Cole Robinson
5dea1c2d80 util: privatize stat_disk() 2016-08-24 15:56:13 -04:00
Cole Robinson
4f9fd84f8f diskbackend: Use type=file for empty cdrom, not type=block
It doesn't have any operational effect, however since most people use
type=file for cdrom isos, this makes it easier for people to hand edit
the XML.
2015-11-21 20:07:05 -05:00
Pavel Hrdina
c7049eb120 pep8 W503: line break before binary operator
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-07-14 13:01:20 -04:00
Giuseppe Scrivano
f5a13510eb clone: do not use a '/' separator when using a disk file under /
It avoids file names like //foo.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1210564

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-06-06 00:00:40 +02:00
Cole Robinson
4553912c64 diskbackend: Fix busted volume lookup API name 2015-04-13 16:41:59 -04:00
Cole Robinson
9ae3dbe05b virt-install: Fix --disk pool=NETPOOL,size=... creation 2014-12-10 13:22:42 -05:00
Cole Robinson
117cbfe12f devicedisk: Don't set driver name=unknown for rbd vols 2014-12-10 13:22:42 -05:00
Cole Robinson
12340a3858 diskbackend: Try looking up network volumes by path
For gluster volumes, which have unique URLs for volume paths, this
makes selecting network volumes via the storagebrowser UI work.

Sheepdog and RBD volumes don't work yet
2014-12-10 09:04:29 -05:00
Cole Robinson
464ebabc5a virt-install: Wire up --disk vol= for network volumes
This involves convering pool/vol XML to disk source bits
2014-12-09 18:23:22 -05:00
Cole Robinson
214872498d test: Set volume type in testdriver XML 2014-12-09 17:50:16 -05:00
Cole Robinson
f7c17d4c46 diskbackend: Mandate parent_pool when vol_object is passed
We will need parent pool for looking up info about network volumes
2014-12-09 17:03:48 -05:00
Cole Robinson
208672eea9 diskbackend: Minor simplifications 2014-12-09 16:57:32 -05:00
Cole Robinson
9952764dda virt-install: Make --disk $URL 'just work'
If VirtualDisk.path is set to a URL, parse it and fill in all the
source_* values automagically.
2014-12-09 10:45:26 -05:00
Cole Robinson
3ac272e635 uri: Add unit tests, fix some bugs 2014-12-09 10:15:53 -05:00
Cole Robinson
1c79b936f5 diskbackend: Check if the passed path is a url 2014-12-09 08:44:45 -05:00
Cole Robinson
c5ccd68e4d devicedisk: Handle an empty storage backend
Rather than have every little bit depend on a present storage backend,
only create one when it really matters.
2014-12-09 08:44:45 -05:00
Cole Robinson
f0b8062226 devicedisk: Unify StorageCreator vs StorageBackend handling 2014-12-09 08:44:45 -05:00
Cole Robinson
db0942bd09 diskbackend: Document the various classes 2014-12-09 08:44:44 -05:00
Chen Hanxiao
802e57ea5e diskbackend: fix some comment typos
s/if/If
s/a/an

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2014-12-09 15:53:21 +08:00
Cole Robinson
cd305da3f8 virt-install: support network --disk's
Handle type=network in devicedisk.py, and wire up all the network fields
for virt-install --disk. Right now it requires manually spelling out
all the protocol, name, host/port etc fields.

The one 'magic' bit is that VirtualDisk.path will be a pretty URL when
all those network fields are specified. This is keeps things mostly
working in various parts of the code where we expect 'path' to be an
identifier for a VirtualDisk.
2014-12-06 21:00:51 -05:00
Cole Robinson
52691c511e devicedisk: Move more validation into diskbackend 2014-12-06 16:44:21 -05:00
Cole Robinson
cf0206a58c devicedisk: Break apart set_create_storage
And break about the vol_install vs local clone storage creators. And
just generally delete a lot of code. The commit aint pretty but it works
and deletes a ton of hacks
2014-12-05 23:28:53 -05:00
Cole Robinson
2acbf52ce3 cli: If creating storage, always build vol_install
This is the start of moving this logic out of devicedisk
2014-12-05 20:00:11 -05:00
Cole Robinson
ef0beeb18b cli: Clean up disk source handling
...sort of. This stuff is a hairy mess, but this makes it more stream line
and easier to extend.
2014-12-05 19:05:15 -05:00
Cole Robinson
dfc062c611 diskbackend: Make check_if_path_managed more readable 2014-12-04 21:08:38 -05:00
Cole Robinson
ba05e1cd43 diskbackend: Drop all pool source matching
It's only used to try and determine if a path actually exists, however
in the pool source case there isn't much we can actually do with that
info.
2014-12-04 20:10:37 -05:00
Cole Robinson
0389ab23a7 diskbackend: Remove backing by pool object
It just muddles things up for a minor edge case. The autopoolify logic
should catch all practical cases we care about.
2014-12-04 19:45:00 -05:00
Cole Robinson
26d16a5978 diskbackend: Fix typo 2014-10-29 12:35:18 -04:00
Cole Robinson
eb7612356e virtinst: Switch to relative imports, fix cyclic import warnings 2014-09-12 16:28:38 -04:00
Cole Robinson
f512c05381 diskbackend: Get volume path from XML
The XML is likely already cached, and path() can hit the network, so
this can speed things up.
2014-09-12 16:28:38 -04:00
Cole Robinson
3064f4058d diskbackend: Simplify pool source lookup
Have it share logic with a similar routine
2014-09-12 16:28:38 -04:00
Ron
ea1d973957 Don't create disk images world readable and executable
Python's os.open() defaults to mode 0777 if not explicitly specified.
Disk image files don't need to be executable, and having them world
readable isn't an ideal situation either.  Owner writable and group
readable is probably more than sufficient when initially creating
them.

Signed-off-by: Ron Lee <ron@debian.org>
2014-07-02 07:35:15 +02:00
Cole Robinson
809c5a81e5 diskbackend: Fix pool 'create' call (bz 1103442) 2014-06-03 16:26:28 -04:00
Cole Robinson
d6f063d0b8 diskbackend: If pool not running, start it
Nowadays we depend on the pool existing and running, so better to get
an error up front if pool startup will fail
2014-05-31 16:29:29 -04:00