Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
emulab-devel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
emulab
emulab-devel
Commits
c314cad6
Commit
c314cad6
authored
11 years ago
by
Srikanth Raju
Committed by
Leigh B Stoller
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use libdb from db/ for Meta server
This way I can throw away all the manual mysql handling that I was doing
parent
719f3a61
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tmcd/Ec2MetaServer.py.in
+38
-45
38 additions, 45 deletions
tmcd/Ec2MetaServer.py.in
with
38 additions
and
45 deletions
tmcd/Ec2MetaServer.py.in
+
38
−
45
View file @
c314cad6
...
@@ -5,15 +5,25 @@ import traceback
...
@@ -5,15 +5,25 @@ import traceback
import
os
import
os
import
sys
import
sys
import
syslog
import
syslog
import
mysql.connector
# Configure variables
TBDIR
=
"
@prefix@
"
TBFACIL
=
"
@TBLOGFACIL@
"
AVAIL
=
"
@THISHOMEBASE@
"
TBPATH
=
os
.
path
.
join
(
TBDIR
,
"
lib
"
)
if
TBPATH
not
in
sys
.
path
:
sys
.
path
.
append
(
TBPATH
)
pass
from
libdb
import
*
# This requires Python 2.6+
# This requires Python 2.6+
class
Ec2MetaHandler
(
BaseHTTPRequestHandler
):
class
Ec2MetaHandler
(
BaseHTTPRequestHandler
):
def
__init__
(
self
,
req
,
ca
,
huh
):
def
__init__
(
self
,
req
,
ca
,
huh
):
self
.
cnx
=
mysql
.
connector
.
connect
(
user
=
'
tmcd
'
,
facil
=
"
LOG_
"
+
TBFACIL
.
upper
()
database
=
'
tbdb
'
,
unix_socket
=
'
/tmp/mysql.sock
'
)
facil
=
"
LOG_
"
+
"
@TBLOGFACIL@
"
.
upper
()
syslog
.
openlog
(
"
tmcd-meta
"
,
syslog
.
LOG_PID
,
getattr
(
syslog
,
facil
))
syslog
.
openlog
(
"
tmcd-meta
"
,
syslog
.
LOG_PID
,
getattr
(
syslog
,
facil
))
BaseHTTPRequestHandler
.
__init__
(
self
,
req
,
ca
,
huh
)
BaseHTTPRequestHandler
.
__init__
(
self
,
req
,
ca
,
huh
)
...
@@ -92,37 +102,32 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
...
@@ -92,37 +102,32 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
return
"
\n
"
;
return
"
\n
"
;
def
doamiid
(
self
,
arg
):
def
doamiid
(
self
,
arg
):
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select osname from os_info
"
rows
=
DBQueryWarn
(
"
select osname from os_info
"
"
join nodes on os_info.osid = nodes.osid
"
"
join nodes on os_info.osid = nodes.osid
"
"
join interfaces on nodes.node_id=interfaces.node_id
"
"
join interfaces on nodes.node_id=interfaces.node_id
"
"
where interfaces.ip=%s
"
,
(
ip
,));
"
where interfaces.ip=%s
"
,
(
ip
,));
if
cursor
.
with_rows
:
if
len
(
rows
)
>
0
:
ami_id
=
cursor
.
fetchone
()
ami_id
=
rows
[
0
]
ami_id
=
ami_id
[
0
]
ami_id
=
ami_id
[
0
]
else
:
else
:
ami_id
=
""
ami_id
=
""
cursor
.
close
()
return
ami_id
;
return
ami_id
;
def
dolocal_hostname
(
self
,
args
):
def
dolocal_hostname
(
self
,
args
):
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select vname,eid,pid from reserved join interfaces on interfaces.node_id=reserved.node_id
"
rows
=
DBQueryWarn
(
"
select vname,eid,pid from reserved join interfaces
"
"
on interfaces.node_id=reserved.node_id
"
"
where interfaces.ip=%s
"
,(
ip
,))
"
where interfaces.ip=%s
"
,(
ip
,))
if
cursor
.
with_rows
:
if
len
(
rows
)
>
0
:
node_id
=
cursor
.
fetchone
()
node_id
=
rows
[
0
]
else
:
else
:
cursor
.
close
()
return
""
return
""
cursor
.
close
()
return
node_id
[
0
]
+
"
.
"
+
node_id
[
1
]
+
"
.
"
+
node_id
[
2
]
+
"
.
"
+
"
emulab.net
"
return
node_id
[
0
]
+
"
.
"
+
node_id
[
1
]
+
"
.
"
+
node_id
[
2
]
+
"
.
"
+
"
emulab.net
"
def
doavail
(
self
,
args
):
def
doavail
(
self
,
args
):
#TODO
return
AVAIL
return
"
emulab
"
def
domacs
(
self
,
args
):
def
domacs
(
self
,
args
):
...
@@ -130,75 +135,65 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
...
@@ -130,75 +135,65 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
return
"
324AF
"
return
"
324AF
"
def
domac
(
self
,
args
):
def
domac
(
self
,
args
):
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select mac from interfaces
"
rows
=
DBQueryWarn
(
"
select mac from interfaces
"
"
where interfaces.ip=%s
"
,(
ip
,))
"
where interfaces.ip=%s
"
,(
ip
,))
if
cursor
.
with_rows
:
if
len
(
rows
)
>
0
:
mac
=
cursor
.
fetchone
()
mac
=
rows
[
0
]
else
:
else
:
cursor
.
close
()
return
""
return
""
cursor
.
close
()
split
=
[
mac
[
0
][
i
:
i
+
2
]
for
i
in
range
(
0
,
len
(
mac
[
0
]),
2
)]
split
=
[
mac
[
0
][
i
:
i
+
2
]
for
i
in
range
(
0
,
len
(
mac
[
0
]),
2
)]
return
"
:
"
.
join
(
split
)
return
"
:
"
.
join
(
split
)
def
doinstance_id
(
self
,
args
):
def
doinstance_id
(
self
,
args
):
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select uuid from interfaces
"
rows
=
DBQueryWarn
(
"
select uuid from interfaces
"
"
where interfaces.ip=%s
"
,(
ip
,))
"
where interfaces.ip=%s
"
,(
ip
,))
if
cursor
.
with_rows
:
if
len
(
rows
)
>
0
:
uuid
=
cursor
.
fetchone
()
uuid
=
rows
[
0
]
else
:
else
:
cursor
.
close
()
return
""
return
""
cursor
.
close
()
return
uuid
[
0
]
return
uuid
[
0
]
def
dopublic_keys
(
self
,
args
):
def
dopublic_keys
(
self
,
args
):
if
len
(
args
)
==
0
:
if
len
(
args
)
==
0
:
#Throw out all the users. Hope the stuff don't change between queries
#Throw out all the users. Hope the stuff don't change between queries
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select user_pubkeys.uid,user_pubkeys.idx from user_pubkeys
"
rows
=
DBQueryWarn
(
"
(
select user_pubkeys.uid,user_pubkeys.idx from user_pubkeys
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
"
join reserved on reserved.exptidx=experiments.idx
"
"
join reserved on reserved.exptidx=experiments.idx
"
"
join interfaces on reserved.node_id=interfaces.node_id
"
"
join interfaces on reserved.node_id=interfaces.node_id
"
"
where interfaces.ip=%s and user_pubkeys.uid=experiments.expt_swap_uid ORDER BY idx DESC
"
"
where interfaces.ip=%s and user_pubkeys.uid=experiments.expt_swap_uid ORDER BY idx DESC
)
"
"
UNION
"
"
UNION
"
"
select user_pubkeys.uid,user_pubkeys.idx from user_pubkeys
"
"
(
select user_pubkeys.uid,user_pubkeys.idx from user_pubkeys
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
"
join reserved on reserved.exptidx=experiments.idx
"
"
join reserved on reserved.exptidx=experiments.idx
"
"
join interfaces on reserved.node_id=interfaces.node_id
"
"
join interfaces on reserved.node_id=interfaces.node_id
"
"
where interfaces.ip=%s and user_pubkeys.uid!=experiments.expt_swap_uid;
"
"
where interfaces.ip=%s and user_pubkeys.uid!=experiments.expt_swap_uid
)
;
"
,
(
ip
,
ip
,))
,
(
ip
,
ip
,))
list
=
""
list
=
""
ctr
=
0
ctr
=
0
if
cursor
.
with_rows
:
if
len
(
rows
)
>
0
:
for
(
user
,
uid
)
in
cursor
:
for
(
user
,
uid
)
in
rows
:
list
=
list
+
str
(
ctr
)
+
"
=
"
+
str
(
user
)
+
str
(
uid
)
+
"
\n
"
list
=
list
+
str
(
ctr
)
+
"
=
"
+
str
(
user
)
+
str
(
uid
)
+
"
\n
"
ctr
=
ctr
+
1
ctr
=
ctr
+
1
else
:
else
:
cursor
.
close
()
return
""
return
""
cursor
.
close
()
return
list
return
list
elif
len
(
args
)
==
1
:
elif
len
(
args
)
==
1
:
#TODO: Verify ig idx is within limits
#TODO: Verify ig idx is within limits
return
"
openssh-key
"
return
"
openssh-key
"
elif
len
(
args
)
==
2
:
elif
len
(
args
)
==
2
:
val
=
int
(
args
[
0
])
val
=
int
(
args
[
0
])
cursor
=
self
.
cnx
.
cursor
()
ip
=
self
.
client_address
[
0
]
ip
=
self
.
client_address
[
0
]
cursor
.
execute
(
"
select * from
"
rows
=
DBQueryWarn
(
"
select * from
"
"
((select user_pubkeys.pubkey from user_pubkeys
"
"
((select user_pubkeys.pubkey from user_pubkeys
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join group_membership on group_membership.uid = user_pubkeys.uid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
"
join experiments on experiments.pid=group_membership.pid AND experiments.gid=group_membership.gid
"
...
@@ -215,13 +210,11 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
...
@@ -215,13 +210,11 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
"
as T limit
"
+
str
(
val
)
+
"
, 1;
"
,
"
as T limit
"
+
str
(
val
)
+
"
, 1;
"
,
(
ip
,
ip
,))
(
ip
,
ip
,))
if
cursor
.
with_
rows
:
if
len
(
rows
)
:
key
=
cursor
.
fetchone
()
key
=
rows
[
0
]
else
:
else
:
cursor
.
close
()
return
""
return
""
cursor
.
close
()
return
key
[
0
]
return
key
[
0
]
metas
=
{
metas
=
{
...
@@ -248,7 +241,7 @@ if __name__ == '__main__':
...
@@ -248,7 +241,7 @@ if __name__ == '__main__':
# Lifted from xmlrpc/sslxmlrpc_server.py.in
# Lifted from xmlrpc/sslxmlrpc_server.py.in
#
#
try
:
try
:
fp
=
open
(
"
@prefix@
/log/tmcd-meta.log
"
,
"
a
"
);
fp
=
open
(
TBDIR
+
"
/log/tmcd-meta.log
"
,
"
a
"
);
sys
.
stdout
=
fp
sys
.
stdout
=
fp
sys
.
stderr
=
fp
sys
.
stderr
=
fp
sys
.
stdin
.
close
();
sys
.
stdin
.
close
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment