Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kolla Ansible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Very Demiurge Very Mindful
Kolla Ansible
Commits
d54e7182
Commit
d54e7182
authored
9 years ago
by
Jenkins
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Enable find_disks module to match by filesystem label"
parents
dcc37238
428b4843
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker/kolla-ansible/find_disks.py
+59
-17
59 additions, 17 deletions
docker/kolla-ansible/find_disks.py
with
59 additions
and
17 deletions
docker/kolla-ansible/find_disks.py
+
59
−
17
View file @
d54e7182
...
@@ -20,16 +20,24 @@
...
@@ -20,16 +20,24 @@
DOCUMENTATION
=
'''
DOCUMENTATION
=
'''
---
---
module: find_disks
module: find_disks
short_description: Return list of devices containing a specfied label
short_description: Return list of devices containing a specfied
name or
label
description:
description:
- This will return a list of all devices with
a
GPT partition
label with
- This will return a list of all devices with
either
GPT partition
name
the name specified.
or filesystem label of
the name specified.
options:
options:
partition_nam
e:
match_mod
e:
description:
description:
- Partition name
- Label match mode, either strict or prefix
default:
'
strict
'
required: False
choices: [
"
strict
"
,
"
prefix
"
]
type: str
name:
description:
- Partition name or filesystem label
required: True
required: True
type: bool
type: str
aliases: [
'
partition_name
'
]
author: Sam Yaple
author: Sam Yaple
'''
'''
...
@@ -37,9 +45,23 @@ EXAMPLES = '''
...
@@ -37,9 +45,23 @@ EXAMPLES = '''
- hosts: ceph-osd
- hosts: ceph-osd
tasks:
tasks:
- name: Return all valid formated devices with the name KOLLA_CEPH_OSD
- name: Return all valid formated devices with the name KOLLA_CEPH_OSD
ceph_osd_list
:
find_disks
:
partition_
name:
'
KOLLA_CEPH_OSD
'
name:
'
KOLLA_CEPH_OSD
'
register: osds
register: osds
- hosts: swift-object-server
tasks:
- name: Return all valid devices with the name KOLLA_SWIFT
find_disks:
name:
'
KOLLA_SWIFT
'
register: swift_disks
- hosts: swift-object-server
tasks:
- name: Return all valid devices with wildcard name
'
swift_d*
'
find_disks:
name:
'
swift_d
'
match_mode:
'
prefix
'
register: swift_disks
'''
'''
import
json
import
json
...
@@ -48,21 +70,41 @@ import pyudev
...
@@ -48,21 +70,41 @@ import pyudev
def
main
():
def
main
():
argument_spec
=
dict
(
argument_spec
=
dict
(
partition_name
=
dict
(
required
=
True
,
type
=
'
str
'
)
match_mode
=
dict
(
required
=
False
,
choices
=
[
'
strict
'
,
'
prefix
'
],
default
=
'
strict
'
),
name
=
dict
(
aliases
=
[
'
partition_name
'
],
required
=
True
,
type
=
'
str
'
)
)
)
module
=
AnsibleModule
(
argument_spec
)
module
=
AnsibleModule
(
argument_spec
)
partition_name
=
module
.
params
.
get
(
'
partition_name
'
)
match_mode
=
module
.
params
.
get
(
'
match_mode
'
)
name
=
module
.
params
.
get
(
'
name
'
)
def
is_dev_matched_by_name
(
dev
,
name
):
if
dev
.
get
(
'
DEVTYPE
'
,
''
)
==
'
partition
'
:
dev_name
=
dev
.
get
(
'
ID_PART_ENTRY_NAME
'
,
''
)
else
:
dev_name
=
dev
.
get
(
'
ID_FS_LABEL
'
,
''
)
if
match_mode
==
'
strict
'
:
return
dev_name
==
name
elif
match_mode
==
'
prefix
'
:
return
dev_name
.
startswith
(
name
)
else
:
return
False
try
:
try
:
ret
=
list
()
ret
=
list
()
ct
=
pyudev
.
Context
()
ct
=
pyudev
.
Context
()
for
dev
in
ct
.
list_devices
(
subsystem
=
'
block
'
,
DEVTYPE
=
'
partition
'
):
for
dev
in
ct
.
list_devices
(
subsystem
=
'
block
'
):
if
dev
.
get
(
'
ID_PART_ENTRY_NAME
'
)
==
partition_name
:
if
is_dev_matched_by_name
(
dev
,
name
):
fs_uuid
=
dev
.
get
(
'
ID_FS_UUID
'
)
fs_uuid
=
dev
.
get
(
'
ID_FS_UUID
'
,
''
)
if
not
fs_uuid
:
fs_label
=
dev
.
get
(
'
ID_FS_LABEL
'
,
''
)
fs_uuid
=
''
if
dev
.
get
(
'
DEVTYPE
'
,
''
)
==
'
partition
'
:
dev_parent
=
dev
.
find_parent
(
'
block
'
).
device_node
device_node
=
dev
.
find_parent
(
'
block
'
).
device_node
ret
.
append
({
'
device
'
:
dev_parent
,
'
fs_uuid
'
:
fs_uuid
})
else
:
device_node
=
dev
.
device_node
ret
.
append
({
'
device
'
:
device_node
,
'
fs_uuid
'
:
fs_uuid
,
'
fs_label
'
:
fs_label
})
module
.
exit_json
(
disks
=
json
.
dumps
(
ret
))
module
.
exit_json
(
disks
=
json
.
dumps
(
ret
))
except
Exception
as
e
:
except
Exception
as
e
:
module
.
exit_json
(
failed
=
True
,
msg
=
repr
(
e
))
module
.
exit_json
(
failed
=
True
,
msg
=
repr
(
e
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment