-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding load_devices.py for blog article
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from net_system.models import NetworkSwitch, InventoryGroup | ||
from net_system.models import Credentials | ||
from getpass import getpass | ||
|
||
import django | ||
|
||
def main(): | ||
django.setup() | ||
|
||
management_ip = raw_input("Please enter IP address: ") | ||
my_switches = (('pynet-sw1', 8222, '10.220.88.28'), | ||
('pynet-sw2', 8322, '10.220.88.29'), | ||
('pynet-sw3', 8422, '10.220.88.30'), | ||
('pynet-sw4', 8522, '10.220.88.31')) | ||
|
||
passwd = getpass() | ||
|
||
# Create Arista inventory group | ||
arista_group = InventoryGroup.objects.get_or_create(group_name='arista') | ||
print arista_group | ||
|
||
# Create four switch objects | ||
for switch_name, ssh_port, ip_addr in my_switches: | ||
switch_obj = NetworkSwitch.objects.get_or_create( | ||
device_name=switch_name, | ||
device_type='arista_eos', | ||
ip_address=ip_addr, | ||
management_ip=management_ip, | ||
port=ssh_port, | ||
group_name=arista_group[0] | ||
) | ||
print switch_obj | ||
|
||
# Create credential object | ||
arista_creds = Credentials.objects.get_or_create( | ||
username='admin1', | ||
password=passwd, | ||
description='Arista credentials' | ||
) | ||
print arista_creds | ||
|
||
# Bind switches to credentials | ||
net_devices = NetworkSwitch.objects.all() | ||
print net_devices | ||
for my_switch in net_devices: | ||
my_switch.credentials = arista_creds[0] | ||
my_switch.save() | ||
|
||
if __name__ == "__main__": | ||
main() |