def enable(hutil): hutil.exit_if_enabled() public_settings = hutil.get_public_settings() protected_settings = hutil.get_protected_settings() if public_settings is None: raise ValueError("Public configuration cannot be None.") if protected_settings is None: raise ValueError("Private configuration cannot be None.") workspaceId = public_settings.get("workspaceId") workspaceKey = protected_settings.get("workspaceKey") if workspaceId is None: raise ValueError("Workspace ID cannot be None.") if workspaceKey is None: raise ValueError("Workspace key cannot be None.") cmd = OnboardCommandTemplate.format(workspaceId, workspaceKey) exit_code = ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), OmsAdminWorkingDirectory, 'Onboard', ExtensionShortName, hutil.get_extension_version(), False) # if onboard succeeds we continue, otherwise fail fast if exit_code == 0: ScriptUtil.run_command( hutil, ScriptUtil.parse_args(EnableOmsAgentServiceCommand), ServiceControlWorkingDirectory, 'Enable', ExtensionShortName, hutil.get_extension_version()) else: sys.exit(exit_code)
def install(hutil): file_directory = os.path.join(os.getcwd(), PackagesDirectory) file_path = os.path.join(file_directory, BundleFileName) os.chmod(file_path, 100) cmd = InstallCommandTemplate.format(BundleFileName) ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), file_directory, 'Install', ExtensionShortName, hutil.get_extension_version())
def uninstall(hutil): file_name = getbundlefilename() file_directory = os.path.join(os.getcwd(), PackagesDirectory) cmd = UninstallCommandTemplate.format(file_name) ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), file_directory, 'Uninstall', ExtensionShortName, hutil.get_extension_version())
def enable(hutil): hutil.exit_if_enabled() public_settings = hutil.get_public_settings() protected_settings = hutil.get_protected_settings() if public_settings is None: raise ValueError("Public configuration cannot be None.") if protected_settings is None: raise ValueError("Private configuration cannot be None.") workspaceId = public_settings.get("workspaceId") workspaceKey = protected_settings.get("workspaceKey") proxy = protected_settings.get("proxy") vmResourceId = protected_settings.get("vmResourceId") if workspaceId is None: raise ValueError("Workspace ID cannot be None.") if workspaceKey is None: raise ValueError("Workspace key cannot be None.") proxyParam = "" if proxy is not None: proxyParam = "-p {0}".format(proxy) vmResourceIdParam = "" if vmResourceId is not None: vmResourceIdParam = "-a {0}".format(vmResourceId) optionalParams = "{0} {1}".format(proxyParam, vmResourceIdParam) cmd = OnboardCommandWithOptionalParamsTemplate.format(workspaceId, workspaceKey, optionalParams) exit_code = ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), OmsAdminWorkingDirectory, 'Onboard', ExtensionShortName, hutil.get_extension_version(), False) # if onboard succeeds we continue, otherwise fail fast if exit_code == 0: ScriptUtil.run_command(hutil, ScriptUtil.parse_args(EnableOmsAgentServiceCommand), ServiceControlWorkingDirectory, 'Enable', ExtensionShortName, hutil.get_extension_version()) else: sys.exit(exit_code)
def enable(hutil): hutil.exit_if_enabled() public_settings = hutil.get_public_settings() protected_settings = hutil.get_protected_settings() if public_settings is None: raise ValueError("Public configuration cannot be None.") if protected_settings is None: raise ValueError("Private configuration cannot be None.") workspaceId = public_settings.get("workspaceId") workspaceKey = protected_settings.get("workspaceKey") if workspaceId is None: raise ValueError("Workspace ID cannot be None.") if workspaceKey is None: raise ValueError("Workspace key cannot be None.") cmd = OnboardCommandTemplate.format(workspaceId, workspaceKey) exit_code = ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), OmsAdminWorkingDirectory, 'Onboard', ExtensionShortName, Version, False) # if onboard succeeds we continue, otherwise fail fast if exit_code == 0: ScriptUtil.run_command(hutil, ScriptUtil.parse_args(EnableOmsAgentServiceCommand), ServiceControlWorkingDirectory, 'Enable', ExtensionShortName, Version) else: sys.exit(exit_code)
def daemon(hutil): retry_count = 10 wait = 20 enable_idns_check = True public_settings = hutil.get_public_settings() if public_settings: if 'retrycount' in public_settings: retry_count = public_settings.get('retrycount') if 'wait' in public_settings: wait = public_settings.get('wait') if 'enableInternalDNSCheck' in public_settings: # removed strtobool/distutils dependency, implementation is based on strtobool specification enable_idns_check_setting = public_settings.get( 'enableInternalDNSCheck') enable_idns_check = True if ( (enable_idns_check_setting.lower() == "yes") | (enable_idns_check_setting.lower() == "y") | (enable_idns_check_setting.lower() == "true") | (enable_idns_check_setting.lower() == "t") | (enable_idns_check_setting.lower() == "on") | (enable_idns_check_setting.lower() == "1")) else False prepare_download_dir(hutil.get_seq_no()) retry_count = download_files_with_retry(hutil, retry_count, wait) # The internal DNS needs some time to be ready. # Wait and retry to check if there is time in retry window. # The check may be removed safely if iDNS is always ready. if enable_idns_check: check_idns_with_retry(hutil, retry_count, wait) cmd = get_command_to_execute(hutil) args = ScriptUtil.parse_args(cmd) if args: ScriptUtil.run_command(hutil, args, prepare_download_dir(hutil.get_seq_no()), 'Daemon', ExtensionShortName, hutil.get_extension_version()) else: error_msg = "commandToExecute is empty or invalid." hutil.error(error_msg) waagent.AddExtensionEvent(name=ExtensionShortName, op=RunScriptOp, isSuccess=False, version=hutil.get_extension_version(), message="(01002)" + error_msg) raise ValueError(error_msg)
def daemon(hutil): retry_count = 10 wait = 20 enable_idns_check = True public_settings = hutil.get_public_settings() if public_settings: if 'retrycount' in public_settings: retry_count = public_settings.get('retrycount') if 'wait' in public_settings: wait = public_settings.get('wait') if 'enableInternalDNSCheck' in public_settings: # removed strtobool/distutils dependency, implementation is based on strtobool specification enable_idns_check_setting = public_settings.get('enableInternalDNSCheck') enable_idns_check = True if ((enable_idns_check_setting.lower() == "yes") | (enable_idns_check_setting.lower() == "y") | (enable_idns_check_setting.lower() == "true") | (enable_idns_check_setting.lower() == "t") | (enable_idns_check_setting.lower() == "on") | (enable_idns_check_setting.lower() == "1")) else False prepare_download_dir(hutil.get_seq_no()) retry_count = download_files_with_retry(hutil, retry_count, wait) # The internal DNS needs some time to be ready. # Wait and retry to check if there is time in retry window. # The check may be removed safely if iDNS is always ready. if enable_idns_check: check_idns_with_retry(hutil, retry_count, wait) cmd = get_command_to_execute(hutil) args = ScriptUtil.parse_args(cmd) if args: ScriptUtil.run_command(hutil, args, prepare_download_dir(hutil.get_seq_no()), 'Daemon', ExtensionShortName, hutil.get_extension_version()) else: error_msg = "commandToExecute is empty or invalid." hutil.error(error_msg) waagent.AddExtensionEvent(name=ExtensionShortName, op=RunScriptOp, isSuccess=False, version=hutil.get_extension_version(), message="(01002)"+error_msg) raise ValueError(error_msg)
def daemon(hutil): retry_count = 10 wait = 20 enable_idns_check = True public_settings = hutil.get_public_settings() if public_settings: if 'retrycount' in public_settings: retry_count = public_settings.get('retrycount') if 'wait' in public_settings: wait = public_settings.get('wait') if 'enableInternalDNSCheck' in public_settings: enable_idns_check = public_settings.get('enableInternalDNSCheck') prepare_download_dir(hutil.get_seq_no()) retry_count = download_files_with_retry(hutil, retry_count, wait) # The internal DNS needs some time to be ready. # Wait and retry to check if there is time in retry window. # The check may be removed safely if iDNS is always ready. if enable_idns_check: check_idns_with_retry(hutil, retry_count, wait) cmd = get_command_to_execute(hutil) args = ScriptUtil.parse_args(cmd) if args: ScriptUtil.run_command(hutil, args, prepare_download_dir(hutil.get_seq_no()), 'Daemon', ExtensionShortName, Version) else: error_msg = "CommandToExecute is empty or invalid." hutil.error(error_msg) waagent.AddExtensionEvent(name=ExtensionShortName, op=RunScriptOp, isSuccess=False, version=Version, message="(01002)" + error_msg) raise ValueError(error_msg)
def daemon(hutil): retry_count = 10 wait = 20 enable_idns_check = True public_settings = hutil.get_public_settings() if public_settings: if 'retrycount' in public_settings: retry_count = public_settings.get('retrycount') if 'wait' in public_settings: wait = public_settings.get('wait') if 'enableInternalDNSCheck' in public_settings: enable_idns_check = strtobool(public_settings.get('enableInternalDNSCheck')) prepare_download_dir(hutil.get_seq_no()) retry_count = download_files_with_retry(hutil, retry_count, wait) # The internal DNS needs some time to be ready. # Wait and retry to check if there is time in retry window. # The check may be removed safely if iDNS is always ready. if enable_idns_check: check_idns_with_retry(hutil, retry_count, wait) cmd = get_command_to_execute(hutil) args = ScriptUtil.parse_args(cmd) if args: ScriptUtil.run_command(hutil, args, prepare_download_dir(hutil.get_seq_no()), 'Daemon', ExtensionShortName, Version) else: error_msg = "CommandToExecute is empty or invalid." hutil.error(error_msg) waagent.AddExtensionEvent(name=ExtensionShortName, op=RunScriptOp, isSuccess=False, version=Version, message="(01002)"+error_msg) raise ValueError(error_msg)
def disable(hutil): ScriptUtil.run_command(hutil, ScriptUtil.parse_args(DisableOmsAgentServiceCommand), ServiceControlWorkingDirectory, 'Disable', ExtensionShortName, hutil.get_extension_version())
def uninstall(hutil): file_name = getbundlefilename(); file_directory = os.path.join(os.getcwd(), PackagesDirectory) cmd = UninstallCommandTemplate.format(file_name) ScriptUtil.run_command(hutil, ScriptUtil.parse_args(cmd), file_directory, 'Uninstall', ExtensionShortName, Version)
def disable(hutil): ScriptUtil.run_command( hutil, ScriptUtil.parse_args(DisableOmsAgentServiceCommand), ServiceControlWorkingDirectory, 'Disable', ExtensionShortName, hutil.get_extension_version())