Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
slapos.package
Commits
3ff0b9e6
Commit
3ff0b9e6
authored
May 21, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use list as report queue instead of Queue.
parent
b63f7492
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
39 deletions
+67
-39
windows/netreport/src/netreport.py
windows/netreport/src/netreport.py
+56
-33
windows/netreport/src/netuse.c
windows/netreport/src/netuse.c
+3
-3
windows/netreport/src/tests.py
windows/netreport/src/tests.py
+8
-3
No files found.
windows/netreport/src/netreport.py
View file @
3ff0b9e6
...
...
@@ -40,7 +40,7 @@
#
# main process
#
# read data from
json file
# read data from
data file (pickle)
#
# check start state, there are 3 cases
#
...
...
@@ -90,7 +90,16 @@
#
# Save unsending queue, report id and state to pickle file.
#
#
# Interface of computer:
#
# reportNetDriveUsage will post a list of record:
#
# (computer_id, sequence_no, timestamp, duration,
# domain, user, usage, remark)
#
# getReportSequenceNo?computer_id=XXXX
#
import
argparse
from
datetime
import
datetime
import
logger
...
...
@@ -128,7 +137,7 @@ def parseArgumentTuple():
default
=
"net_drive_usage_report.data"
)
parser
.
add_argument
(
"--server-name"
,
help
=
"Interval in seconds to send report to master."
,
default
=
None
)
default
=
""
)
option
=
parser
.
parse_args
()
# Build option_dict
...
...
@@ -150,8 +159,10 @@ class NetDriveUsageReporter(object):
self
.
slap
=
slapos
.
slap
.
slap
()
self
.
slap_computer
=
None
self
.
report_sequence_no
=
0
self
.
_queue
=
Queue
.
queue
(
self
.
queue_size
)
self
.
_queue
=
None
self
.
_state_file
=
self
.
data_file
+
".state"
self
.
_domain_name
=
None
self
.
_domain_account
=
None
def
initializeConnection
(
self
):
connection_dict
=
{}
...
...
@@ -161,22 +172,32 @@ class NetDriveUsageReporter(object):
**
connection_dict
)
self
.
slap_computer
=
self
.
slap
.
registerComputer
(
self
.
computer_id
)
def
_getUserInfo
(
self
):
user_info
=
netuser
.
userInfo
()
self
.
_domain_name
=
user_info
[
1
]
self
.
_domain_account
=
user_info
[
0
]
def
run
(
self
):
self
.
_getUserInfo
()
self
.
initializeConnection
()
self
.
_loadReportState
()
self
.
_sendReportInQueue
()
self
.
report_state
=
REPORT_STATE_RUNNING
pickle
.
dump
(
self
.
report_state
,
self
.
_state_file
)
current_timestamp
=
datetime
.
now
()
while
True
:
last_timestamp
=
datetime
.
now
()
d
=
last_timestamp
-
current_timestamp
if
d
.
seconds
<
self
.
report_interval
:
sleep
(
self
.
report_interval
)
continue
current_timestamp
=
last_timestamp
r
=
self
.
getUsageReport
()
self
.
sendUsageReport
(
r
)
try
:
while
True
:
last_timestamp
=
datetime
.
now
()
d
=
last_timestamp
-
current_timestamp
if
d
.
seconds
<
self
.
report_interval
:
sleep
(
self
.
report_interval
)
continue
r
=
self
.
getUsageReport
(
d
.
seconds
,
current_timestamp
)
current_timestamp
=
last_timestamp
if
not
self
.
sendUsageReport
(
r
):
break
except
KeyboardInterrupt
:
pass
self
.
_saveReportState
()
self
.
report_state
=
REPORT_STATE_STOP
pickle
.
dump
(
self
.
report_state
,
self
.
_state_file
)
...
...
@@ -199,34 +220,35 @@ class NetDriveUsageReporter(object):
pass
# get sequence no from master sever
self
.
report_sequence_no
=
s
[
"sequence-no"
]
for
r
in
s
[
"queue"
]:
self
.
_queue
.
put
(
r
)
self
.
_queue
=
s
[
"queue"
]
def
_saveReportState
(
self
):
q
=
[]
try
:
while
not
self
.
_queue
.
empty
():
q
.
append
(
self
.
_queue
.
get_nowait
())
except
Queue
.
Empty
:
pass
s
=
{
"computer-id"
:
self
.
computer_id
,
"sequence-no"
:
self
.
report_sequence_no
,
"queue"
:
q
,
"queue"
:
self
.
_queue
,
}
pickle
.
dump
(
s
,
self
.
data_file
)
def
getUsageReport
(
self
):
def
getUsageReport
(
self
,
duration
,
timestamp
=
None
):
if
timestamp
is
None
:
timestamp
=
datetime
.
now
()
r
=
[
self
.
computer_id
,
self
.
report_sequence_no
,
timestamp
,
duration
,
self
.
_domain_name
,
self
.
_domain_account
,
]
self
.
report_sequence_no
+=
1
re
turn
netuse
.
usagereport
()
def
sendUsageReport
(
self
,
report
):
if
self
.
_sendReportInQueue
():
if
not
self
.
_postData
(
report
):
self
.
_queue
.
put
(
report
)
else
:
self
.
_queue
.
put
(
report
)
re
mark
=
[]
total
=
0
for
x
in
netuse
.
usageReport
(
self
.
server_name
):
total
+=
x
[
2
]
remark
.
append
(
" "
.
join
(
map
(
str
,
x
[
0
:
3
])))
r
.
append
(
total
)
r
.
append
(
"
\
n
"
.
join
(
remark
))
return
r
def
sendUsageReport
(
self
,
r
):
self
.
_queue
[
0
:
0
]
=
[
r
]
return
self
.
_sendReportInQueue
()
def
_postData
(
self
,
r
):
"""Send a marshalled dictionary of the net drive usage record
serialized via_getDict.
...
...
@@ -236,10 +258,11 @@ class NetDriveUsageReporter(object):
def
_sendReportInQueue
(
self
):
try
:
while
True
:
r
=
self
.
_queue
.
get_nowait
()
r
=
self
.
_queue
[
-
1
]
if
not
self
.
_postData
(
r
):
return
False
except
Queue
.
Empty
:
self
.
_queue
.
pop
()
except
IndexError
:
pass
return
True
...
...
windows/netreport/src/netuse.c
View file @
3ff0b9e6
...
...
@@ -264,7 +264,7 @@ static PyMethodDef NetUseMethods[] = {
netuse_user_info
,
METH_VARARGS
,
(
"user
i
nfo()
\n\n
"
"user
I
nfo()
\n\n
"
"Get the logon user information, return a tuple:
\n
"
"(user, domain, server).
\n
"
)
...
...
@@ -274,12 +274,12 @@ static PyMethodDef NetUseMethods[] = {
netuse_map_drive
,
METH_VARARGS
,
(
"map
d
rive()
\n\n
"
"map
D
rive()
\n\n
"
"Create mapped drive from server shared folder
\n
"
)
},
{
"usage
r
eport"
,
"usage
R
eport"
,
netuse_usage_report
,
METH_VARARGS
,
(
...
...
windows/netreport/src/tests.py
View file @
3ff0b9e6
...
...
@@ -23,17 +23,22 @@ class BaseTestCase(unittest.TestCase):
class
NetUsageTests
(
BaseTestCase
):
def
test_user_info
(
self
):
u
=
netuse
.
user
i
nfo
()
u
=
netuse
.
user
I
nfo
()
self
.
assertEquals
(
len
(
u
),
3
)
self
.
assertEquals
(
u
,
[])
def
test_usage_report
(
self
):
r
=
netuse
.
usage
r
eport
()
r
=
netuse
.
usage
R
eport
()
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_server
(
self
):
r
=
netuse
.
usagereport
(
'myserver'
)
r
=
netuse
.
usageReport
(
'myserver'
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_server_is_none
(
self
):
r
=
netuse
.
usageReport
(
None
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
...
...
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