예제 #1
0
    def test_parse_iso_time(self):
        secs = timestamp.parse_iso_time(self.SOME_TIMESTAMP)
        self.failUnlessEqual(secs, self.SOME_TIME)

        secs2 = timestamp.parse_iso_time(self.SOME_TIMESTAMP2)
        self.failUnlessEqual(secs2, self.SOME_TIME)

        self.failUnlessRaises(ValueError, timestamp.parse_iso_time, "2012-00-00T00:00:00Z")
        self.failUnlessRaises(ValueError, timestamp.parse_iso_time, "not a timestamp")
예제 #2
0
    def test_parse_iso_time(self):
        secs = timestamp.parse_iso_time(self.SOME_TIMESTAMP)
        self.failUnlessEqual(secs, self.SOME_TIME)

        secs2 = timestamp.parse_iso_time(self.SOME_TIMESTAMP2)
        self.failUnlessEqual(secs2, self.SOME_TIME)

        self.failUnlessRaises(ValueError, timestamp.parse_iso_time,
                              "2012-00-00T00:00:00Z")
        self.failUnlessRaises(ValueError, timestamp.parse_iso_time,
                              "not a timestamp")
예제 #3
0
def compare_servers_to_local(remotepropstuplelist, localstate, stdout, stderr, now=None):
    if now is None:
        now = time.time()
    running_list = []
    for (rpt_launch_time, rpt_instance_id, rpt_host, rpt_status) in remotepropstuplelist:
        rpt_publichost = pubIPextractor(rpt_host)
        rpt_publichost_s = rpt_publichost or '<no public IP>'

        if not localstate.has_key(rpt_instance_id):
            # unknown instance
            launch_time = parse_iso_time(rpt_launch_time)
            if now - launch_time < 10*60:
                print >>stdout, ("Note: Ignoring unknown %s instance %s at %s because it was launched less than 10 minutes ago at %s."
                                 % (rpt_status, rpt_instance_id, rpt_publichost_s, rpt_launch_time))
            else:
                print >>stderr, ("Warning: The %s instance %s at %s launched at %s is not in the list of known servers."
                                 % (rpt_status, rpt_instance_id, rpt_publichost_s, rpt_launch_time))

                if rpt_status == 'running' and rpt_publichost:
                    running_list.append(rpt_publichost)
        else:
            # known instance
            (launch_time, publichost, status) = localstate[rpt_instance_id]
            if status == 'ignore' or (status == 'not_running' and rpt_status != 'running'):
                print >>stdout, ("Note: Ignoring %s instance %s at %s launched at %s."
                                 % (rpt_status, rpt_instance_id, rpt_publichost_s, rpt_launch_time))
            else:
                if rpt_status == 'running' and rpt_publichost:
                    running_list.append(rpt_publichost)

                if publichost != rpt_publichost:
                    print >>stderr, ("Warning: The %s instance %s launched at %s changed public IP from %s to %s."
                                     % (rpt_status, rpt_instance_id, rpt_launch_time, publichost, rpt_publichost_s))

                if launch_time != rpt_launch_time:
                    print >>stderr, ("Warning: The %s instance %s at %s changed launch time from %s to %s (probably restarted)."
                                     % (rpt_status, rpt_instance_id, rpt_publichost_s, launch_time, rpt_launch_time))

                if status != rpt_status:
                    print >>stderr, ("Warning: The %s instance %s at %s launched at %s was expected to be %s."
                                     % (rpt_status, rpt_instance_id, rpt_publichost_s, rpt_launch_time, status))
            del localstate[rpt_instance_id]

    printed_heading = False
    for key in localstate:
        (s_launch_time, s_publichost, s_status) = localstate[key]
        if s_status not in ('ignore', 'not_running'):
            if not printed_heading:
                print >>stderr
                print >>stderr, "The following known servers were not found by the AWS query:"
                printed_heading = True

            print >>stderr, ("Instance ID: %s  Public IP: %-15s  Launch time: %s  Expected status: %s"
                             % (key, s_publichost, s_launch_time, s_status))

    if printed_heading:
        print >>stderr

    return running_list
예제 #4
0
def compare_servers_to_local(remotepropstuplelist,
                             localstate,
                             stdout,
                             stderr,
                             now=None):
    if now is None:
        now = time.time()
    running_list = []
    for (rpt_launch_time, rpt_instance_id, rpt_host,
         rpt_status) in remotepropstuplelist:
        rpt_publichost = pubIPextractor(rpt_host)
        rpt_publichost_s = rpt_publichost or '<no public IP>'

        if not localstate.has_key(rpt_instance_id):
            # unknown instance
            launch_time = parse_iso_time(rpt_launch_time)
            if now - launch_time < 10 * 60:
                print >> stdout, (
                    "Note: Ignoring unknown %s instance %s at %s because it was launched less than 10 minutes ago at %s."
                    % (rpt_status, rpt_instance_id, rpt_publichost_s,
                       rpt_launch_time))
            elif rpt_status == 'terminated':
                print >> stdout, (
                    "Note: Ignoring %s instance %s at %s launched at %s." %
                    (rpt_status, rpt_instance_id, rpt_publichost_s,
                     rpt_launch_time))
            else:
                print >> stderr, (
                    "Warning: The %s instance %s at %s launched at %s is not in the list of known servers."
                    % (rpt_status, rpt_instance_id, rpt_publichost_s,
                       rpt_launch_time))

                if rpt_status == 'running' and rpt_publichost:
                    running_list.append(rpt_publichost)
        else:
            # known instance
            (launch_time, publichost, status) = localstate[rpt_instance_id]
            if status == 'ignore' or (status == 'not_running'
                                      and rpt_status != 'running'):
                print >> stdout, (
                    "Note: Ignoring %s instance %s at %s launched at %s." %
                    (rpt_status, rpt_instance_id, rpt_publichost_s,
                     rpt_launch_time))
            else:
                if rpt_status == 'running' and rpt_publichost:
                    running_list.append(rpt_publichost)

                if publichost != rpt_publichost:
                    print >> stderr, (
                        "Warning: The %s instance %s launched at %s changed public IP from %s to %s."
                        % (rpt_status, rpt_instance_id, rpt_launch_time,
                           publichost, rpt_publichost_s))

                if launch_time != rpt_launch_time:
                    print >> stderr, (
                        "Warning: The %s instance %s at %s changed launch time from %s to %s (probably restarted)."
                        % (rpt_status, rpt_instance_id, rpt_publichost_s,
                           launch_time, rpt_launch_time))

                if status != rpt_status:
                    print >> stderr, (
                        "Warning: The %s instance %s at %s launched at %s was expected to be %s."
                        % (rpt_status, rpt_instance_id, rpt_publichost_s,
                           rpt_launch_time, status))
            del localstate[rpt_instance_id]

    printed_heading = False
    for key in localstate:
        (s_launch_time, s_publichost, s_status) = localstate[key]
        if s_status not in ('ignore', 'not_running'):
            if not printed_heading:
                print >> stderr
                print >> stderr, "The following known servers were not found by the AWS query:"
                printed_heading = True

            print >> stderr, (
                "Instance ID: %s  Public IP: %-15s  Launch time: %s  Expected status: %s"
                % (key, s_publichost, s_launch_time, s_status))

    if printed_heading:
        print >> stderr

    return running_list