Skip to content

Commit 86316ab

Browse files
committed
Populate Shares
1 parent bf89f4c commit 86316ab

File tree

6 files changed

+177
-4
lines changed

6 files changed

+177
-4
lines changed

ctools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from windows.ImportSharesWindow import importSharesWindow
2020
from windows.AddMembersWindow import addMembersWindow
2121
from windows.ReportZonesWindow import reportZonesWindow
22+
from windows.PopulateCloudFoldersWindow import populateCloudFoldersWindow
2223
#from windows.SMBAuditWindow import smbAuditWindow
2324

2425
from PySide6 import QtCore
@@ -39,7 +40,7 @@ def main():
3940

4041
widget = QStackedWidget()
4142

42-
widget.setWindowTitle("CTools v3.1a")
43+
widget.setWindowTitle("CTools v3.1b")
4344

4445
widget.setWindowIcon(QIcon('icon.jpeg'))
4546

@@ -83,6 +84,9 @@ def main():
8384
report_zones = reportZonesWindow(widget)
8485
widget.addWidget(report_zones)
8586

87+
populate_shares = populateCloudFoldersWindow(widget)
88+
widget.addWidget(populate_shares)
89+
8690
## STEP7- Add new windows above this line ##
8791

8892
widget.setCurrentWidget(run_cmd)

populate.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from cterasdk import *
2+
from cterasdk import settings
3+
from filer import get_filer, get_filers
4+
5+
import urllib3
6+
urllib3.disable_warnings()
7+
8+
import logging
9+
10+
from login import global_admin_login
11+
12+
def get_cloud_folders(self):
13+
"""Get all cloud folders on a tenant."""
14+
try:
15+
result = self.cloudfs.drives.all()
16+
logging.info("Finished get_cloud_folders task.")
17+
18+
return result
19+
except CTERAException as ce:
20+
logging.error(ce)
21+
logging.error("Failed get_cloud_folders task.")
22+
23+
return None
24+
25+
def create_shares_from_folders_list(self, folders, edge_filer):
26+
"""Create shares from a list of cloud folders."""
27+
try:
28+
for folder in folders:
29+
if folder.name != 'My Files':
30+
logging.info("Creating share for folder: " + folder.name)
31+
32+
users = self.users.list_local_users(include = ['name', 'email', 'firstName', 'lastName'])
33+
match = None
34+
for user in users:
35+
if user.name == folder.owner.split('/')[-1]:
36+
match = user
37+
break
38+
39+
if match is not None:
40+
path = "cloud/users/"+ match.firstName + " " + match.lastName + "/" + folder.name
41+
edge_filer.shares.add(folder.name, path)
42+
43+
44+
except CTERAException as ce:
45+
logging.error(ce)
46+
logging.error("Failed create_shares_from_folders_list task.")
47+
48+
def run_populate(address, username, password, device_name):
49+
try:
50+
settings.sessions.management.ssl = False
51+
global_admin = global_admin_login(address, username, password, True)
52+
folders = get_cloud_folders(global_admin)
53+
54+
filer = get_filer(global_admin, device_name)
55+
56+
create_shares_from_folders_list(global_admin, folders, filer)
57+
except CTERAException as ce:
58+
logging.error(ce)
59+
logging.error("Failed creating share task.")
60+
finally:
61+
global_admin.logout()
62+
63+
64+
"""if __name__ == "__main__":
65+
run_populate("192.168.22.197", "admin", "lap6056*", "labgw")"""

share_add.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from populate import run_populate
2+
3+
if __name__ == "__main__":
4+
run_populate("192.168.22.197", "admin", "lap6056*", "labgw")

ui_help.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ def create_tool_bar(widget, currentWindow):
2929
delete_shares = QPushButton("Delete Shares")
3030
import_shares = QPushButton("Copy Shares")
3131
add_members = QPushButton("Add/Remove Members")
32-
zones_report = QPushButton("Zones Report")
32+
report_zones = QPushButton("Report Zones")
33+
populate_shares = QPushButton("Populate Shares")
3334

3435
#STEP8 - Create the push button above so you can navigate to the tool
3536

3637

3738
# STEP9 - Add the button you just created to the list below. MAKE SURE YOU PUT IT BEFORE EXIT
38-
tool_list = [run_cmd, show_status, suspend_sync, unsuspend_sync, enable_ssh, disable_ssh, enable_telnet, reset_password, cloud_folders, delete_shares, import_shares, add_members, zones_report]
39+
tool_list = [run_cmd, show_status, suspend_sync, unsuspend_sync, enable_ssh, disable_ssh, enable_telnet, reset_password, cloud_folders, delete_shares, import_shares, add_members, report_zones, populate_shares]
3940

40-
tool_list[currentWindow].setStyleSheet("color: darkblue; background-color: lightblue; ")
41+
tool_list[currentWindow].setStyleSheet("color: darkblue; background-color: lightblue;")
4142

