Merge branch 'master' of ssh://sapanb@git.planet-lab.org/git/plcapi
authorSapan Bhatia <gwsapan@gmail.com>
Tue, 26 Apr 2011 14:05:51 +0000 (10:05 -0400)
committerSapan Bhatia <gwsapan@gmail.com>
Tue, 26 Apr 2011 14:05:51 +0000 (10:05 -0400)
Makefile
PLC/API.py
PLC/Accessors/Accessors_standard.py
PLC/Methods/AddNode.py
PLC/Methods/GetSlivers.py
PLC/Methods/UpdateNode.py
PLC/Namespace.py
PLC/Peers.py
PLCAPI.spec
aspects/__init__.py
planetlab5.sql

index b71d8d3..fc7e48c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -83,7 +83,7 @@ ifeq (,$(SSHURL))
        @echo "  or   make sync PLCHOST=testplc.onelab.eu GUEST=vplc03.inria.fr"
        @exit 1
 else
-       +$(RSYNC) plcsh PLC planetlab5.sql migrations $(SSHURL)/usr/share/plc_api/
+       +$(RSYNC) plcsh PLC planetlab5.sql migrations aspects $(SSHURL)/usr/share/plc_api/
        +$(RSYNC) db-config.d/ $(SSHURL)/etc/planetlab/db-config.d/
        +$(RSYNC) plc.d/ $(SSHURL)/etc/plc.d/
        $(SSHCOMMAND) apachectl graceful
index 191720d..359e955 100644 (file)
@@ -7,6 +7,7 @@
 # Copyright (C) 2004-2006 The Trustees of Princeton University
 #
 
+import os
 import sys
 import traceback
 import string
@@ -147,6 +148,31 @@ class PLCAPI:
         if self.config.PLC_OMF_ENABLED:
             from aspects import apply_omf_aspect
             apply_omf_aspect()
+        
+        if self.config.PLC_RATELIMIT_ENABLED:
+            from aspects import apply_ratelimit_aspect
+            apply_ratelimit_aspect()
+
+
+        # Enable Caching. Only for GetSlivers for the moment.
+        # TODO: we may consider to do this in an aspect like the ones above.
+        try:
+            if self.config.PLC_GETSLIVERS_CACHE:
+                getslivers_cache = true
+        except AttributeError:
+            getslivers_cache = false
+
+        if getslivers_cache:
+            os.environ['DJANGO_SETTINGS_MODULE']='plc_django_settings'
+            from cache_utils.decorators import cached
+            from PLC.Methods.GetSlivers import GetSlivers
+
+            @cached(7200)
+            def cacheable_call(cls, auth, node_id_or_hostname):
+                return cls.raw_call(auth, node_id_or_hostname)
+            
+            GetSlivers.call = cacheable_call
+            
 
 
     def callable(self, method):
index 2c1e141..0867515 100644 (file)
@@ -25,8 +25,15 @@ current_module = sys.modules[__name__]
 define_accessors(current_module, Slice, "Vref", "vref",
                  "slice/config", "vserver reference image name",
                  set_roles=["admin","pi","user","node"], expose_in_api=True)
+# this contains the actual script text
+# if set, it supersedes 'initscript'
+define_accessors(current_module, Slice, "InitscriptCode","initscript_code",
+                 "slice/usertools", "Slice initialization script code",
+                 set_roles=["admin","pi","user"], expose_in_api=True)
+# this may contain a *name* that refers to the GetInitScripts
+# it was initially designed to share scripts among slices
 define_accessors(current_module, Slice, "Initscript","initscript",
-                 "slice/usertools", "Slice initialization script",
+                 "slice/usertools", "Slice initialization script name",
                  set_roles=["admin","pi","user"], expose_in_api=True)
 
 # BootManager might need to set any of these 3, so 'node' needs to be in set_roles
index a1e8337..fade827 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Peers import Peers
 from PLC.Sites import Site, Sites
 from PLC.Nodes import Node, Nodes
 from PLC.TagTypes import TagTypes
