Esempio n. 1
0
def main():
    waagent.LoggerInit('/var/log/waagent.log','/dev/stdout')
    waagent.Log("%s started to handle." %(ExtensionShortName))    

    global hutil
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error, ExtensionShortName)
    hutil.try_parse_context()

    global public_settings
    public_settings = hutil.get_public_settings()
    if not public_settings:
        public_settings = {}

    global protected_settings
    protected_settings = hutil.get_protected_settings()
    if not protected_settings:
        protected_settings = {}

    global distro_category
    distro_category = get_distro_category()

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
Esempio n. 2
0
def main():
    waagent.LoggerInit('/var/log/waagent.log','/dev/stdout')
    waagent.Log("%s started to handle." %(ExtensionShortName))    

    global hutil
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    hutil.try_parse_context()

    global public_settings
    public_settings = hutil.get_public_settings()
    if not public_settings:
        waagent.AddExtensionEvent(name=ExtensionShortName, op='MainInProgress', isSuccess=True, message="Public settings are NOT provided.")
        public_settings = {}

    global protected_settings
    protected_settings = hutil.get_protected_settings()
    if not protected_settings:
        waagent.AddExtensionEvent(name=ExtensionShortName, op='MainInProgress', isSuccess=True, message="protected settings are NOT provided.")    
        protected_settings = {}

    global distro_category
    distro_category = get_distro_category()

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
def enable():
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error, ExtensionShortName)
    hutil.do_parse_context('Enable')
    try:
        protect_settings = hutil._context._config['runtimeSettings'][0][
            'handlerSettings'].get('protectedSettings')
        reset_ssh = protect_settings.get('reset_ssh')
        # check port each time the VM boots up
        if reset_ssh:
            _open_ssh_port()
            hutil.log("Succeeded in check and open ssh port.")
        hutil.exit_if_enabled()
        remove_user = protect_settings.get('remove_user')
        if reset_ssh:
            _reset_sshd_config("/etc/ssh/sshd_config")
            hutil.log("Succeeded in reset sshd_config.")
        if remove_user:
            _remove_user_account(remove_user, hutil)
        _set_user_account_pub_key(protect_settings, hutil)
        hutil.do_exit(0, 'Enable', 'success', '0', 'Enable succeeded.')
    except Exception, e:
        hutil.error(
            "Failed to enable the extension with error: %s, stack trace: %s" %
            (str(e), traceback.format_exc()))
        hutil.do_exit(1, 'Enable', 'error', '0', 'Enable failed.')
def main():
    global logger
    global hutil
    global MyPatching
    HandlerUtil.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    HandlerUtil.waagent.Log("%s started to handle." %
                            (CommonVariables.extension_name))
    hutil = HandlerUtil.HandlerUtility(HandlerUtil.waagent.Log,
                                       HandlerUtil.waagent.Error,
                                       CommonVariables.extension_name)
    logger = RDMALogger(hutil)
    MyPatching = GetMyPatching(logger)
    hutil.patching = MyPatching
    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
        elif re.match("^([-/]*)(rdmaupdate)", a):
            rdmaupdate()
        elif re.match("^([-/]*)(chkrdma)", a):
            chkrdma()
Esempio n. 5
0
def main():
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    global hutil
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error, ExtensionShortName)
    global myProvision
    myProvision = GetMyProvision(hutil)
    if myProvision == None:
        sys.exit(1)

    if os.path.isfile("mrseq"):
        os.remove("mrseq")

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
        elif re.match("^([-/]*)(provision)", a):
            provision()
def init_globals():
    """Initialize all the globals in a function so that we can catch any exceptions that might be raised."""
    global hutil, WorkDir, MDSDFileResourcesDir, MDSDRoleName, MDSDFileResourcesPrefix, MDSDPidFile, MDSDPidPortFile
    global EnableSyslog, ExtensionOperationType, MdsdFolder, StartDaemonFilePath, MDSD_LISTEN_PORT, omfileconfig
#    global rsyslog_ommodule_for_check, RunGetOutput, MdsdFolder, omi_universal_pkg_name
#    global DebianConfig, RedhatConfig, UbuntuConfig1510OrHigher, SUSE11_MDSD_SSL_CERTS_FILE
#    global SuseConfig11, SuseConfig12, CentosConfig, All_Dist

    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("LinuxAzureDiagnostic started to handle.")
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    init_distro_specific_actions()

    WorkDir = os.getcwd()
    MDSDFileResourcesDir = "/var/run/mdsd"
    MDSDRoleName = 'lad_mdsd'
    MDSDFileResourcesPrefix = os.path.join(MDSDFileResourcesDir, MDSDRoleName)
    MDSDPidFile = os.path.join(WorkDir, 'mdsd.pid')
    MDSDPidPortFile = MDSDFileResourcesPrefix + '.pidport'
    EnableSyslog = True
    ExtensionOperationType = None
    MdsdFolder = os.path.join(WorkDir, 'bin')
    StartDaemonFilePath = os.path.join(os.getcwd(), __file__)
    MDSD_LISTEN_PORT = 29131
    omfileconfig = os.path.join(WorkDir, 'omfileconfig')

    init_public_and_private_settings()
