def update_user_home_image(fetch=True): plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE) if plugin is None: VolMgr.log_info("No plugin provided for bucketstore. Can not update packages and user home images") return home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG) pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG) bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image(Compute.get_install_id()) new_home_img_path = os.path.join(home_img_dir, new_home_img) new_pkg_img_path = os.path.join(pkg_img_dir, new_pkg_img) updated = False for img_path in (new_home_img_path, new_pkg_img_path): if not os.path.exists(img_path): if fetch: VolMgr.log_debug("fetching new image to %s", img_path) k = plugin.pull(bucket, img_path) if k is not None: VolMgr.log_debug("fetched new image") if os.path.exists(new_home_img_path): VolMgr.log_debug("set new home image to %s", new_home_img_path) JBoxVol.USER_HOME_IMG = new_home_img_path updated = True if os.path.exists(new_pkg_img_path): VolMgr.log_debug("set new pkg image to %s", new_pkg_img_path) JBoxVol.PKG_IMG = new_pkg_img_path updated = True return updated
def update_user_home_image(fetch=True): plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE) if plugin is None: VolMgr.log_info("No plugin provided for bucketstore. Can not update packages and user home images") return home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG) pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG) bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image(Compute.get_install_id()) new_home_img_path = os.path.join(home_img_dir, new_home_img) new_pkg_img_path = os.path.join(pkg_img_dir, new_pkg_img) updated = False for img_path in (new_home_img_path, new_pkg_img_path): if not os.path.exists(img_path): if fetch: VolMgr.log_debug("fetching new image to %s", img_path) k = plugin.pull(bucket, img_path) if k is not None: VolMgr.log_debug("fetched new image") if os.path.exists(new_home_img_path): VolMgr.log_debug("set new home image to %s", new_home_img_path) JBoxVol.USER_HOME_IMG = new_home_img_path updated = True if os.path.exists(new_pkg_img_path): VolMgr.log_debug("set new pkg image to %s", new_pkg_img_path) JBoxVol.PKG_IMG = new_pkg_img_path updated = True return updated
def has_update_for_user_home_image(): home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG) pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG) # VolMgr.log_debug("checking for updates to user home image %s/%s", img_dir, curr_img) bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image( Compute.get_install_id()) if bucket is None: VolMgr.log_info("Home: none configured. current: %s/%s", home_img_dir, curr_home_img) return False if new_home_img == curr_home_img and new_pkg_img == curr_pkg_img: VolMgr.log_info("Home: no updates. current: %s/%s", home_img_dir, curr_home_img) VolMgr.log_info("Packages: no updates. current: %s/%s", pkg_img_dir, curr_pkg_img) return False else: VolMgr.log_info("Home: update: %s/%s. current: %s/%s", bucket, new_home_img, home_img_dir, curr_home_img) VolMgr.log_info("Packages: update: %s/%s. current: %s/%s", bucket, new_pkg_img, home_img_dir, curr_pkg_img) return True
def has_update_for_user_home_image(): home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG) pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG) # VolMgr.log_debug("checking for updates to user home image %s/%s", img_dir, curr_img) bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image(Compute.get_install_id()) if bucket is None: VolMgr.log_info("Home: none configured. current: %s/%s", home_img_dir, curr_home_img) return False if new_home_img == curr_home_img and new_pkg_img == curr_pkg_img: VolMgr.log_info("Home: no updates. current: %s/%s", home_img_dir, curr_home_img) VolMgr.log_info("Packages: no updates. current: %s/%s", pkg_img_dir, curr_pkg_img) return False else: VolMgr.log_info("Home: update: %s/%s. current: %s/%s", bucket, new_home_img, home_img_dir, curr_home_img) VolMgr.log_info("Packages: update: %s/%s. current: %s/%s", bucket, new_pkg_img, home_img_dir, curr_pkg_img) return True
def test(): sprops = JBoxSessionProps(TESTCLSTR, unique_sessname('*****@*****.**')) TestDBTables.log_debug("JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s", sprops.get_user_id(), sprops.get_snapshot_id(), sprops.get_message()) JBoxDynConfig.set_cluster_leader(TESTCLSTR, 'testinstance') assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) == 'testinstance' JBoxDynConfig.unset_cluster_leader(TESTCLSTR) assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) is None assert JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, False) assert not JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, True) assert JBoxDynConfig.get_allow_registration(TESTCLSTR) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 20) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 20 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 60) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 assert JBoxDynConfig.get_message(TESTCLSTR) is None JBoxDynConfig.set_message(TESTCLSTR, "hello world", datetime.timedelta(minutes=1)) assert JBoxDynConfig.get_message(TESTCLSTR) == "hello world" JBoxDynConfig.set_user_home_image(TESTCLSTR, "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") assert JBoxDynConfig.get_user_home_image(TESTCLSTR) == ("juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") num_pending_activations = JBoxUserV2.count_pending_activations() TestDBTables.log_debug("pending activations: %d", num_pending_activations) count_created = JBoxUserV2.count_created(48) TestDBTables.log_debug("accounts created in last 1 hour: %d", count_created)