-from PLC.NodeTags import NodeTags
+from PLC.NodeTags import NodeTags, NodeTag
 from PLC.Methods.AddNodeTag import AddNodeTag
 from PLC.Methods.UpdateNodeTag import UpdateNodeTag
 
@@ -80,13 +80,22 @@ class AddNode(Method):
 
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
-            if not TagTypes(self.api,{'tagname':tagname}):
+            tag_types = TagTypes(self.api,{'tagname':tagname})
+            if not tag_types:
                 raise PLCInvalidArgument,"No such TagType %s"%tagname
+            tag_type = tag_types[0] 
             node_tags=NodeTags(self.api,{'tagname':tagname,'node_id':node['node_id']})
             if not node_tags:
-                AddNodeTag(self.api).__call__(auth,node['node_id'],tagname,value)
+                node_tag = NodeTag(self.api)
+                node_tag['node_id'] = node['node_id']
+                node_tag['tag_type_id'] = tag_type['tag_type_id']
+                node_tag['tagname']  = tagname
+                node_tag['value'] = value
+                node_tag.sync()
             else:
-                UpdateNodeTag(self.api).__call__(auth,node_tags[0]['node_tag_id'],value)
+                node_tag = node_tags[0]
+                node_tag['value'] = value
+                node_tag.sync() 
 
         self.event_objects = {'Site': [site['site_id']],
                               'Node': [node['node_id']]}
index 1f4bc12..45fcacb 100644 (file)
@@ -23,11 +23,6 @@ from PLC.PersonTags import PersonTag,PersonTags
 
 from PLC.Accessors.Accessors_standard import *
 
-# Caching
-import os
-os.environ['DJANGO_SETTINGS_MODULE']='plc_django_settings'
-from cache_utils.decorators import cached
-
 # XXX used to check if slice expiration time is sane
 MAXINT =  2L**31-1
 
@@ -211,20 +206,9 @@ class GetSlivers(Method):
     }
 
     def call(self, auth, node_id_or_hostname = None):
-        try:
-            cache_opt = self.api.config.PLC_GETSLIVERS_CACHE
-        with AttributeError:
-            cache_opt = False
-
-        if (cache_opt):
-            return self.cacheable_call(auth, node_id_or_hostname)
-        else:
-            return self.raw_call(auth, node_id_or_hostname)
-
-    @cached(7200)
-    def cacheable_call(self, auth, node_id_or_hostname):
         return self.raw_call(auth, node_id_or_hostname)
 
+
     def raw_call(self, auth, node_id_or_hostname):
         timestamp = int(time.time())
 
index a74db92..2927f73 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Peers import Peers
 from PLC.Sites import Sites
 from PLC.Nodes import Node, Nodes
 from PLC.TagTypes import TagTypes
-from PLC.NodeTags import NodeTags
+from PLC.NodeTags import NodeTags, NodeTag
 from PLC.Methods.AddNodeTag import AddNodeTag
 from PLC.Methods.UpdateNodeTag import UpdateNodeTag
 
@@ -102,10 +102,16 @@ class UpdateNode(Method):
                 raise PLCInvalidArgument,"No such TagType %s"%tagname
             node_tags=NodeTags(self.api,{'tagname':tagname,'node_id':node['node_id']})
             if not node_tags:
-                AddNodeTag(self.api).__call__(auth,node['node_id'],tagname,value)
+                node_tag = NodeTag(self.api)
+                node_tag['node_id'] = node['node_id']
+                node_tag['tag_type_id'] = tag_type['tag_type_id']
+                node_tag['tagname']  = tagname
+                node_tag['value'] = value
+                node_tag.sync()
             else:
-                UpdateNodeTag(self.api).__call__(auth,node_tags[0]['node_tag_id'],value)
-
+                node_tag = node_tags[0]
+                node_tag['value'] = value
+                node_tag.sync()
         # Logging variables
         self.event_objects = {'Node': [node['node_id']]}
         if 'hostname' in node:
index 1332ea2..d0ce9b8 100644 (file)
@@ -1,6 +1,3 @@
-### $Id: Namespace.py
-### $URL:
-
 URN_PREFIX = "urn:publicid:IDN"
 
 def get_leaf(hrn):
