Пример #1
0
def main():
    init_options()
    Shell.init_options()

    # This should be taken care of by argparse...

    if Options().method in [METHOD_APPEND, METHOD_INSERT]:
        if not Options().target:
            print "manifold-tables: error: argument -j/--jump is required"
            sys.exit(0)

        # Build rule dictionary
        rule = Rule()
        rule.object = Options().object
        fields = [x.strip() for x in Options().fields.split(',')]
        rule.fields = set(fields)
        rule.access = Options().access
        rule.target = Options().target
        rule_dict = rule.to_dict()

    shell = Shell()

    if Options().method == METHOD_APPEND:
        shell.evaluate("insert into local:policy SET policy_json = '%s'" %
                       json.dumps(rule_dict))

    elif Options().method == METHOD_FLUSH:
        shell.evaluate("delete from local:policy")

    else:
        raise Exception, "Not implemented"

    shell.terminate()
Пример #2
0
def main():
    argc = len(sys.argv)
    if argc not in [2, 3]:
        usage()
        sys.exit(1)

    name = sys.argv[2] if argc == 3 else 'local'

    Shell.init_options()
    shell = Shell(interactive=False)
    command = 'SELECT table, column.name FROM %(name)s:object' % locals()
    objects = shell.evaluate(command % locals())
    shell.terminate()

    f = open(sys.argv[1], 'w')
    print >> f, metadata_to_graphviz(objects['value'])
    f.close()
Пример #3
0
def main():
    argc = len(sys.argv)
    if argc != 2:
        usage()
        sys.exit(1)
    name = sys.argv[1]

    Shell.init_options()
    shell = Shell(interactive=False)

    command = 'UPDATE local:platform SET disabled = False WHERE platform == "%(name)s"'
    shell.evaluate(command % locals())

    # Equivalent using a query object...
    #
    # from manifold.core.query import Query
    # platform_filters = [['platform', '=', name]]
    # platform_params = {'disabled': False}
    # query = Query(action='update', object='local:platform', filters=platform_filters, params=platform_params)
    # shell.execute(query)

    shell.terminate()
Пример #4
0
LIST_RESOURCES        = 'SELECT hrn FROM resource'
LIST_LEASES           = 'SELECT resource, start_time, end_time, duration FROM lease'
LIST_SLICE_RESOURCES  = 'SELECT hrn FROM resource WHERE slice == "%s"' % (SLICE_HRN, )
LIST_SLICE_LEASES     = 'SELECT resource, start_time, end_time, duration FROM lease WHERE slice == "%s"' % (SLICE_HRN, )

# sfa/iotlab/iotlabshell.py:    _MINIMUM_DURATION = 10  # 10 units of granularity 60 s, 10 mins
# 1800 too much !!!!
ADD_LEASE             = 'UPDATE slice SET resource = ["%s"], lease = [{resource: "%s", start_time: %d, duration: 10}] where slice_hrn == "%s"' % (IOTLAB_NODE_1, IOTLAB_NODE_1, START, SLICE_HRN, )


################################################################################

def run_command(command):
   s.display(s.evaluate(command))

################################################################################

s = Shell(interactive=False)
s.select_auth_method('local')

#run_command(LIST_RESOURCES)
run_command(LIST_LEASES) # Possibility to have a hardcoded value
#run_command(LIST_SLICE_RESOURCES)
#run_command(LIST_SLICE_LEASES)

# Lease is not display at the end when the command succeeds
#run_command(ADD_LEASE)

s.terminate()
Пример #5
0
    print type(result_value)
    if isinstance(result_value, dict):
        return result_value['value']
    assert isinstance(result_value, ResultValue)
    assert result_value.is_success()
    records = result_value.get_value()
    #assert isinstance(records, Records) # ONLY IN ROUTERV2
    return records


#Options().log_level = 'DEBUG'
Options().username = auth['Username']
Options().password = auth['AuthString']
Options().xmlrpc_url = "https://portal.onelab.eu:7080"

shell = Shell(interactive=False)
shell.select_auth_method('password')

command = 'SELECT hrn, hostname FROM resource'
result_value = shell.evaluate(command)
try:
    records = assert_rv_success(result_value)
    print "===== RESULTS ====="
    print records

except Exception, e:
    print "===== ERROR ====="
    import traceback
    traceback.print_exc()
    print e
Пример #6
0
 def setUpClass(self):
     # TODO Enable NITOS Only
     self._shell = Shell(interactive=False)
     self._shell.select_auth_method('local')
