class Devices:
def __init__(self, fqdn):
self.fqdn = fqdn
def domain(self, fqdn):
self.fqdn = fqdn.split(".")
if fqdn.split(".")[1] == 'sa':
return 'South America'
elif fqdn.split(".")[1] == 'na':
return 'North America'
elif fqdn.split(".")[1] == 'ap':
return 'Asia Pacific'
elif fqdn.split(".")[1] == 'ea':
return "Europe"
device_1 = Devices('retuyr.sa.abc.com')
device_2 = Devices('agtrah.na.abc.com')
domain1 = Devices('retuyr.sa.abc.com')
domain2 = Devices('agtrah.na.abc.com')
print('FQDN: %s' % device_1.fqdn)
print('Region is: %s' % domain1.domain(fqdn='retuyr.sa.abc.com'))
print('FQDN: %s' % device_2.fqdn)
print('Region is: %s' % domain2.domain(fqdn='agtrah.na.abc.com'))
I know there could be other ways to find the region here and it is not necessary to do a 'split'. But, I have got some other functions to run in child classes so need to keep it this way.
and the output here is:
FQDN: retuyr.sa.abc.com
Region is: South America
FQDN: agtrah.na.abc.com
Region is: North America
Now, I was able to do this much. But, what I want is to read a particular column from csv file, that has FQDN name and iterate over all the names in that file. The csv file has many columns in it and it is a very large file. How shall i parse those value inside this class. Please help!
EDIT:
My CSV looks like this:
Server, FQDN, IP_Address, Name, primary1, Address
abc1, retuyr.sa.abc.com, 10.10.10.1, someinfo, someaddress
abc1, agtrah.na.abc.com, 10.10.10.2, someinfo, someaddress
xyz2, somemorefqdns, 10.10.10.3, someinfo, someaddress
...
...
This is a pretty big csv file. but what I'm concerned here is, to only get the FQDN and get the desired region, based on my FOR loop conditions. My desired output will remain the same. Only difference is, I don't want to enter all these FQDN names manually. Just want them to read it from the csv file.