use first capture group in regex
This commit is contained in:
parent
d90eac3fe6
commit
9f0db28ed8
4 changed files with 12 additions and 11 deletions
|
|
@ -10,7 +10,7 @@ class Datacenter():
|
|||
This class is used to guess the datacenter in order to push the information
|
||||
in Netbox for a `Device`
|
||||
|
||||
A driver takes a `value` and evaluates a regex with a `named group`: `datacenter`.
|
||||
A driver takes a `value` and evaluates a regex with a `capture group`.
|
||||
|
||||
There's embeded drivers such as `file` or `cmd` which read a file or return the
|
||||
output of a file.
|
||||
|
|
@ -20,7 +20,7 @@ class Datacenter():
|
|||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.driver = DATACENTER_LOCATION.split(':')[0]
|
||||
self.driver_value = DATACENTER_LOCATION.split(':')[1]
|
||||
self.driver_value = ':'.join(DATACENTER_LOCATION.split(':')[1:])
|
||||
self.driver_file = DATACENTER_LOCATION_DRIVER_FILE
|
||||
|
||||
if self.driver_file:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import subprocess
|
|||
def get(value, regex):
|
||||
output = subprocess.getoutput(value)
|
||||
r = re.search(regex, output)
|
||||
if r:
|
||||
result = r.group('datacenter')
|
||||
return result
|
||||
if r and len(r.groups()) > 0:
|
||||
return r.groups()[0]
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ import re
|
|||
def get(value, regex):
|
||||
for line in open(value, 'r'):
|
||||
r = re.search(regex, line)
|
||||
if r:
|
||||
return r.group('datacenter')
|
||||
if r and len(r.groups()) > 0:
|
||||
return r.groups()[0]
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue