68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
# colocrossing_api.py
|
|
from selenium import webdriver
|
|
from selenium.webdriver.support.ui import Select
|
|
|
|
# Initialize the WebDriver (make sure you have the appropriate WebDriver installed)
|
|
driver = webdriver.Chrome() # You can use other WebDriver options like Firefox, Edge, etc.
|
|
|
|
# URL for login
|
|
login_url = "https://portal.colocrossing.com/auth/login"
|
|
profile_url = "https://portal.colocrossing.com/devices2/view/profile/"
|
|
|
|
|
|
def init(username, password):
|
|
# Navigate to the login page
|
|
driver.get(login_url)
|
|
|
|
# Find the username and password input fields and submit button by 'id'
|
|
username_field = driver.find_element(by="id", value="login_username")
|
|
password_field = driver.find_element(by="id", value="login_password")
|
|
submit_button = driver.find_element(by="id", value="login_button")
|
|
|
|
# Fill in the login form
|
|
username_field.send_keys(username)
|
|
password_field.send_keys(password)
|
|
|
|
# Submit the login form
|
|
submit_button.click()
|
|
|
|
# Wait for a moment to ensure the login process completes (you may need to customize the waiting time)
|
|
driver.implicitly_wait(10) # Wait for 10 seconds (adjust as needed)
|
|
|
|
# Try Click the Acknowledge button catch the exception if it doesn't exist
|
|
# noinspection PyBroadException
|
|
try:
|
|
accept_button = driver.find_element(by="id", value="acknowledge_button")
|
|
accept_button.click()
|
|
except Exception:
|
|
return "No Acknowledge Button found"
|
|
|
|
|
|
def power_cycle(credentials, device_id):
|
|
# Navigate to the device profile page
|
|
driver.get(profile_url + str(device_id))
|
|
|
|
# Wait for a moment to ensure the page loads (you may need to customize the waiting time)
|
|
driver.implicitly_wait(10) # Wait for 10 seconds (adjust as needed)
|
|
|
|
# Tick the checkbox with class control_pdu_port_checkbox
|
|
checkbox = driver.find_element(by="class name", value="control_pdu_port_checkbox")
|
|
checkbox.click()
|
|
|
|
# Set the select with name control_action to option 1
|
|
select = driver.find_element(by="name", value="control_action")
|
|
select_option = Select(select)
|
|
select_option.select_by_value("1")
|
|
|
|
# Click the button with class control_pdu_port_button
|
|
button = driver.find_element(by="class name", value="control_pdu_port_button")
|
|
button.click()
|
|
|
|
# Click the button that contains "Confirm"
|
|
confirm_button = driver.find_element(by="xpath", value="//button//span[contains(text(), 'Confirm')]")
|
|
confirm_button.click()
|
|
|
|
# Check if "PDU ports have been turned on." is in the page body
|
|
if "PDU ports have been turned on." in driver.page_source:
|
|
return "#TO__PCOK"
|