Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77462235
deactivate_device.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 14, 15:23
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Aug 16, 15:23 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19871749
Attached To
rPHINFRA c4science
deactivate_device.py
View Options
#!/usr/bin/env python3
from
phabricator
import
Phabricator
import
sys
phab
=
Phabricator
(
host
=
'https://c4science.ch/api/'
)
phab
.
update_interfaces
()
# Disable write on device
def
deactivate_write
(
action
,
binding
):
if
action
==
'off'
:
transactions
=
[
{
'type'
:
'property.set'
,
'value'
:
{
'writable'
:
False
}},
{
'type'
:
'disabled'
,
'value'
:
True
},
]
else
:
transactions
=
[
{
'type'
:
'property.set'
,
'value'
:
{
'writable'
:
True
}},
{
'type'
:
'disabled'
,
'value'
:
False
},
]
print
(
phab
.
almanac
.
binding
.
edit
(
objectIdentifier
=
binding
,
transactions
=
transactions
,
))
# Get bindinds list
def
get_bindings
(
devices
):
device
=
phab
.
almanac
.
device
.
search
(
constraints
=
{
'names'
:
devices
,
}
)
if
len
(
device
.
data
)
==
0
:
print
(
'No device found'
)
sys
.
exit
(
1
)
devices_phid
=
[
a
[
'phid'
]
for
a
in
device
.
data
]
service
=
phab
.
almanac
.
service
.
search
(
constraints
=
{
'names'
:
[
'repo-cluster'
,
'repo-single'
],
}
)
services_phid
=
[
a
[
'phid'
]
for
a
in
service
.
data
]
bindings
=
phab
.
almanac
.
binding
.
search
(
constraints
=
{
'servicePHIDs'
:
services_phid
,
'devicePHIDs'
:
devices_phid
,
},
)
if
len
(
bindings
.
data
)
==
0
:
print
(
'No binding found'
)
sys
.
exit
(
1
)
return
[
a
[
'phid'
]
for
a
in
bindings
.
data
]
# MAIN
if
len
(
sys
.
argv
)
<
2
:
print
(
'USAGE: {cmd} [on|off] [device]...
\n
example: {cmd} off c4science-phd00 c4science-phd01'
.
format
(
cmd
=
sys
.
argv
[
0
]))
sys
.
exit
(
1
)
action
=
sys
.
argv
[
1
]
devices
=
sys
.
argv
[
2
:]
bindings
=
get_bindings
(
devices
)
for
binding
in
bindings
:
deactivate_write
(
action
,
binding
)
Event Timeline
Log In to Comment