Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
e0c929b0
Commit
e0c929b0
authored
Oct 25, 2014
by
Leigh B Stoller
Browse files
Add background (-b) mode to allocation and deallocation. Sends email with
logfile upon error. I really need a new state; allocating.
parent
05a0e37b
Changes
2
Hide whitespace changes
Inline
Side-by-side
utils/createdataset.in
View file @
e0c929b0
...
...
@@ -41,11 +41,13 @@ sub usage()
print
STDERR
"
-o uid Owner (defaults to caller)
\n
";
print
STDERR
"
-e date Expiration date (or 'never')
\n
";
print
STDERR
"
-a attrs comma-seperated string of key=value attributes
\n
";
print
STDERR
"
-b Allocate resources in the background
\n
";
print
STDERR
"
name Name (in the form <pid>/<id>)
\n
";
exit
(
-
1
);
}
my
$optlist
=
"
dhUo:s:t:e:a:f:
";
my
$optlist
=
"
dhUo:s:t:e:a:f:
b
";
my
$debug
=
0
;
my
$background
=
0
;
my
$pid
;
my
$uid
;
my
$expire
;
...
...
@@ -73,11 +75,14 @@ sub fatal($);
# Configure variables
#
my
$TB
=
"
@prefix
@
";
my
$TBOPS
=
"
@TBOPSEMAIL
@
";
my
$TBBASE
=
"
@TBBASE
@
";
#
# Testbed Support libraries
#
use
lib
"
@prefix
@/lib
";
use
libtestbed
;
use
libdb
;
use
Quota
;
use
Lease
;
...
...
@@ -108,6 +113,9 @@ if (defined($options{h})) {
if
(
defined
(
$options
{
d
}))
{
$debug
++
;
}
if
(
defined
(
$options
{
b
}))
{
$background
++
;
}
if
(
defined
(
$options
{
U
}))
{
$approveme
=
0
;
}
...
...
@@ -117,7 +125,14 @@ if (defined($options{o})) {
if
(
defined
(
$options
{
s})) {
if ($options{s} =~ /^(\d+)$/) {
$size = $1;
}
else
{
}
elsif
(
$options
{
s} =~ /^(\d+)(\w+)$/) {
$size = Blockstore::ConvertToMebi($options{s});
if ($size < 0) {
fatal("Could not parse size.");
}
}
else
{
fatal
("
Could not parse size.
");
}
}
...
...
@@ -358,6 +373,7 @@ my $lease = Lease->Create($args, \%attrs);
if
(
!
$lease
)
{
fatal
("
Could not create dataset lease
$lname
in
$pid
.
");
}
my
$lease_idx
=
$lease
->
lease_idx
();
# No longer need to hold the quota lock
if
(
defined
(
$quota
))
{
...
...
@@ -370,12 +386,37 @@ if (defined($quota)) {
# This can take a long time so we lock it to avoid races with others.
#
if
(
$approveme
)
{
my
$logname
;
if
(
$background
)
{
print
"
Resource allocation proceeding the background ...
\n
";
$logname
=
TBMakeLogname
("
createdataset
");
if
(
my
$childpid
=
TBBackGround
(
$logname
))
{
exit
(
0
);
}
# Let parent exit;
sleep
(
2
);
}
if
(
$lease
->
Lock
()
||
$lease
->
AllocResources
("
valid
"))
{
print
STDERR
"
WARNING: could not approve new lease, contact testbed-ops.
\n
";
$approveme
=
0
;
#
# Need to notify on error, if ran in the background.
#
if
(
$background
)
{
SENDMAIL
(
$TBOPS
,
"
Lease allocation failed!
",
"
Background resource allocation for Lease '
$pid
/
$lname
'
"
.
"
failed!
\n\n
",
$TBOPS
,
undef
,
$logname
);
}
}
$lease
->
Unlock
()
if
(
$lease
->
GotLock
());
exit
(
0
)
if
(
$background
);
}
print
"
Created lease '
$pid
/
$lname
' for
"
.
$descrip
{
$dstype
};
...
...
@@ -385,7 +426,11 @@ if ($expire == 0) {
print
"
, expires on
"
.
localtime
(
$expire
)
.
"
.
\n
";
}
if
(
!
$approveme
)
{
# send message to testbed-ops to approve?
# Note that the lease daemon sends out periodic email about
# unapproved leases.
SENDMAIL
(
$TBOPS
,
"
Lease approval required
",
"
Lease '
$pid
/
$lname
' requires approval. You can view it at
\n
"
.
"
$TBBASE
/show-dataset.php?idx=
$lease_idx
\n\n
");
print
"
NOTE: lease must still be approved before it can be used
\n
";
}
...
...
utils/deletelease.in
View file @
e0c929b0
...
...
@@ -40,9 +40,11 @@ sub usage()
print
STDERR
"
lname Name of lease in <pid>/<id> form
\n
";
exit
(
-
1
);
}
my
$optlist
=
"
dhfFw:
";
my
$optlist
=
"
dhfFw:
b
";
my
$debug
=
0
;
my
$force
=
0
;
my
$background
=
0
;
my
$logname
;
my
$pid
;
my
$lname
;
my
$lease
;
...
...
@@ -55,11 +57,13 @@ sub fatal($);
# Configure variables
#
my
$TB
=
"
@prefix
@
";
my
$TBOPS
=
"
@TBOPSEMAIL
@
";
#
# Testbed Support libraries
#
use
lib
"
@prefix
@/lib
";
use
libtestbed
;
use
libdb
;
use
Lease
;
use
Project
;
...
...
@@ -89,6 +93,9 @@ if (defined($options{h})) {
if
(
defined
(
$options
{
d
}))
{
$debug
=
1
;
}
if
(
defined
(
$options
{
b
}))
{
$background
=
1
;
}
if
(
defined
(
$options
{
f
}))
{
$force
=
1
;
}
...
...
@@ -192,9 +199,29 @@ if (!$lease->ValidTransition("DEAD")) {
}
}
if
(
$background
)
{
print
"
Resource deallocation proceeding the background ...
\n
";
$logname
=
TBMakeLogname
("
deletelease
");
if
(
my
$childpid
=
TBBackGround
(
$logname
))
{
exit
(
0
);
}
# Let parent exit;
sleep
(
2
);
}
# Dealloc will put the lease back into the unapproved state
if
(
$lease
->
DeallocResources
())
{
$lease
->
UpdateState
(
LEASE_STATE_LOCKED
());
#
# Need to notify on error, if ran in the background.
#
if
(
$background
)
{
SENDMAIL
(
$TBOPS
,
"
Lease deallocation failed!
",
"
Background resource deallocation for Lease '
$pid
/
$lname
'
"
.
"
failed!
\n\n
",
$TBOPS
,
undef
,
$logname
);
}
fatal
("
$pid
/
$lname
: could not deallocate resources, left in 'locked' state.
");
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment