Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Fixes EUCA-12541 and EUCA-12539
Browse files Browse the repository at this point in the history
Update to check for dependencies needed to execute external commands and bail if not met
Also add hints to -h/usage for depedencies needed.
Adding --sc-host-port command line parameter for consuming the storage controller location
  • Loading branch information
Jeremy Breiding committed Jul 6, 2016
1 parent 516ed5d commit d5c8095
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
46 changes: 27 additions & 19 deletions tools/nodeadmin-pack-instance
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def _time_out(func, args=(), kwargs={}, timeout_duration=1, default=None):

def _parse_args():
parser = argparse.ArgumentParser(description="Pack an instance from libvirt and "
"place artifacts in an packed file")
"place artifacts in an packed file",
epilog="The following environment variables must be established as well:\n"
"EUCALYPTUS=/\n"
"AXIS2C_HOME=/usr/lib64/axis2c\n"
"LD_LIBRARY_PATH=$AXIS2C_HOME/lib:$AXIS2C_HOME/modules/rampart\n",
formatter_class=argparse.RawDescriptionHelpFormatter)

group_i = parser.add_mutually_exclusive_group(required=True)
group_i.add_argument("--all",
Expand All @@ -127,6 +132,9 @@ def _parse_args():
parser.add_argument("--no-compression",
help="skip compression during packing operation",
action="store_true")
parser.add_argument("--sc-host-port",
help="the host and port of the storage controller",
required=True)

args = parser.parse_args()
loglevel = logging.INFO
Expand Down Expand Up @@ -191,21 +199,9 @@ def _lookup_domain(conn, instance_name):
return domain


def _find_storage_controller():
euserv_cmd = ["/usr/bin/euserv-describe-services",
"--filter", "service-type=storage", "--expert"]

proc = Popen(euserv_cmd, stdout=PIPE)
storage_controller = proc.stdout.read().split()[4]
logging.debug(storage_controller)

return storage_controller


def _disconnect_volumes(instance_id):
storage_controller = _find_storage_controller()
def _disconnect_volumes(instance_id, sc_host_port):
scclient_args = [
"DisconnectVolumes", "-s", storage_controller, "-i", instance_id]
"DisconnectVolumes", "-s", sc_host_port, "-i", instance_id]
scclient_cmd = [_NODEADMIN_VOLUME] + scclient_args

rc = check_call(scclient_cmd)
Expand Down Expand Up @@ -372,7 +368,7 @@ def _gather_files(instance_name, instance_path):
return target_files


def pack_instance(instance, output_file, shutdown, skip_compression):
def pack_instance(instance, output_file, shutdown, skip_compression, sc_host_port):
logging.debug("attempting to pack instance %s", instance)
instance_tuple = None

Expand Down Expand Up @@ -405,7 +401,7 @@ def pack_instance(instance, output_file, shutdown, skip_compression):
_modify_libvirt_xml(instance_tuple[1])
_create_tar(tar_files, output_file, skip_compression)

_disconnect_volumes(instance_tuple[0])
_disconnect_volumes(instance_tuple[0], sc_host_port)

return 0

Expand Down Expand Up @@ -434,6 +430,13 @@ def _place_stop_delete_file():
stat.S_IXGRP | stat.S_IRGRP | stat.S_IROTH | stat.S_IXOTH)


def _check_for_axisc_environment():
env_eucalyptus = len(os.getenv("EUCALYPTUS") or "") > 0
env_axis2c_home = len(os.getenv("AXIS2C_HOME") or "") > 0
env_ld_library_path = len(os.getenv("LD_LIBRARY_PATH") or "") > 0
return (env_eucalyptus and env_axis2c_home and env_ld_library_path)


def _main(args, log_level):
logging.basicConfig(format="%(levelname)s: %(message)s", level=log_level)
logging.debug("Your Arguments: %s", args)
Expand All @@ -444,6 +447,11 @@ def _main(args, log_level):
"Node controller service is running. Please stop this service before continuing.")
return 1

if not _check_for_axisc_environment():
logging.error(
"Missing environment variables $EUCALYPTUS, $AXIS2C_HOME and LD_LIBRARY_PATH")
return 1

_place_stop_delete_file()

if args.all:
Expand All @@ -453,7 +461,7 @@ def _main(args, log_level):
output_file = os.path.join(
args.output_directory, instance + _PACK_TAR)
rc = pack_instance(
instance, output_file, args.shutdown, args.no_compression)
instance, output_file, args.shutdown, args.no_compression, args.sc_host_port)
if rc:
logging.warn(
"Failed packing instance %s (%d)", instance, rc)
Expand All @@ -465,7 +473,7 @@ def _main(args, log_level):
output_file = os.path.join(
args.output_directory, args.instance + _PACK_TAR)
rc = pack_instance(
args.instance, output_file, args.shutdown, args.no_compression)
args.instance, output_file, args.shutdown, args.no_compression, args.sc_host_port)

if rc:
logging.warn(
Expand Down
46 changes: 27 additions & 19 deletions tools/nodeadmin-unpack-instance
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,21 @@ def _time_out(func, args=(), kwargs={}, timeout_duration=1, default=None):

def _parse_args():
parser = argparse.ArgumentParser(description="Restore an instance to libvirt after "
"unpacking artifacts from packed file")
"unpacking artifacts from packed file",
epilog="The following environment variables must be established as well:\n"
"EUCALYPTUS=/\n"
"AXIS2C_HOME=/usr/lib64/axis2c\n"
"LD_LIBRARY_PATH=$AXIS2C_HOME/lib:$AXIS2C_HOME/modules/rampart\n",
formatter_class=argparse.RawDescriptionHelpFormatter)

parser.add_argument("packed_file",
help="file path to the packed file storing the instance")
parser.add_argument("--verbose",
help="increase output verbosity",
action="store_true")
parser.add_argument("--sc-host-port",
help="the host and port of the storage controller",
required=True)

args = parser.parse_args()

Expand Down Expand Up @@ -164,17 +172,6 @@ def _lookup_domain(conn, instance_name):
return domain


def _find_storage_controller():
euserv_cmd = ["/usr/bin/euserv-describe-services",
"--filter", "service-type=storage", "--expert"]

proc = Popen(euserv_cmd, stdout=PIPE)
storage_controller = proc.stdout.read().split()[4]
logging.debug(storage_controller)

return storage_controller


def _restore_instance(instance, instance_path, *args, **kwargs):
conn = _get_libvirt_connection()
rc = None
Expand Down Expand Up @@ -208,11 +205,9 @@ def _get_eucalyptus_home_path():
return _get_conf_value(_EUCALYPTUS)


def _connect_volumes(instance_id):
storage_controller = _find_storage_controller()

def _connect_volumes(instance_id, sc_host_port):
scclient_args = [
"ConnectVolumes", "-s", storage_controller, "-i", instance_id]
"ConnectVolumes", "-s", sc_host_port, "-i", instance_id]
scclient_cmd = [_NODEADMIN_VOLUME] + scclient_args

rc = check_call(scclient_cmd)
Expand All @@ -233,7 +228,7 @@ def _change_ownership(instance_path):
instance_path = os.path.dirname(instance_path)


def unpack_instance(instance_path, packed_path):
def unpack_instance(instance_path, packed_path, sc_host_port):
_extract_files(packed_path)

instance_name = os.path.basename(instance_path)
Expand All @@ -248,7 +243,7 @@ def unpack_instance(instance_path, packed_path):

_change_ownership(instance_path)

_connect_volumes(instance_name)
_connect_volumes(instance_name, sc_host_port)

_restore_instance(instance_name, instance_path)
logging.info("instance %s unpacked", instance_name)
Expand All @@ -268,6 +263,13 @@ def _is_nc_service_running():
return results is not None


def _check_for_axisc_environment():
env_eucalyptus = len(os.getenv("EUCALYPTUS") or "") > 0
env_axis2c_home = len(os.getenv("AXIS2C_HOME") or "") > 0
env_ld_library_path = len(os.getenv("LD_LIBRARY_PATH") or "") > 0
return (env_eucalyptus and env_axis2c_home and env_ld_library_path)


def main(args, log_level):
logging.basicConfig(format="%(levelname)s: %(message)s", level=log_level)
logging.debug("Your Arguments: %s", args)
Expand All @@ -277,6 +279,11 @@ def main(args, log_level):
"Node controller service is running. Please stop this service before continuing.")
return 1

if not _check_for_axisc_environment():
logging.error(
"Missing environment variables $EUCALYPTUS, $AXIS2C_HOME and LD_LIBRARY_PATH")
return 1

logging.info("unpack on %s", args.packed_file)

if not os.path.exists(args.packed_file):
Expand All @@ -285,7 +292,8 @@ def main(args, log_level):
instance_tuple = _find_instance(args.packed_file)

if instance_tuple:
rc = unpack_instance(instance_tuple[1], args.packed_file)
rc = unpack_instance(
instance_tuple[1], args.packed_file, args.sc_host_port)

if rc:
raise NodeAdminUnpackError("unpack instance returned %d", rc)
Expand Down

0 comments on commit d5c8095

Please sign in to comment.