Skip to content

Commit 5680a7d

Browse files
authored
Merge pull request #44 from ctera/copy-shares-nfs
Added a couple of tools as well as support for copying nfs shares in …
2 parents 86316ab + 217d685 commit 5680a7d

File tree

6 files changed

+109
-60
lines changed

6 files changed

+109
-60
lines changed

cli-testing.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

copynfs.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import cterasdk
2+
from filer import get_filer, get_filers
3+
from cterasdk import Edge, edge_types, edge_enum
4+
from login import global_admin_login
5+
6+
def copy_nfs_share(ga, share, dest):
7+
try:
8+
tenant = ga.users.session().user.tenant
9+
filer_dest = get_filer(ga, dest, tenant)
10+
11+
client_list = []
12+
for client in share.trustedNFSClients:
13+
if client.accessLevel == "ReadWrite":
14+
client_list.append(edge_types.NFSv3AccessControlEntry(client.address, client.netmask, edge_enum.FileAccessMode.RW))
15+
elif client.accessLevel == "ReadOnly":
16+
client_list.append(edge_types.NFSv3AccessControlEntry(client.address, client.netmask, edge_enum.FileAccessMode.RO))
17+
18+
filer_dest.shares.add(share.name, share.directory[1:], export_to_nfs=True, trusted_nfs_clients=client_list)
19+
except Exception as e:
20+
print("Failed to copy share: %s" % share.name)
21+
print(e)
22+
23+
def get_nfs_shares(ga, source):
24+
tenant = ga.users.session().user.tenant
25+
filer = get_filer(ga, source, tenant)
26+
27+
try:
28+
shares = filer.shares.get()
29+
30+
nfs_shares = []
31+
32+
for share in shares:
33+
if share.exportToNFS:
34+
nfs_shares.append(share)
35+
36+
return nfs_shares
37+
except Exception as e:
38+
print("Failed to get shares from device: %s" % source)
39+
print(e)
40+
return None
41+
42+
def copy_nfs_shares(ga, source, dest):
43+
try:
44+
tenant = ga.users.session().user.tenant
45+
filer_source = get_filer(ga, source, tenant)
46+
filer_dest = get_filer(ga, dest, tenant)
47+
48+
nfs_shares_source = get_nfs_shares(ga, source)
49+
50+
for share in nfs_shares_source:
51+
try:
52+
#get the nfs clients from the source share
53+
source_nfs_clients = filer_source.shares.get(share.name).trustedNFSClients
54+
55+
print(dir(source_nfs_clients[0]))
56+
57+
print("nfs client accessLevel: %s" % source_nfs_clients[0].accessLevel)
58+
print("nfs client address: %s" % source_nfs_clients[0].address)
59+
print("nfs client netmask: %s" % source_nfs_clients[0].netmask)
60+
61+
client_list = []
62+
for client in source_nfs_clients:
63+
if client.accessLevel == "ReadWrite":
64+
client_list.append(edge_types.NFSv3AccessControlEntry(client.address, client.netmask, edge_enum.FileAccessMode.RW))
65+
elif client.accessLevel == "ReadOnly":
66+
client_list.append(edge_types.NFSv3AccessControlEntry(client.address, client.netmask, edge_enum.FileAccessMode.RO))
67+
68+
filer_dest.shares.add(share.name, share.directory[1:], export_to_nfs=True, trusted_nfs_clients=client_list)
69+
except Exception as e:
70+
print("Failed to copy share: %s" % share.name)
71+
print(e)
72+
73+
except Exception as e:
74+
print("Failed to copy shares from device: %s to device: %s" % (source, dest))
75+
print(e)
76+
77+
78+
"""if __name__ == "__main__":
79+
ga = global_admin_login("192.168.22.197", "admin", "lap6056*", True)
80+
try:
81+
copy_nfs_shares(ga, "lakegw2", "labgw")
82+
except Exception as e:
83+
print(e)
84+
finally:
85+
ga.logout()"""

copyshares.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cterasdk
22
from filer import get_filer, get_filers
3+
from copynfs import copy_nfs_share
34
from cterasdk import Edge, edge_types, edge_enum
45
import logging
56

@@ -42,6 +43,10 @@ def copyshares(self, source, dest):
4243
if share.name == 'public' or share.name == 'cloud' or share.name == 'backups':
4344
logging.info("%s skipped" % str(share.name))
4445
continue
46+
elif share.exportToNFS:
47+
logging.info("Copying NFS share: %s" % str(share.name))
48+
copy_nfs_share(self, share, dest)
49+
continue
4550
try:
4651
acl_entries = []
4752
for acl in share.acl:

ctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def main():
4040

4141
widget = QStackedWidget()
4242

43-
widget.setWindowTitle("CTools v3.1b")
43+
widget.setWindowTitle("CTools v3.1c")
4444

4545
widget.setWindowIcon(QIcon('icon.jpeg'))
4646

populate.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ def create_shares_from_folders_list(self, folders, edge_filer):
2929
if folder.name != 'My Files':
3030
logging.info("Creating share for folder: " + folder.name)
3131

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)
32+
try:
33+
users = self.users.list_local_users(include = ['name', 'email', 'firstName', 'lastName'])
34+
match = None
35+
for user in users:
36+
if user.name == folder.owner.split('/')[-1]:
37+
match = user
38+
break
39+
40+
if match is not None:
41+
path = "cloud/users/"+ match.firstName + " " + match.lastName + "/" + folder.name
42+
edge_filer.shares.add(folder.name, path)
43+
except CTERAException as ce:
44+
logging.error(ce)
45+
logging.error("Failed creating share for folder: " + folder.name)
4246

4347

4448
except CTERAException as ce:

windows/PopulateCloudFoldersWindow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from PySide6.QtGui import (
1919
QPixmap
2020
)
21-
WINDOW_WIDTH = 600
22-
WINDOW_HEIGHT = 500
21+
WINDOW_WIDTH = 700
22+
WINDOW_HEIGHT = 600
2323
OUTPUT_HEIGHT = 250
2424
class populateCloudFoldersWindow(QMainWindow):
2525
"""PyCalc's main window (GUI or view)."""
@@ -32,7 +32,7 @@ def __init__(self, widget):
3232
self.top = QHBoxLayout()
3333
welcome = QLabel("<h2>Welcome to CTools!</h2><h5>One tool for all</h5>")
3434
pic_label = QLabel(self)
35-
pixmap = QPixmap("logo.png")
35+
pixmap = QPixmap("C:\\Users\\lakea\\Desktop\\CTERA\\ctools\\logo.png")#replace with image location
3636
pic_label.setPixmap(pixmap)
3737
#pic_label.setScaledContents(True)
3838
self.top.addWidget(welcome)
@@ -58,7 +58,7 @@ def _createToolBar(self):
5858
def _createToolViewLayout(self):
5959
toolView = QVBoxLayout()
6060
# 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"])
61+
BoilerLayout, self.input_widgets = gen_custom_tool_layout("Populate Cloud Folders as Shares (Except My Files)", ["Device Name"], ["Ignore cert warnings for login", "Verbose Logging"])
6262
toolView.addLayout(BoilerLayout)
6363
# Create action buttons
6464
actionButtonLayout = QHBoxLayout()

0 commit comments

Comments
 (0)