4243
tools.addWidget(label, alignment=Qt.AlignTop)
4344

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import logging
2+
from log_setter import set_logging
3+
## STEP6a - import the tool function from the file you imported into the CTOOLS3 project folder
4+
from populate import run_populate
5+
from ui_help import gen_tool_layout, gen_custom_tool_layout, create_tool_bar
6+
from login import global_admin_login
7+
from PySide6.QtCore import Qt
8+
from PySide6.QtWidgets import (
9+
QMainWindow,
10+
QWidget,
11+
QPushButton,
12+
QVBoxLayout,
13+
QLabel,
14+
QHBoxLayout,
15+
QTextEdit,
16+
QFrame,
17+
)
18+
from PySide6.QtGui import (
19+
QPixmap
20+
)
21+
WINDOW_WIDTH = 600
22+
WINDOW_HEIGHT = 500
23+
OUTPUT_HEIGHT = 250
24+
class populateCloudFoldersWindow(QMainWindow):
25+
"""PyCalc's main window (GUI or view)."""
26+
def __init__(self, widget):
27+
super().__init__()
28+
self.widget = widget
29+
self.setWindowTitle("CTools 3.0")
30+
self.setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT)
31+
self.generalLayout = QVBoxLayout()
32+
self.top = QHBoxLayout()
33+
welcome = QLabel("<h2>Welcome to CTools!</h2><h5>One tool for all</h5>")
34+
pic_label = QLabel(self)
35+
pixmap = QPixmap("logo.png")
36+
pic_label.setPixmap(pixmap)
37+
#pic_label.setScaledContents(True)
38+
self.top.addWidget(welcome)
39+
self.top.addStretch()
40+
self.top.addWidget(pic_label)
41+
self.mainContent = QHBoxLayout()
42+
centralWidget = QWidget(self)
43+
centralWidget.setLayout(self.generalLayout)
44+
self.setCentralWidget(centralWidget)
45+
self.generalLayout.addLayout(self.top)
46+
self.generalLayout.addLayout(self.mainContent)
47+
self._createToolBar()
48+
self._createToolViewLayout()
49+
def _createToolBar(self):
50+
tools = create_tool_bar(self.widget, 13)
51+
# Add line separator between Tool List and Tool View
52+
line = QFrame()
53+
line.setFrameShape(QFrame.VLine)
54+
line.setFrameShadow(QFrame.Sunken)
55+
line.setLineWidth(1)
56+
self.mainContent.addLayout(tools)
57+
self.mainContent.addWidget(line)
58+
def _createToolViewLayout(self):
59+
toolView = QVBoxLayout()
60+
# Step3 - You will change the next two lines according to the KB
61+
BoilerLayout, self.input_widgets = gen_custom_tool_layout("Populate Cloud Folders", ["Device Name"], ["Ignore cert warnings for login", "Verbose Logging"])
62+
toolView.addLayout(BoilerLayout)
63+
# Create action buttons
64+
actionButtonLayout = QHBoxLayout()
65+
self.cancel = QPushButton("Cancel")
66+
self.start = QPushButton("Start")
67+
actionButtonLayout.addWidget(self.cancel)
68+
actionButtonLayout.addWidget(self.start)
69+
toolView.addLayout(actionButtonLayout)
70+
# STEP5 - Add button listeners
71+
self.start.clicked.connect(self.tool)
72+
# Create Output box
73+
self.output = QTextEdit()
74+
self.output.setReadOnly(True)
75+
toolView.addWidget(self.output)
76+
self.mainContent.addLayout(toolView)
77+
# STEP4 - Grab the arguments for you tool
78+
def tool(self):
79+
portal_address = self.input_widgets[0].text()
80+
portal_username = self.input_widgets[1].text()
81+
portal_password = self.input_widgets[2].text()
82+
device_name = self.input_widgets[3].text()
83+
ignore_cert = self.input_widgets[4].isChecked()
84+
verbose = self.input_widgets[5].isChecked()
85+
if verbose:
86+
set_logging(logging.DEBUG, 'debug-log.txt')
87+
else:
88+
set_logging()
89+
## Step6b - Run the tool here
90+
# Ex: run_status(global_admin, filename, all_tenants_flag)
91+
run_populate(portal_address, portal_username, portal_password, device_name)
92+
self._updateOutput()
93+
def _updateOutput(self):
94+
file = open("output.tmp", 'r')
95+
with file:
96+
text = file.read()
97+
self.output.setText(text)
98+
self.output.verticalScrollBar().setValue(self.output.verticalScrollBar().maximum())

windows/ReportZonesWindow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _createToolViewLayout(self):
7979

8080
password = QLabel("Portal Admin Password:")
8181
self.password_field = QLineEdit()
82+
self.password_field.setEchoMode(QLineEdit.Password)
8283

8384
output_dir = QLabel("Output Location:")
8485
self.output_field = QHBoxLayout()

0 commit comments

Comments
 (0)