Пример #7
0
class TestbedWithReservationTestCase(ManifoldTestCase):
    @classmethod
    def setUpClass(self):
        # TODO Enable NITOS Only
        self._shell = Shell(interactive=False)
        self._shell.select_auth_method('local')

    @classmethod
    def tearDownClass(self):
        self._shell.terminate()

    def _run(self, command):
        result_value = self._shell.evaluate(command)
        records = self.assert_rv_success(result_value)
        return records

    def test_list_resources(self):
        """
        List all the resources from the testbed
        """
        Q = 'SELECT hrn, type FROM %sresource' % (self.NAMESPACE, )
        records = self._run(Q)

        # Let's check we have the requested fields (this should not be part of this test ?)
        assert len(records) > 0
        first_record = records[0]
        assert set(first_record.keys()) == {'hrn', 'type'}

        return records

    def test_list_leases(self):
        """
        List all the leases from the testbed
        """
        Q = 'SELECT resource, start_time, end_time FROM %slease' % (
            self.NAMESPACE, )
        records = self._run(Q)

        # We might count the leases, add one, and check that we have one more...

    def test_list_slice_resources(self):
        Q = 'SELECT hrn FROM %sresource WHERE slice == "%s"' % (
            self.NAMESPACE,
            self.SLICE_URN,
        )
        records = self._run(Q)

    def test_list_slice_leases(self):
        Q = 'SELECT resource, start_time, end_time FROM %slease WHERE slice == "%s"' % (
            self.NAMESPACE,
            self.SLICE_URN,
        )
        records = self._run(Q)

    def test_add_lease(self):
        """
        Add a lease to the slice by adding both a sliver to the node, and a lease.

        KNOWN BUGS:
        - If in metadata we don't have resource[] and lease[], which we handle
          artificially in the code, then the query plan becomes very complex,
          and has wrong rename in the path. For example it finds resource in
          lease.resource, which is true in fact, and renames it to resource.urn
          to find this default field...
        - Need to reproduce... when adding a second lease
          [Failure instance: Traceback (failure with no frames): <type
          'exceptions.ValueError'>: Error in SFA Proxy [Failure instance:
          Traceback: <class 'xmlrpclib.Fault'>: <Fault 2: "Uncaught exception
          Cannot lease 'omf.nitos.node037', because it is unavailable for the
          requested time. in method CreateSliver">
        """
        Q = 'UPDATE %sslice SET resource = ["%s"], lease = [{resource: "%s", start_time: "%s", end_time: "%s"}] where slice_hrn == "%s"' % (
            self.NAMESPACE,
            self.NODE_1,
            self.NODE_1,
            self.START,
            self.END,
            self.SLICE_HRN,
        )
        records = self._run(Q)

    def test_add_two_leases(self):
        """
        Same resource twice, not in resources (no need here).
        """
        Q = 'UPDATE %sslice SET resource = ["%s"], lease = [{resource: "%s", start_time: "%s", end_time: "%s"}, {resource: "%s", start_time: "%s", end_time: "%s"}] where slice_hrn == "%s"' % (
            self.NAMESPACE,
            self.NODE_1,
            self.NODE_1,
            self.START,
            self.END,
            self.NODE_1,
            self.START + 3600,
            self.END + 3600,
            self.SLICE_HRN,
        )
        records = self._run(Q)

    def test_add_two_leases_2(self):
        """
        Different resources, one is not in resources.
        """
        Q = 'UPDATE %sslice SET resource = ["%s"], lease = [{resource: "%s", start_time: "%s", end_time: "%s"}, {resource: "%s", start_time: "%s", end_time: "%s"}] where slice_hrn == "%s"' % (
            self.NAMESPACE,
            self.NODE_1,
            self.NODE_1,
            self.START,
            self.END,
            self.NODE_2,
            self.START + 3600,
            self.END + 3600,
            self.SLICE_HRN,
        )
        records = self._run(Q)

    def test_add_two_leases_3(self):
        """
        Different resources, both in resources.
        """
        Q = 'UPDATE %sslice SET resource = ["%s", "%s"], lease = [{resource: "%s", start_time: "%s", end_time: "%s"}, {resource: "%s", start_time: "%s", end_time: "%s"}] where slice_hrn == "%s"' % (
            self.NAMESPACE,
            self.NODE_1,
            self.NODE_2,
            self.NODE_1,
            self.START,
            self.END,
            self.NODE_2,
            self.START + 3600,
            self.END + 3600,
            self.SLICE_HRN,
        )
        records = self._run(Q)

    def test_clear_slice(self):
        Q = 'UPDATE %sslice SET resource = [], lease = [] where slice_hrn == "%s"' % (
            self.NAMESPACE,
            self.SLICE_HRN,
        )
        records = self._run(Q)

        assert len(records) == 1
        first_record = records[0]

        # XXX What shall we expect
        EXPECTED_FIELDS = {'slice_hrn', 'slice_urn', 'resource', 'lease'}
        assert set(first_record.keys(
        )) == EXPECTED_FIELDS, "Record has keys: %r. Expected: %r" % (
            first_record.keys(), EXPECTED_FIELDS)

        assert len(first_record['resource']) == 0
        assert len(first_record['lease']) == 0