Skip to content

Commit 7bc38b8

Browse files
committed
Adding day2 classes exercises
1 parent a2c1bcf commit 7bc38b8

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

day2/classes_ex1.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
4+
5+
class NetDevice(object):
6+
def __init__(self, ip_addr, username, password):
7+
self.ip_addr = ip_addr
8+
self.username = username
9+
self.password = password
10+
11+
self.serial_number = ""
12+
self.vendor = ""
13+
self.model = ""
14+
self.os_version = ""
15+
self.uptime = ""
16+
17+
18+
my_obj1 = NetDevice(ip_addr="1.1.1.1", username="admin", password="pwd")
19+
my_obj2 = NetDevice(ip_addr="1.1.1.2", username="admin", password="pwd")
20+
my_obj3 = NetDevice(ip_addr="1.1.1.3", username="admin", password="pwd")
21+
my_obj4 = NetDevice(ip_addr="1.1.1.4", username="admin", password="pwd")

day2/classes_ex1.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Classes Ex1
3+
------------
4+
5+
Create a network device class. The class should have fields for
6+
ip_addr, username, password, serial_number, model, vendor, uptime
7+
and os_version.
8+
9+
Assign at least the ip_addr, username, and password field to the
10+
object using __init__.
11+
12+
Create four different network device objects using this class
13+

day2/classes_ex2.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
from __future__ import unicode_literals
4+
5+
6+
class NetDevice(object):
7+
def __init__(self, ip_addr, username, password):
8+
self.ip_addr = ip_addr
9+
self.username = username
10+
self.password = password
11+
12+
self.serial_number = ""
13+
self.vendor = ""
14+
self.model = ""
15+
self.os_version = ""
16+
self.uptime = ""
17+
18+
def print_ip(self):
19+
print("Device IP address is: {}".format(self.ip_addr))
20+
21+
def print_credentials(self):
22+
print("Device username: {}".format(self.username))
23+
print("Device password: {}".format(self.password))
24+
25+
def set_vendor(self, vendor):
26+
self.vendor = vendor
27+
print("Setting vendor to: {}".format(self.vendor))
28+
29+
30+
if __name__ == "__main__":
31+
32+
print()
33+
# Validation code
34+
my_obj1 = NetDevice(ip_addr="1.1.1.1", username="admin", password="pwd")
35+
my_obj1.print_ip()
36+
my_obj1.print_credentials()
37+
my_obj1.set_vendor("Cisco")
38+
print()

day2/classes_ex2.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Classes Ex2
3+
------------
4+
5+
Expand on the class created in exercise1.
6+
7+
1. Write a method that prints out the ip_address of the device.
8+
2. Write a method that prints out the username and password of the device.
9+
3. Write method that takes one argument (vendor) and sets the vendor field on the
10+
device.
11+

0 commit comments

Comments
 (0)