Skip to content

Commit 75cceba

Browse files
author
ibmcb
authored
Merge pull request #117 from hinesmr/master
DigitalOcean block storage volume support
2 parents 2ea6dfb + 2f0a1a5 commit 75cceba

File tree

7 files changed

+119
-19
lines changed

7 files changed

+119
-19
lines changed

lib/auxiliary/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def is_failed_vm(self, attrs, metrics = None) :
118118
elif "cloud_ip" in attrs and attrs["cloud_ip"] == "undefined" :
119119
return False
120120
elif metrics is not None and "last_known_state" in metrics :
121-
if metrics["last_known_state"].count("with ip assigned") == 0 :
121+
if metrics["last_known_state"].count("with ip assigned") == 0 and metrics["last_known_state"].count("generic post-boot script executed") == 0:
122122
return True
123123
else :
124124
return False
@@ -543,7 +543,7 @@ def build_and_send_header(self):
543543
if not gfilter.count(dest + "-") :
544544
continue
545545
output += "[<a href='" + self.prefix() + "/monitor?remove=" + gfilter + "' target='_top'>X</a>] " + \
546-
gfilter.split("-")[1].replace("_", " ") + "&nbsp;"
546+
gfilter.split("-", 1)[1].replace("_", " ") + "&nbsp;"
547547

