Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(356)

Unified Diff: hooks/charmhelpers/contrib/storage/linux/utils.py

Issue 108840044: Fill out the HM9000 implementation
Patch Set: Fill out the HM9000 implementation Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « hooks/charmhelpers/contrib/storage/linux/lvm.py ('k') | hooks/charmhelpers/core/hookenv.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: hooks/charmhelpers/contrib/storage/linux/utils.py
=== modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py'
--- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-14 16:40:09 +0000
+++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-30 23:34:00 +0000
@@ -1,4 +1,5 @@
-from os import stat
+import os
+import re
from stat import S_ISBLK
from subprocess import (
@@ -14,7 +15,9 @@
:returns: boolean: True if path is a block device, False if not.
'''
- return S_ISBLK(stat(path).st_mode)
+ if not os.path.exists(path):
+ return False
+ return S_ISBLK(os.stat(path).st_mode)
def zap_disk(block_device):
@@ -29,7 +32,18 @@
'--clear', block_device])
dev_end = check_output(['blockdev', '--getsz', block_device])
gpt_end = int(dev_end.split()[0]) - 100
- check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
+ check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
'bs=1M', 'count=1'])
- check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
- 'bs=512', 'count=100', 'seek=%s'%(gpt_end)])
+ check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
+ 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
+
+def is_device_mounted(device):
+ '''Given a device path, return True if that device is mounted, and False
+ if it isn't.
+
+ :param device: str: Full path of the device to check.
+ :returns: boolean: True if the path represents a mounted device, False if
+ it doesn't.
+ '''
+ out = check_output(['mount'])
+ return bool(re.search(device + r"[0-9]+\b", out))
« no previous file with comments | « hooks/charmhelpers/contrib/storage/linux/lvm.py ('k') | hooks/charmhelpers/core/hookenv.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b