Skip to content

Commit

Permalink
Modfies object to be Device
Browse files Browse the repository at this point in the history
- modifies object initialization to be Device instead
of PYAOSCX Factory
 master
  • Loading branch information
tchiapuziowong committed Sep 28, 2021
1 parent 781043f commit ac49ede
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 76 deletions.
10 changes: 5 additions & 5 deletions library/aoscx_acl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -139,21 +139,21 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

for interface_name in acl_interface_list:
if state == 'delete':
# Create ACL Object
interface = pyaoscx_factory.interface(interface_name)
interface = device.interface(interface_name)
# Delete it
interface.clear_acl(acl_type)
# Changed
result['changed'] = True

if state == 'create' or state == 'update':
# Create ACL Object
interface = pyaoscx_factory.interface(interface_name)
interface = device.interface(interface_name)
# Verify if interface was create
if interface.was_modified():
# Changed
Expand Down
10 changes: 5 additions & 5 deletions library/aoscx_acl_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -138,13 +138,13 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

for vlan_name in acl_vlan_list:
if state == 'delete':
# Create VLAN Object
vlan = pyaoscx_factory.vlan(vlan_name)
vlan = device.vlan(vlan_name)
# Delete acl
if acl_direction == 'in':
vlan.detach_acl_in(acl_name, acl_type)
Expand All @@ -155,7 +155,7 @@ def main():

if state == 'create' or state == 'update':
# Create VLAN Object
vlan = pyaoscx_factory.vlan(vlan_name)
vlan = device.vlan(vlan_name)
# Verify if interface was create
if vlan.was_modified():
# Changed
Expand Down
8 changes: 4 additions & 4 deletions library/aoscx_backup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -157,11 +157,11 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

# Create a Configuration Object
config = pyaoscx_factory.configuration()
config = device.configuration()
success = config.backup_configuration(
config_name=config_name,
output_file=config_file,
Expand Down
8 changes: 3 additions & 5 deletions library/aoscx_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -114,10 +114,8 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create Device Object
device = pyaoscx_factory.device()
# Create a Device Object
device = Device(s)

if state == 'delete':
# Delete it
Expand Down
8 changes: 3 additions & 5 deletions library/aoscx_boot_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -93,11 +93,9 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)

# Create a Device Object
device = pyaoscx_factory.device()
device = Device(s)

success = device.boot_firmware(partition_name)

# Changed
Expand Down
8 changes: 4 additions & 4 deletions library/aoscx_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -108,11 +108,11 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

# Create a Configuration Object
config = pyaoscx_factory.configuration()
config = device.configuration()
success = config.create_checkpoint(source_config, destination_config)

# Changed
Expand Down
11 changes: 6 additions & 5 deletions library/aoscx_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


from __future__ import (absolute_import, division, print_function)

__metaclass__ = type


Expand Down Expand Up @@ -146,7 +147,7 @@ def main():
try:
from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -187,16 +188,16 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

if state == 'delete':
# Modifed Variables
modified_op = False
modified_op2 = False

# Create DNS object
dns = pyaoscx_factory.dns(vrf=vrf_name)
dns = device.dns(vrf=vrf_name)

# Delete MGMT nameservers
if mgmt_nameservers is not None:
Expand All @@ -222,7 +223,7 @@ def main():
modified_op2 = False

# Create DNS object
dns = pyaoscx_factory.dns(
dns = device.dns(
vrf=vrf_name,
domain_name=dns_domain_name,
domain_list=dns_domain_list,
Expand Down
12 changes: 6 additions & 6 deletions library/aoscx_l3_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def main():
try:
from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -193,12 +193,12 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

if state == 'delete':
# Create Interface Object
interface = pyaoscx_factory.interface(interface_name)
interface = device.interface(interface_name)
# Delete it
interface.delete()

Expand All @@ -207,7 +207,7 @@ def main():

if state == 'create' or state == 'update':
# Create Interface Object
interface = pyaoscx_factory.interface(interface_name)
interface = device.interface(interface_name)
# Verify if interface was create
if interface.was_modified():
# Changed
Expand All @@ -233,7 +233,7 @@ def main():

if ip_helper_addresses is not None:
# Create DHCP_Relay object
dhcp_relay = pyaoscx_factory.dhcp_relay(
dhcp_relay = device.dhcp_relay(
vrf=vrf, port=interface_name)
# Add helper addresses
dhcp_relay.add_ipv4_addresses(ip_helper_addresses)
Expand Down
10 changes: 5 additions & 5 deletions library/aoscx_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def main():
try:
from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -189,12 +189,12 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

if state == 'delete':
# Create Static Route Object
static_route = pyaoscx_factory.static_route(
static_route = device.static_route(
vrf_name, prefix)
# Delete it
static_route.delete()
Expand All @@ -203,7 +203,7 @@ def main():

if state == 'create' or state == 'update':
# Create Static Route object
static_route = pyaoscx_factory.static_route(
static_route = device.static_route(
vrf_name,
prefix
)
Expand Down
11 changes: 5 additions & 6 deletions library/aoscx_upload_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
required: false
config_file:
description: "File name and path for locally uploading configuration,
will be converted to JSON,
only JSON version of configuration can be uploaded"
type: str
required: false
Expand Down Expand Up @@ -99,7 +98,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -139,11 +138,11 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

# Create an instance of the Configuration class from PyaoscxFactory
config = pyaoscx_factory.configuration() # Contains action methods
# Create an instance of the Configuration class from Device
config = device.configuration() # Contains action methods

# Upload configuration file/json to switch
success = config.upload_switch_config(
Expand Down
8 changes: 3 additions & 5 deletions library/aoscx_upload_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -123,11 +123,9 @@ def main():
session_info['url'],
session_info['credentials'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)

# Create a Device Object
device = pyaoscx_factory.device()
device = Device(s)

success = device.upload_firmware(
partition_name=partition_name,
firmware_file_path=firmware_file_path,
Expand Down
10 changes: 5 additions & 5 deletions library/aoscx_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main():

from ansible.module_utils.aoscx_pyaoscx import Session
from pyaoscx.session import Session as Pyaoscx_Session
from pyaoscx.pyaoscx_factory import PyaoscxFactory
from pyaoscx.device import Device

USE_PYAOSCX_SDK = True

Expand Down Expand Up @@ -132,12 +132,12 @@ def main():
s = Pyaoscx_Session.from_session(
session_info['s'], session_info['url'])

# Create a Pyaoscx Factory Object
pyaoscx_factory = PyaoscxFactory(s)
# Create a Device Object
device = Device(s)

if state == 'delete':
# Create Vlan Object
vlan = pyaoscx_factory.vlan(vlan_id)
vlan = device.vlan(vlan_id)
# Delete it
vlan.delete()
# Changed
Expand All @@ -146,7 +146,7 @@ def main():
elif state == 'update' or state == 'create':
# Create Vlan with incoming attributes, in case VLAN does not exist
# inside device
vlan = pyaoscx_factory.vlan(
vlan = device.vlan(
vlan_id, vlan_name, description, "static", admin_state)

if vlan.was_modified():
Expand Down
Loading

0 comments on commit ac49ede

Please sign in to comment.