General update on Carling tools, device creation on IoT Hub and I-Sight Configuration Tool
This commit is contained in:
@@ -4,16 +4,33 @@ from cube_activate_ssh import activate_ssh
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
load_dotenv(override=True)
|
||||
def resource_path(relative_path):
|
||||
""" Get absolute path to resource, works for dev and for PyInstaller """
|
||||
try:
|
||||
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
||||
base_path = sys._MEIPASS
|
||||
except Exception:
|
||||
base_path = os.path.abspath(".")
|
||||
|
||||
ip_address_prefix = "10.162.48."
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
dotenv_path = resource_path('.env')
|
||||
load_dotenv(dotenv_path=dotenv_path)
|
||||
|
||||
ip_address_prefix = "10.188.10."
|
||||
ssh_command = "hostname"
|
||||
|
||||
csv_filename = "lacabana01.csv"
|
||||
csv_filename = "HOOHANA_01.csv"
|
||||
|
||||
ssh_username = os.getenv("DEFAULT_CUBE_LINUX_ADMIN_USER")
|
||||
ssh_password = os.getenv("DEFAULT_CUBE_LINUX_ADMIN_PASSWORD")
|
||||
ENV_SSH = {
|
||||
"DEFAULT_CUBE_LINUX_ADMIN_USER": os.getenv("DEFAULT_CUBE_LINUX_ADMIN_USER"),
|
||||
"DEFAULT_CUBE_LINUX_ADMIN_PASSWORD": os.getenv("DEFAULT_CUBE_LINUX_ADMIN_PASSWORD")
|
||||
}
|
||||
|
||||
ssh_username = ENV_SSH["DEFAULT_CUBE_LINUX_ADMIN_USER"]
|
||||
ssh_password = ENV_SSH["DEFAULT_CUBE_LINUX_ADMIN_PASSWORD"]
|
||||
|
||||
def execute_ssh_command(ip, command):
|
||||
client = paramiko.SSHClient()
|
||||
@@ -68,6 +85,7 @@ def restart_cloudagent(ip):
|
||||
def main():
|
||||
|
||||
print("Starting...")
|
||||
#print(f"{ssh_username} {ssh_password}")
|
||||
|
||||
with open(csv_filename, mode="w", newline="") as file:
|
||||
writer = csv.writer(file)
|
||||
@@ -125,55 +143,6 @@ def main():
|
||||
migration = "NONE"
|
||||
status = "INCORRECT"
|
||||
|
||||
# if migration == "SAFT" or migration == "NONE":
|
||||
# print("SAFT device, migrating to INOX...")
|
||||
|
||||
# print("Creating device on INOX...")
|
||||
# try:
|
||||
# registry_manager.create_device_with_sas(
|
||||
# cube_id,
|
||||
# primary_key="", secondary_key="",
|
||||
# status="enabled",
|
||||
# iot_edge=False
|
||||
# )
|
||||
# except Exception as iot_e:
|
||||
# print("Error creating new device!")
|
||||
# print(iot_e)
|
||||
# continue
|
||||
|
||||
# print("Adding tags to new device...")
|
||||
# try:
|
||||
# twin = registry_manager.get_twin(cube_id)
|
||||
# twin_patch = Twin(properties=TwinProperties(desired={}), tags={
|
||||
# "site": SITE_NAME,
|
||||
# "number": i
|
||||
# })
|
||||
# registry_manager.update_twin(cube_id, twin_patch, twin.etag)
|
||||
# except Exception as iot_e:
|
||||
# print("Error assigning tags to new device!")
|
||||
# print(iot_e)
|
||||
|
||||
# print("Requesting primary key...")
|
||||
# try:
|
||||
# device_info = registry_manager.get_device(cube_id)
|
||||
# primary_key = device_info.authentication.symmetric_key.primary_key
|
||||
# new_connection_string = f"HostName\\={CONNECTION_STRING.split(';')[0].split('=')[1]};DeviceId\\={cube_id};SharedAccessKey\\={primary_key}"
|
||||
# new_content = f'light-telemetry=false\ncompression-enabled=true\ntelemetry-on=true\nremote-update-on=true\nconnection-string={new_connection_string}'
|
||||
# except Exception as iot_e:
|
||||
# print("Error getting new Connection String!")
|
||||
# print(iot_e)
|
||||
# continue
|
||||
# print("Setting new Connection String...")
|
||||
# try:
|
||||
# update_cloud_config(ip_address, new_content)
|
||||
# except Exception as ssh_e:
|
||||
# print("Error when setting the new Connection String!")
|
||||
# print(ssh_e)
|
||||
# continue
|
||||
# print("Done!")
|
||||
|
||||
restart_cloudagent(ip_address)
|
||||
|
||||
writer.writerow([i, ip_address, cube_id, migration, status])
|
||||
file.flush()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user