548548
output += """
549549
</div>

lib/clouds/do_cloud_ops.py

Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ def vmccleanup(self, obj_attr_list) :
183183
_msg += " were terminated"
184184
cbdebug(_msg)
185185

186+
_running_volumes = True
187+
while _running_volumes :
188+
_running_volumes = False
189+
for credential_pair in obj_attr_list["credentials"].split(","):
190+
credentials = credential_pair.split(":")
191+
tenant = credentials[0]
192+
193+
_volumes = catalogs.digitalocean[credential_pair].list_volumes()
194+
for _volume in _volumes :
195+
if _volume.name.count("cb-" + obj_attr_list["username"]) :
196+
try :
197+
cbdebug("Destroying: " + _volume.name + " (" + tenant + ")", True)
198+
_volume.destroy()
199+
except :
200+
pass
201+
_running_volumes = True
202+
else :
203+
_msg = "Cleaning up DigitalOcean. Ignoring volume: " + _volume.name
204+
cbdebug(_msg)
205+
206+
if _running_volumes :
207+
sleep(int(obj_attr_list["update_frequency"]))
208+
209+
_msg = "All volumes on DigitalOcean " + obj_attr_list["name"]
210+
_msg += " were destroyed"
211+
cbdebug(_msg)
212+
186213
_status = 0
187214

188215
except CldOpsException, obj :
@@ -411,15 +438,13 @@ def is_vm_ready(self, obj_attr_list) :
411438

412439
@trace
413440
def vmcreate(self, obj_attr_list) :
414-
'''
415-
TBD
416-
'''
417-
try :
418-
_status = 100
419-
_fmsg = "An error has occurred when creating new Droplet, but no error message was captured"
441+
_status = 100
442+
_fmsg = "An error has occurred when creating new Droplet, but no error message was captured"
443+
obj_attr_list["cloud_vm_uuid"] = "NA"
444+
_instance = False
445+
volume = False
420446

421-
obj_attr_list["cloud_vm_uuid"] = "NA"
422-
_instance = False
447+
try :
423448

424449
obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"]
425450
obj_attr_list["cloud_vm_name"] += '-' + "vm" + obj_attr_list["name"].split("_")[1]
@@ -529,14 +554,72 @@ def vmcreate(self, obj_attr_list) :
529554
del obj_attr_list["instance_obj"]
530555

531556
_status = 0
532-
533557
else :
534558
obj_attr_list["last_known_state"] = "vm creation failed"
535559
_fmsg = "Failed to obtain instance's (cloud-assigned) uuid. The "
536560
_fmsg += "instance creation failed for some unknown reason."
537561
cberr(_fmsg)
538562
_status = 100
539563

564+
565+
if "cloud_vv" in obj_attr_list :
566+
_status = 101
567+
568+
obj_attr_list["last_known_state"] = "about to send volume create request"
569+
570+
obj_attr_list["cloud_vv_name"] = "cb-" + obj_attr_list["username"]
571+
obj_attr_list["cloud_vv_name"] += '-' + "vv"
572+
obj_attr_list["cloud_vv_name"] += obj_attr_list["name"].split("_")[1]
573+
obj_attr_list["cloud_vv_name"] += '-' + obj_attr_list["role"]
574+
if obj_attr_list["ai"] != "none" :
575+
obj_attr_list["cloud_vv_name"] += '-' + obj_attr_list["ai_name"]
576+
577+
obj_attr_list["cloud_vv_name"] = obj_attr_list["cloud_vv_name"].replace("_", "-")
578+
579+
_msg = "Creating a volume, with size "
580+
_msg += obj_attr_list["cloud_vv"] + " GB, on VMC \""
581+
_msg += obj_attr_list["vmc_name"] + "\" with name " + obj_attr_list["cloud_vv_name"] + "..."
582+
cbdebug(_msg, True)
583+
584+
_mark1 = int(time())
585+
586+
volume = catalogs.digitalocean[credential_pair].create_volume(int(obj_attr_list["cloud_vv"]),
587+
obj_attr_list["cloud_vv_name"],
588+
location = [x for x in self.locations if x.id == obj_attr_list["vmc_name"]][0])
589+
590+
sleep(int(obj_attr_list["update_frequency"]))
591+
592+
obj_attr_list["cloud_vv_uuid"] = volume.id
593+
594+
_mark2 = int(time())
595+
obj_attr_list["do_015_create_volume_time"] = _mark2 - _mark1
596+
597+
if volume :
598+
_mark3 = int(time())
599+
_msg = "Attaching the newly created Volume \""
600+
_msg += obj_attr_list["cloud_vv_name"] + "\" (cloud-assigned uuid \""
601+
_msg += obj_attr_list["cloud_vv_uuid"] + "\") to instance \""
602+
_msg += obj_attr_list["cloud_vm_name"] + "\" (cloud-assigned uuid \""
603+
_msg += obj_attr_list["cloud_vm_uuid"] + "\")"
604+
cbdebug(_msg)
605+
606+
if not volume.attach(_reservation) :
607+
msg = "Volume attach failed. Aborting VM creation..."
608+
cbdebug(msg, True)
609+
volume.destroy()
610+
raise CldOpsException(msg, _status)
611+
612+
cbdebug("Volume attach success.", True)
613+
_mark4 = int(time())
614+
obj_attr_list["do_015_create_volume_time"] += (_mark4 - _mark3)
615+
_status = 0
616+
else :
617+
msg = "Volume creation failed. Aborting VM creation..."
618+
cbdebug(msg, True)
619+
raise CldOpsException(msg, _status)
620+
else :
621+
obj_attr_list["cloud_vv_uuid"] = "none"
622+
540623
except CldOpsException, obj :
541624
_status = obj.status
542625
_fmsg = str(obj.msg)
@@ -563,6 +646,7 @@ def vmcreate(self, obj_attr_list) :
563646
else :
564647
if _reservation :
565648
_reservation.destroy()
649+
566650
raise CldOpsException(_msg, _status)
567651
else :
568652
_msg = "VM " + obj_attr_list["uuid"] + " was successfully "
@@ -631,6 +715,21 @@ def vmdestroy(self, obj_attr_list) :
631715
_time_mark_drc = int(time())
632716
obj_attr_list["mgt_903_deprovisioning_request_completed"] = _time_mark_drc - _time_mark_drs
633717

718+
if "cloud_vv_name" in obj_attr_list :
719+
tenant = credential_pair.split(":")[0]
720+
cbdebug("Checking for volumes from tenant: " + tenant)
721+
_volumes = catalogs.digitalocean[credential_pair].list_volumes()
722+
for _volume in _volumes :
723+
if _volume.name == obj_attr_list["cloud_vv_name"] :
724+
try :
725+
cbdebug("Destroying: " + _volume.name + " (" + tenant + ")", True)
726+
_volume.destroy()
727+
break
728+
except :
729+
pass
730+
else :
731+
cbdebug("Ignoring volume: " + _volume.name)
732+
634733
_status = 0
635734

636735
except CldOpsException, obj :
@@ -912,3 +1011,4 @@ def aiundefine(self, obj_attr_list, current_step) :
9121011
_msg += "\"."
9131012
cbdebug(_msg)
9141013
return _status, _msg
1014+

scripts/common/cb_common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ function mount_filesystem_on_volume {
454454
if [[ $(check_filesystem $VOLUME) == "none" ]]
455455
then
456456
syslog_netcat "Creating $FILESYS_TYPE filesystem on volume $VOLUME"
457-
sudo mkfs.$FILESYS_TYPE $VOLUME
457+
sudo mkfs.$FILESYS_TYPE -F $VOLUME
458458
fi
459459

460460
syslog_netcat "Making $FILESYS_TYPE filesystem on volume $VOLUME accessible through the mountpoint ${MOUNTPOINT_DIR}"
@@ -511,7 +511,7 @@ function mount_filesystem_on_memory {
511511
if [[ $(check_filesystem $RAMDEVICE) == "none" ]]
512512
then
513513
syslog_netcat "Creating $FILESYS_TYPE filesystem on volume $VOLUME"
514-
sudo mkfs.$FILESYS_TYPE $RAMDEVICE
514+
sudo mkfs.$FILESYS_TYPE -F $RAMDEVICE
515515
fi
516516

517517
syslog_netcat "Making $FILESYS_TYPE filesystem on ram disk $RAMDEVICE accessible through the mountpoint ${MOUNTPOINT_DIR}"

scripts/ibm_daytrader_ppc64le/cb_setup_ramdisk.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [[ x"${RAMDISK}" == x || x"${RAMDISK}" == "false" ]]; then
3535
else
3636
syslog_netcat "Setting RAMDISK (${RAMDISK_DEVICE} for holding DB2 database ${DATABASE_NAME} on host ($SHORT_HOSTNAME)"
3737
sudo mkdir ${DATABASE_PATH}
38-
sudo mkfs.ext4 /dev/ram0
38+
sudo mkfs.ext4 -F /dev/ram0
3939
sudo mount /dev/ram0 $DATABASE_PATH
4040
sudo chown ${my_login_username}:${my_login_username} $DATABASE_PATH
4141
syslog_netcat "Copying ${DATABASE_PATH}_${SIZE} contents to ${DATABASE_PATH}"

scripts/mongo_ycsb/cb_restart_mongo.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ then
4242
if [[ $(check_filesystem $VOLUME) == "none" ]]
4343
then
4444
syslog_netcat "Creating $MONGODB_DATA_FSTYP filesystem on volume $VOLUME"
45-
sudo mkfs.$MONGODB_DATA_FSTYP $VOLUME
45+
sudo mkfs.$MONGODB_DATA_FSTYP -F $VOLUME
4646
fi
4747
syslog_netcat "Making $MONGODB_DATA_FSTYP filesystem on volume $VOLUME accessible through the mountpoint ${MONGODB_DATA_DIR}"
4848
sudo mount $VOLUME ${MONGODB_DATA_DIR}
@@ -82,4 +82,4 @@ else
8282
fi
8383

8484
provision_application_stop $START
85-
exit ${STATUS}
85+
exit ${STATUS}

scripts/mongo_ycsb/cb_restart_mongo_cfg.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ then
2323
if [[ $(check_filesystem $VOLUME) == "none" ]]
2424
then
2525
syslog_netcat "Creating $MONGODB_DATA_FSTYP filesystem on volume $VOLUME"
26-
sudo mkfs.$MONGODB_DATA_FSTYP $VOLUME
26+
sudo mkfs.$MONGODB_DATA_FSTYP -F $VOLUME
2727
fi
2828
syslog_netcat "Making $MONGODB_DATA_FSTYP filesystem on volume $VOLUME accessible through the mountpoint ${MONGODB_DATA_DIR}"
2929
sudo mount $VOLUME ${MONGODB_DATA_DIR}
@@ -75,4 +75,4 @@ fi
7575

7676
provision_application_stop $START
7777

78-
exit ${STATUS}
78+
exit ${STATUS}

scripts/open_daytrader/cb_setup_ramdisk.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [[ x"${RAMDISK}" == x || x"${RAMDISK}" == "false" ]]; then
3535
else
3636
syslog_netcat "Setting RAMDISK (${RAMDISK_DEVICE} for holding DB2 database ${DATABASE_NAME} on host ($SHORT_HOSTNAME)"
3737
sudo mkdir ${DATABASE_PATH}
38-
sudo mkfs.ext4 /dev/ram0
38+
sudo mkfs.ext4 -F /dev/ram0
3939
sudo mount /dev/ram0 $DATABASE_PATH
4040
sudo chown klabuser:klabuser $DATABASE_PATH
4141
syslog_netcat "Copying ${DATABASE_PATH}_${SIZE} contents to ${DATABASE_PATH}"

0 commit comments

Comments
 (0)