Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
71c46efe
Commit
71c46efe
authored
Jul 10, 2014
by
Steve Salevan
Committed by
Steve Salevan
Jul 10, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving to_safe back into class for consistency purposes
parent
e621b3a8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
plugins/inventory/collins.py
+11
-11
No files found.
plugins/inventory/collins.py
View file @
71c46efe
...
@@ -93,13 +93,6 @@ class CollinsDefaults(object):
...
@@ -93,13 +93,6 @@ class CollinsDefaults(object):
LOG_FORMAT
=
'
%(asctime)-15
s
%(message)
s'
LOG_FORMAT
=
'
%(asctime)-15
s
%(message)
s'
def
to_safe
(
word
):
""" Converts 'bad' characters in a string to underscores so they
can be used as Ansible groups """
return
re
.
sub
(
"[^A-Za-z0-9
\
-]"
,
"_"
,
word
)
class
CollinsInventory
(
object
):
class
CollinsInventory
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -317,14 +310,15 @@ class CollinsInventory(object):
...
@@ -317,14 +310,15 @@ class CollinsInventory(object):
# Adds an asset index to the Ansible inventory based upon unpacking
# Adds an asset index to the Ansible inventory based upon unpacking
# the name of the asset's current STATE from its dictionary.
# the name of the asset's current STATE from its dictionary.
if
'STATE'
in
asset
[
'ASSET'
]
and
asset
[
'ASSET'
][
'STATE'
]:
if
'STATE'
in
asset
[
'ASSET'
]
and
asset
[
'ASSET'
][
'STATE'
]:
state_inventory_key
=
to_safe
(
'STATE-
%
s'
%
asset
[
'ASSET'
][
'STATE'
][
'NAME'
])
state_inventory_key
=
self
.
to_safe
(
'STATE-
%
s'
%
asset
[
'ASSET'
][
'STATE'
][
'NAME'
])
self
.
push
(
self
.
inventory
,
state_inventory_key
,
asset_identifier
)
self
.
push
(
self
.
inventory
,
state_inventory_key
,
asset_identifier
)
# Indexes asset by all user-defined Collins attributes.
# Indexes asset by all user-defined Collins attributes.
if
'ATTRIBS'
in
asset
:
if
'ATTRIBS'
in
asset
:
for
attrib_block
in
asset
[
'ATTRIBS'
]
.
keys
():
for
attrib_block
in
asset
[
'ATTRIBS'
]
.
keys
():
for
attrib
in
asset
[
'ATTRIBS'
][
attrib_block
]
.
keys
():
for
attrib
in
asset
[
'ATTRIBS'
][
attrib_block
]
.
keys
():
attrib_key
=
to_safe
(
attrib_key
=
self
.
to_safe
(
'
%
s-
%
s'
%
(
attrib
,
asset
[
'ATTRIBS'
][
attrib_block
][
attrib
]))
'
%
s-
%
s'
%
(
attrib
,
asset
[
'ATTRIBS'
][
attrib_block
][
attrib
]))
self
.
push
(
self
.
inventory
,
attrib_key
,
asset_identifier
)
self
.
push
(
self
.
inventory
,
attrib_key
,
asset_identifier
)
...
@@ -333,7 +327,7 @@ class CollinsInventory(object):
...
@@ -333,7 +327,7 @@ class CollinsInventory(object):
if
attribute
not
in
CollinsDefaults
.
SPECIAL_ATTRIBUTES
:
if
attribute
not
in
CollinsDefaults
.
SPECIAL_ATTRIBUTES
:
attribute_val
=
asset
[
'ASSET'
][
attribute
]
attribute_val
=
asset
[
'ASSET'
][
attribute
]
if
attribute_val
is
not
None
:
if
attribute_val
is
not
None
:
attrib_key
=
to_safe
(
'
%
s-
%
s'
%
(
attribute
,
attribute_val
))
attrib_key
=
self
.
to_safe
(
'
%
s-
%
s'
%
(
attribute
,
attribute_val
))
self
.
push
(
self
.
inventory
,
attrib_key
,
asset_identifier
)
self
.
push
(
self
.
inventory
,
attrib_key
,
asset_identifier
)
# Indexes asset by hardware product information.
# Indexes asset by hardware product information.
...
@@ -341,7 +335,7 @@ class CollinsInventory(object):
...
@@ -341,7 +335,7 @@ class CollinsInventory(object):
if
'PRODUCT'
in
asset
[
'HARDWARE'
][
'BASE'
]:
if
'PRODUCT'
in
asset
[
'HARDWARE'
][
'BASE'
]:
product
=
asset
[
'HARDWARE'
][
'BASE'
][
'PRODUCT'
]
product
=
asset
[
'HARDWARE'
][
'BASE'
][
'PRODUCT'
]
if
product
:
if
product
:
product_key
=
to_safe
(
product_key
=
self
.
to_safe
(
'HARDWARE-PRODUCT-
%
s'
%
asset
[
'HARDWARE'
][
'BASE'
][
'PRODUCT'
])
'HARDWARE-PRODUCT-
%
s'
%
asset
[
'HARDWARE'
][
'BASE'
][
'PRODUCT'
])
self
.
push
(
self
.
inventory
,
product_key
,
asset_identifier
)
self
.
push
(
self
.
inventory
,
product_key
,
asset_identifier
)
...
@@ -414,6 +408,12 @@ class CollinsInventory(object):
...
@@ -414,6 +408,12 @@ class CollinsInventory(object):
cache
.
write
(
json_data
)
cache
.
write
(
json_data
)
cache
.
close
()
cache
.
close
()
def
to_safe
(
self
,
word
):
""" Converts 'bad' characters in a string to underscores so they
can be used as Ansible groups """
return
re
.
sub
(
"[^A-Za-z0-9
\
-]"
,
"_"
,
word
)
def
json_format_dict
(
self
,
data
,
pretty
=
False
):
def
json_format_dict
(
self
,
data
,
pretty
=
False
):
""" Converts a dict to a JSON object and dumps it as a formatted string """
""" Converts a dict to a JSON object and dumps it as a formatted string """
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment