Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5132c367
authored
Jul 29, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix mount_store()
parent
724d775a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
18 deletions
+27
-18
agent.py
+27
-18
No files found.
agent.py
View file @
5132c367
...
...
@@ -12,7 +12,7 @@ import fileinput
import
platform
import
sys
import
tarfile
from
os.path
import
expanduser
,
join
from
os.path
import
expanduser
,
join
,
exists
from
os
import
mkdir
from
glob
import
glob
from
StringIO
import
StringIO
...
...
@@ -30,10 +30,17 @@ logger = logging.getLogger()
SSH_DIR
=
expanduser
(
'~cloud/.ssh'
)
AUTHORIZED_KEYS
=
join
(
SSH_DIR
,
'authorized_keys'
)
fstab_template
=
(
'sshfs#
%(username)
s@
%(host)
s:home /home/cloud/sshfs '
'fuse defaults,idmap=user,reconnect,_netdev,uid=1000,'
'gid=1000,allow_other,StrictHostKeyChecking=no,'
'IdentityFile=/home/cloud/.ssh/id_rsa 0 0
\n
'
)
STORE_DIR
=
'/store'
mount_template_linux
=
(
'//
%(host)
s/u-1
%(dir)
s cifs username=
%(username)
s'
',password=
%(password)
s,iocharset=utf8,uid=cloud 0 0
\n
'
)
mount_template_windows
=
(
'net use * /delete /yes
\r\n
'
'timeout 5
\r\n
'
'net use z:
\\
%(host)
s
\\
%(username)
s "
%(password)
s" '
'/user:
%(username)
s
\r\n
'
)
system
=
platform
.
system
()
...
...
@@ -141,24 +148,26 @@ class Context(object):
wmi
.
WMI
()
.
Win32_ComputerSystem
()[
0
]
.
Rename
(
hostname
)
@staticmethod
def
mount_store
(
host
,
username
,
password
,
key
):
def
mount_store
(
host
,
username
,
password
):
data
=
{
'host'
:
host
,
'username'
:
username
,
'password'
:
password
}
if
system
==
'Linux'
:
for
line
in
fileinput
.
input
(
'/etc/fstab'
,
inplace
=
1
):
if
line
.
startswith
(
'sshfs#'
):
line
=
''
data
[
'dir'
]
=
STORE_DIR
if
not
exists
(
STORE_DIR
):
mkdir
(
STORE_DIR
)
# TODO
for
line
in
fileinput
.
input
(
'/etc/fstab'
,
inplace
=
True
):
if
not
(
line
.
startswith
(
'//'
)
and
' cifs '
in
line
):
print
line
.
rstrip
()
with
open
(
'/etc/fstab'
,
'a'
)
as
f
:
f
.
write
(
fstab_template
%
{
'host'
:
host
,
'username'
:
username
,
'password'
:
password
})
f
.
write
(
mount_template_linux
%
data
)
subprocess
.
call
(
'mount -a'
,
shell
=
True
)
elif
system
==
'Windows'
:
data
=
(
'net use * /delete /yes
\r\n
'
'timeout 5
\r\n
'
'net use z:
\\
%(hostname)
s
\\
%(username)
s "
%(password)
s" '
'/user:
%(username)
s'
)
with
open
(
r'c:\Windows\System32\Repl\Import\Scripts'
r'
%
s.bat'
%
username
,
'w'
)
as
f
:
f
.
write
(
data
)
with
open
(
r'c:\Windows\System32\Repl\Import\Scripts\%s.bat'
%
username
,
'w'
)
as
f
:
f
.
write
(
mount_template_windows
%
data
)
@staticmethod
def
get_keys
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment