Exemple #1
0
 def handle(self, *args, **options):
     (options, args) = parser.parse_args() 
     file_path = os.path.abspath(options.iplist)
     ip_list = open(file_path)
     for ip in ip_list:
         #print ip,
         ip = ip.strip('\n')
         h = Host(name=options.name, ip_in=ip, ip_out=options.ip_out, model=options.model, image=options.image, cloudandservice_id=options.cloudandservice, service_id=options.service, type=options.type, status=options.status)
         #h = Host(name=options.name, ip_in=ip,  internetdatacenter_id=options.internetdatacenter, service_id=options.service, type=options.type, status=options.status)
         h.save()     
 def handle(self, namespace):
     origin = getOrigin(namespace.origin)
     for host in namespace.host:
         host = host.lower()
         if self.checkHost(host):
             raise HostinfoException("Host %s already exists" % host)
         if host[0] in ('-',):
             raise HostinfoException(
                 "Host begins with a forbidden character ('%s') - not adding" % host[0])
         hobj = Host(hostname=host, origin=origin)
         hobj.save()
     return None, 0
 def handle(self, namespace):
     origin = getOrigin(namespace.origin)
     for host in namespace.host:
         host = host.lower()
         if self.checkHost(host):
             raise HostinfoException("Host %s already exists" % host)
         if host[0] in ('-', ):
             raise HostinfoException(
                 "Host begins with a forbidden character ('%s') - not adding"
                 % host[0])
         hobj = Host(hostname=host, origin=origin)
         hobj.save()
     return None, 0
Exemple #4
0
 def handle(self, *args, **options):
     (options, args) = parser.parse_args()
     file_path = os.path.abspath(options.iplist)
     ip_list = open(file_path)
     for ip in ip_list:
         #print ip,
         ip = ip.strip('\n')
         h = Host(name=options.name,
                  ip_in=ip,
                  ip_out=options.ip_out,
                  internetdatacenter_id=options.internetdatacenter,
                  service_id=options.service,
                  type=options.type,
                  status=options.status)
         #h = Host(name=options.name, ip_in=ip,  internetdatacenter_id=options.internetdatacenter, service_id=options.service, type=options.type, status=options.status)
         h.save()
         h.hostcomment_set.create(comment=options.comment)
Exemple #5
0
 def handle(self, *args, **options):
     (options, args) = parser.parse_args()
     file_path = os.path.abspath(options.iplist)
     ip_list = open(file_path)
     for ip in ip_list:
         #print ip,
         ip = ip.strip('\n')
         h = Host(name=options.name,
                  ip_in=ip,
                  ip_out=options.ip_out,
                  model=options.model,
                  image=options.image,
                  cloudandservice_id=options.cloudandservice,
                  service_id=options.service,
                  type=options.type,
                  status=options.status)
         #h = Host(name=options.name, ip_in=ip,  internetdatacenter_id=options.internetdatacenter, service_id=options.service, type=options.type, status=options.status)
         h.save()
 def handle(self, *args, **options):
     (options, args) = parser.parse_args()
     file_path = os.path.abspath(options.iplist)
     ip_list = open(file_path)
     for ip in ip_list:
         # print ip,
         ip = ip.strip("\n")
         h = Host(
             name=options.name,
             ip_in=ip,
             ip_out=options.ip_out,
             internetdatacenter_id=options.internetdatacenter,
             service_id=options.service,
             type=options.type,
             status=options.status,
         )
         # h = Host(name=options.name, ip_in=ip,  internetdatacenter_id=options.internetdatacenter, service_id=options.service, type=options.type, status=options.status)
         h.save()
         h.hostcomment_set.create(comment=options.comment)
    def handleHost(self, hosttree):
        """
        We can't load dates (created/modified) of elements because these are
        set automatically by Django

          <host docpage="None"  origin="explorer2hostinfo.py by w86765"  modified="2008-03-20" created="2008-03-20" >
            <hostname>zone_161.117.101.190</hostname>
            <data>
              <confitem key="os" origin="w86765" modified="2008-08-19" created="2008-08-19">solaris</confitem>
              <confitem key="type" origin="..." modified="2008-07-02" created="2008-03-20">virtual</confitem>
              <confitem key="virtualmaster" origin="..." modified="2008-03-20" created="2008-03-20">idmsvrqv01d</confitem>
              <confitem key="zonename" origin="..." modified="2008-03-20" created="2008-03-20">app04</confitem>
            </data>
          </host>
        """
        hostname = hosttree.find('hostname').text
        self.verbose(hostname)
        try:
            host = Host.objects.get(hostname=hostname)
        except ObjectDoesNotExist:
            host = Host(hostname=hostname,
                        docpage=hosttree.attrib.get('docpage', None),
                        origin=hosttree.attrib.get('origin',
                                                   'unknown - import'))
            self.verbose("New host %s" % repr(host))
            if not self.namespace.kiddingFlag:
                host.save()

        for data in hosttree.find('data').findall('confitem'):
            key = data.attrib['key']
            if 'origin' in data.attrib:
                origin = data.attrib['origin']
            else:
                origin = 'unknown'
            value = data.text
            try:
                self.handleValue(host, key, origin, value)
            except RestrictedValueException:
                sys.stderr.write(
                    "Trying to change a restricted value: %s:%s=%s - ignoring\n"
                    % (hostname, key, value))
    def handleHost(self, hosttree):
        """
        We can't load dates (created/modified) of elements because these are
        set automatically by Django

          <host docpage="None"  origin="explorer2hostinfo.py by w86765"  modified="2008-03-20" created="2008-03-20" >
            <hostname>zone_161.117.101.190</hostname>
            <data>
              <confitem key="os" origin="w86765" modified="2008-08-19" created="2008-08-19">solaris</confitem>
              <confitem key="type" origin="..." modified="2008-07-02" created="2008-03-20">virtual</confitem>
              <confitem key="virtualmaster" origin="..." modified="2008-03-20" created="2008-03-20">idmsvrqv01d</confitem>
              <confitem key="zonename" origin="..." modified="2008-03-20" created="2008-03-20">app04</confitem>
            </data>
          </host>
        """
        hostname = hosttree.find('hostname').text
        self.verbose(hostname)
        try:
            host = Host.objects.get(hostname=hostname)
        except ObjectDoesNotExist:
            host = Host(
                hostname=hostname,
                docpage=hosttree.attrib.get('docpage', None),
                origin=hosttree.attrib.get('origin', 'unknown - import')
                )
            self.verbose("New host %s" % repr(host))
            if not self.namespace.kiddingFlag:
                host.save()

        for data in hosttree.find('data').findall('confitem'):
            key = data.attrib['key']
            if 'origin' in data.attrib:
                origin = data.attrib['origin']
            else:
                origin = 'unknown'
            value = data.text
            try:
                self.handleValue(host, key, origin, value)
            except RestrictedValueException:
                sys.stderr.write("Trying to change a restricted value: %s:%s=%s - ignoring\n" % (hostname, key, value))