Esempio n. 7
0
def enable():
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    hutil.do_parse_context('Enable')
    try:
        _forcibly_reset_chap(hutil)

        reset_ssh = None
        remove_user = None
        protect_settings = hutil.get_protected_settings()
        if protect_settings:
            reset_ssh = protect_settings.get('reset_ssh')
            remove_user = protect_settings.get('remove_user')

        if remove_user and _is_sshd_config_modified(protect_settings):
            hutil.error(
                "Cannot reset sshd_config and remove a user in one operation.")
            waagent.AddExtensionEvent(
                name=hutil.get_name(),
                op=waagent.WALAEventOperation.Enable,
                isSuccess=False,
                message="(03002)Argument error, conflicting operations")
            hutil.do_exit(1, 'Enable', 'error', '0', 'Enable failed.')

        # check port each time the VM boots up
        if reset_ssh:
            _open_ssh_port()
            hutil.log("Succeeded in check and open ssh port.")

        hutil.exit_if_enabled()
        if _is_sshd_config_modified(protect_settings):
            _backup_sshd_config(SshdConfigPath)

        if reset_ssh:
            waagent.AddExtensionEvent(name=hutil.get_name(),
                                      op="scenario",
                                      isSuccess=True,
                                      message="reset-ssh")
            _reset_sshd_config(SshdConfigPath)
            hutil.log("Succeeded in reset sshd_config.")

        if remove_user:
            waagent.AddExtensionEvent(name=hutil.get_name(),
                                      op="scenario",
                                      isSuccess=True,
                                      message="remove-user")
            _remove_user_account(remove_user, hutil)

        _set_user_account_pub_key(protect_settings, hutil)

        if _is_sshd_config_modified(protect_settings):
            waagent.MyDistro.restartSshService()

        check_and_repair_disk(hutil)
        hutil.do_exit(0, 'Enable', 'success', '0', 'Enable succeeded.')
    except Exception as e:
        hutil.error(("Failed to enable the extension with error: {0}, "
                     "stack trace: {1}").format(str(e),
                                                traceback.format_exc()))
        hutil.do_exit(1, 'Enable', 'error', '0', 'Enable failed.')
Esempio n. 8
0
def parse_context(operation):
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    hutil.do_parse_context(operation)
    op_log = os.path.join(hutil.get_log_dir(), OperationFileName.format(hutil.get_extension_version()))
    with open(op_log, 'a+') as oplog_handler:
        oplog_handler.write("Date:{0}; Operation:{1}; SeqNo:{2}\n"
                            .format(datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
                                    operation, hutil.get_seq_no()))
    return hutil
Esempio n. 9
0
def get_settings():
    import Utils.HandlerUtil as Util
    from Utils.WAAgentUtil import waagent
    waagent.LoggerInit('/var/log/waagent.log', '/dev/null')
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error,
                                "bosh-deploy-script")
    hutil.do_parse_context("enable")

    return hutil.get_public_settings()
 def setUp(self):
     self.logger = console_logger.ConsoleLogger()
     self.distro_patcher = patch.GetDistroPatcher(self.logger)
     self.hutil = HandlerUtil.HandlerUtility(self.logger.log, self.logger.error, "AzureDiskEncryptionForLinux")
     self.hutil.patching = self.distro_patcher
     # invoke unit test from within main for setup (to avoid having to change dependencies)
     # then move cwd to parent to emulate calling convention of guest agent 
     if os.getcwd().endswith('main'):
         os.chdir(os.path.dirname(os.getcwd()))
     else:
         self.logger.log(os.getcwd())
Esempio n. 11
0
def get_settings():
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error,
                                "bosh-deploy-script")
    hutil.do_parse_context("enable")
    settings_path = os.path.join('bosh', 'settings')

    call("mkdir -p ./bosh", shell=True)

    if not os.path.isfile(settings_path):
        settings = hutil.get_public_settings()
        with open(settings_path, "w") as tmpfile:
            tmpfile.write(json.dumps(settings, indent=4, sort_keys=True))
    else:
        with open(settings_path) as settings_file:
            settings = json.load(settings_file)

    return settings
def main():
    global MyPatching,backup_logger,hutil
    HandlerUtil.LoggerInit('/var/log/waagent.log','/dev/stdout')
    HandlerUtil.waagent.Log("%s started to handle." % (CommonVariables.extension_name)) 
    hutil = HandlerUtil.HandlerUtility(HandlerUtil.waagent.Log, HandlerUtil.waagent.Error, CommonVariables.extension_name)
    backup_logger = Backuplogger(hutil)
    MyPatching = GetMyPatching(logger = backup_logger)
    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
    def setUp(self):
        print '\n\n============================================================================================'
        waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
        waagent.Log("%s started to handle." % (ExtensionShortName))

        global protect_settings
        protect_settings = json.loads(contents)
        global hutil
        hutil = Util.HandlerUtility(waagent.Log, waagent.Error,
                                    ExtensionShortName)
        global MyPatching
        MyPatching = FakePatching(hutil)
        if MyPatching == None:
            sys.exit(1)

        try:
            os.remove('mrseq')
        except:
            pass

        waagent.SetFileContents(MyPatching.package_downloaded_path, '')
        waagent.SetFileContents(MyPatching.package_patched_path, '')