コード例 #1
0
def _get_contacts_data():
    """
    Get the contact information.  For now this is from a private github repo, but in the future
    it could be much more complicated to get the contact details
    """
    
    global _contacts_data
    # TODO: periodically update contacts info
    if not _contacts_data:
        # use local copy if it exists
        if os.path.exists("../contacts.yaml"):
            _contacts_data = get_contacts_data("../contacts.yaml")
        elif os.path.exists("/etc/opt/topology/config.ini") or os.path.exists("../config.ini"):
            # Get the contacts from bitbucket
            # Read in the config file with the SSH key location
            config = configparser.ConfigParser()
            config.read(["/etc/opt/topology/config.ini", "../config.ini"])
            ssh_key = config['git']['ssh_key']
            # Create a temporary directory to store the contact information
            with tempfile.TemporaryDirectory() as tmp_dir:
                # From SO: https://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command
                cmd = "ssh-agent bash -c 'ssh-add {0}; git clone [email protected]:opensciencegrid/contact.git {1}'".format(ssh_key, tmp_dir)

                # I know this should be Popen or similar.  But.. I am unable to make that work.
                # I suspect it has something to do with the subshell that is being executed
                git_result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8")
                if git_result.returncode != 0:
                    # Git command exited with nonzero!
                    print("Git failed:\n" + git_result.stdout, file=sys.stderr)
                _contacts_data = get_contacts_data(os.path.join(tmp_dir, 'contacts.yaml'))

    return _contacts_data
コード例 #2
0
ファイル: vo_reader.py プロジェクト: zvada/topology
def main(argv):
    parser = ArgumentParser()
    parser.add_argument("indir",
                        help="input dir for virtual-organizations data")
    parser.add_argument("outfile",
                        nargs='?',
                        default=None,
                        help="output file for vosummary")
    parser.add_argument("--contacts", help="contacts yaml file")
    parser.add_argument(
        "--nostrict",
        action='store_false',
        dest='strict',
        help="Skip files with parse errors (instead of exiting)")
    args = parser.parse_args(argv[1:])

    contacts_data = None
    if args.contacts:
        contacts_data = get_contacts_data(args.contacts)
    xml = to_xml(
        get_vos_data(args.indir,
                     contacts_data=contacts_data,
                     strict=args.strict).get_tree(authorized=True))
    if args.outfile:
        with open(args.outfile, "w") as fh:
            fh.write(xml)
    else:
        print(xml)
コード例 #3
0
def get_rgsummary_rgdowntime(indir, contacts_file=None, authorized=False):
    contacts_data = None
    if contacts_file:
        contacts_data = get_contacts_data(contacts_file)
    topology = get_topology(indir, contacts_data)
    filters = Filters()
    filters.past_days = -1
    return topology.get_resource_summary(authorized=authorized, filters=filters), \
           topology.get_downtimes(authorized=authorized, filters=filters)
コード例 #4
0
    def get_contacts_data(self) -> ContactsData:
        """
        Get the contact information from a private git repo
        """
        if self.contacts_data.should_update():
            ok = self._update_contacts_repo()
            self.contacts_data.update(contacts_reader.get_contacts_data(self.contacts_file),
                                      bump_timestamp=ok)

        return self.contacts_data.data
コード例 #5
0
ファイル: models.py プロジェクト: marcioac/topology
    def get_contacts_data(self) -> ContactsData:
        """
        Get the contact information from a private git repo
        """
        if self.contacts_data.should_update():
            ok = self._update_contacts_repo()
            if ok:
                self.contacts_data.update(contacts_reader.get_contacts_data(self.contacts_file))
            else:
                self.contacts_data.try_again()

        return self.contacts_data.data
コード例 #6
0
ファイル: models.py プロジェクト: vbrik/topology
    def get_contacts_data(self) -> ContactsData:
        """
        Get the contact information from a private git repo
        """
        if not self.config.get("CONTACT_DATA_DIR", None):
            log.debug("CONTACT_DATA_DIR not specified; getting empty contacts")
            return contacts_reader.get_contacts_data(None)
        elif self.contacts_data.should_update():
            ok = self._update_contacts_repo()
            if ok:
                try:
                    self.contacts_data.update(contacts_reader.get_contacts_data(self.contacts_file))
                except Exception:
                    if self.strict:
                        raise
                    log.exception("Failed to update contacts data")
                    self.contacts_data.try_again()
            else:
                self.contacts_data.try_again()

        return self.contacts_data.data
コード例 #7
0
ファイル: models.py プロジェクト: marcoverl/topology
    def get_contacts_data(self) -> ContactsData:
        """
        Get the contact information from a private git repo
        """
        if self.contacts_data.should_update():
            ok = self._update_contacts_repo()
            if ok:
                try:
                    self.contacts_data.update(
                        contacts_reader.get_contacts_data(self.contacts_file))
                except Exception:
                    if self.strict:
                        raise
                    log.exception("Failed to update contacts data")
                    self.contacts_data.try_again()
            else:
                self.contacts_data.try_again()

        return self.contacts_data.data
コード例 #8
0
ファイル: models.py プロジェクト: zvada/topology
    def get_comanage_data(self) -> ContactsData:
        """
        Get the contact information from comanage / cilogon ldap
        """
        if not (self.cilogon_ldap_url and self.cilogon_ldap_user
                and self.cilogon_ldap_passfile):
            log.debug("CILOGON_LDAP_{URL|USER|PASSFILE} not specified; "
                      "getting empty contacts")
            return contacts_reader.get_contacts_data(None)
        elif self.comanage_data.should_update():
            try:
                idmap = self.get_cilogon_ldap_id_map()
                data = cilogon_ldap.cilogon_id_map_to_yaml_data(idmap)
                self.comanage_data.update(ContactsData(data))
            except Exception:
                if self.strict:
                    raise
                log.exception("Failed to update comanage data")
                self.comanage_data.try_again()

        return self.comanage_data.data
コード例 #9
0
def main(argv):
    parser = ArgumentParser()
    parser.add_argument("indir",
                        help="input dir for virtual-organizations data")
    parser.add_argument("outfile",
                        nargs='?',
                        default=None,
                        help="output file for vosummary")
    parser.add_argument("--contacts", help="contacts yaml file")
    args = parser.parse_args(argv[1:])

    contacts_data = None
    if args.contacts:
        contacts_data = get_contacts_data(args.contacts)
    xml = to_xml(
        get_vos_data(args.indir,
                     contacts_data=contacts_data).get_tree(authorized=True))
    if args.outfile:
        with open(args.outfile, "w") as fh:
            fh.write(xml)
    else:
        print(xml)