@@ -26,7 +23,7 @@ def hrn_to_pl_login_base(hrn):
 
 def hostname_to_hrn(auth_hrn, login_base, hostname):
     """
-    Convert hrn to plantelab name.
+    Convert hrn to planetlab name.
     """
     sfa_hostname = ".".join([auth_hrn, login_base, hostname.split(".")[0]])
     return sfa_hostname
index fb47b6e..1fa515a 100644 (file)
@@ -1,14 +1,14 @@
-# $Id$
-# $URL$
 #
 # Thierry Parmentelat - INRIA
 #
 
 import re
 from types import StringTypes
+import traceback
 from urlparse import urlparse
 
 import PLC.Auth
+from PLC.Debug import log
 from PLC.Faults import *
 from PLC.Namespace import hostname_to_hrn
 from PLC.Parameter import Parameter, Mixed
@@ -165,14 +165,19 @@ class Peer(Row):
              'peer_node_id': peer_node_id},
             commit = commit)
 
-        # attempt to manually update the 'hrn' tag
-        root_auth = self['hrn_root']
         sites = Sites(self.api, node['site_id'], ['login_base'])
         site = sites[0]
         login_base = site['login_base']
-        hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
-        tags = {'hrn': hrn}
-        Node(self.api, node).update_tags(tags)
+        try:
+            # attempt to manually update the 'hrn' tag with the remote prefix
+            hrn_root = self['hrn_root']
+            hrn = hostname_to_hrn(hrn_root, login_base, node['hostname'])
+            tags = {'hrn': hrn}
+            Node(self.api, node).update_tags(tags)
+        except:
+            print >>log, "WARNING: (beg) could not find out hrn on hostname=%s"%node['hostname']
+            traceback.print_exc(5,log)
+            print >>log, "WARNING: (end) could not find out hrn on hostname=%s"%node['hostname']
 
     def remove_node(self, node, commit = True):
         """
@@ -181,7 +186,7 @@ class Peer(Row):
 
         remove = Row.remove_object(Node, 'peer_node')
         remove(self, node, commit)
-        # attempt to manually update the 'hrn' tag
+        # attempt to manually update the 'hrn' tag now that the node is local
         root_auth = self.api.config.PLC_HRN_ROOT
         sites = Sites(self.api, node['site_id'], ['login_base'])
         site = sites[0]
index b9a230a..6b25c1f 100644 (file)
@@ -1,6 +1,6 @@
 %define name PLCAPI
 %define version 5.0
-%define taglevel 30
+%define taglevel 32
 
 %define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 
@@ -145,6 +145,12 @@ rm -rf $RPM_BUILD_ROOT
 
 
 %changelog
+* Tue Mar 22 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - plcapi-5.0-32
+- rename initscript_body into initscript_code
+
+* Mon Mar 21 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - plcapi-5.0-31
+- new initscript_body tag
+
 * Wed Mar 09 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - plcapi-5.0-30
 - working draft for GetSliceSshKeys
 
index cdab6d6..aa7b05c 100644 (file)
@@ -7,6 +7,8 @@ from aspects.ratelimitaspects import RateLimitAspect
 def apply_omf_aspect():
     # track all PLC methods to add OMF hooks
     weave_class_method(OMFAspect(), Method, "__call__")
+
+def apply_ratelimit_aspect():
     weave_class_method(RateLimitAspect(), Method, "__call__")
 
 def apply_debugger_aspect():
index 4083039..95eb02b 100644 (file)
@@ -840,7 +840,7 @@ CREATE TABLE initscripts (
     initscript_id serial PRIMARY KEY,                  -- Initscript identifier
     name text NOT NULL,                                        -- Initscript name
     enabled bool NOT NULL DEFAULT true,                        -- Initscript is active
-    script text NOT NULL,                              -- Initscript body
+    script text NOT NULL,                              -- Initscript code
     UNIQUE (name)
 ) WITH OIDS;
 CREATE INDEX initscripts_name_idx ON initscripts (name);