Example #1
0
    def listRecords(cls, token, args):
        domainList = DomainList(token)
        records = []
        if args.domains:
            for nameOrDomainid in args.domains:
                domainId = domainList.toDomainid(nameOrDomainid)
                if domainId:
                    recordList = RecordList(token, domainId)
                    records.extend(recordList)
        else:
            for domain in domainList:
                recordList = RecordList(token, domain.domainId)
                records.extend(recordList)

        # Header
        if args.verbose:
            yield [
                'ID', 'DomainID', 'Name', 'Type', 'TTL', 'Data', 'Description',
                'CreatedAt'
            ]
        else:
            yield ['Name', 'Type', 'TTL', 'Data']
        # Body
        for record in sorted(records,
                             key=lambda x: (x.domainId, x.name, x.type)):
            if args.verbose:
                yield [
                    record.recordId, record.domainId, record.name, record.type,
                    record.ttl, record.data, record.description,
                    record.created_at
                ]
            else:
                yield [record.name, record.type, record.ttl, record.data]
Example #2
0
    def updateRecord(cls, token, args):
        domainList = DomainList(token)
        recordList = None
        if args.domain:
            domainId = domainList.toDomainid(args.domain)
            if domainId:
                recordList = RecordList(token, domainId)
            else:
                raise error.NotFound('domain', args.domain)
        else:
            for domain in domainList:
                recordList = RecordList(token, domain.domainId)
                record = recordList.getRecord(args.record_id)
                if record:
                    break
            else:
                raise error.NotFound('record', args.record_id)

        recordList.update(args.record_id,
                          name=args.name,
                          type=args.type,
                          data=args.data,
                          priority=args.priority,
                          ttl=args.ttl,
                          description=args.description,
                          gslb=args.gslb)
Example #3
0
 def updateDomain(cls, token, args):
     domainList = DomainList(token)
     domainList.update(args.name,
                       email=args.email,
                       ttl=args.ttl,
                       description=args.description,
                       gslb=args.gslb)
Example #4
0
 def addDomain(cls, token, args):
     domainList = DomainList(token)
     domain = domainList.add(args.name,
                             args.email,
                             ttl=args.ttl,
                             description=args.description,
                             gslb=args.gslb)
     if not args.quiet:
         yield ['ID']
         yield [domain.domainId]
Example #5
0
 def deleteRecord(cls, token, args):
     domainList = DomainList(token)
     for domain in domainList:
         recordList = RecordList(token, domain.domainId)
         record = recordList.getRecord(args.record_id)
         if record:
             recordList.delete(record.recordId)
             return
     else:
         raise error.NotFound('record', args.record_id)
Example #6
0
    def addRecord(cls, token, args):
        domainList = DomainList(token)
        domainId = domainList.toDomainid(args.domain)
        if args.type != 'CNAME':
            args.name = domainList.toName(domainId)  # ドメイン名以外は受け付けないので
        if not domainId:
            raise error.NotFound('domain', args.domain)

        recordList = RecordList(token, domainId)
        record = recordList.add(
            name=args.name,
            type=args.type,
            data=args.data,
            priority=args.priority,
            ttl=args.ttl,
            description=args.description,
        )
        if not args.quiet:
            yield ['ID']
            yield [record.recordId]
Example #7
0
    def listDomains(cls, token, args):
        domainList = DomainList(token)

        # Header
        if args.verbose:
            yield [
                'ID', 'Name', 'TTL', 'Email', 'Serial', 'GSLB', 'Description',
                'CreatedAt'
            ]
        else:
            yield ['Name', 'TTL', 'CreatedAt']
        # Body
        for domain in domainList:
            if args.verbose:
                yield [
                    domain.domainId, domain.name, domain.ttl, domain.email,
                    domain.serial, domain.gslb, domain.description,
                    domain.created_at
                ]
            else:
                yield [domain.name, domain.ttl, domain.created_at]
Example #8
0
 def deleteDomain(cls, token, args):
     domainList = DomainList(token)
     domainList.delete(args.domain)