You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/01/23 15:06:49 UTC

[2/3] marvin: factories for each api entity

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1abf48d6/tools/marvin/marvin/integration/lib/factory/__init__.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/factory/__init__.py b/tools/marvin/marvin/integration/lib/factory/__init__.py
new file mode 100644
index 0000000..287f9b1
--- /dev/null
+++ b/tools/marvin/marvin/integration/lib/factory/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1abf48d6/tools/marvin/marvin/integration/lib/generateBase.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/generateBase.py b/tools/marvin/marvin/integration/lib/generateBase.py
index 2f603ee..8b4bfd8 100644
--- a/tools/marvin/marvin/integration/lib/generateBase.py
+++ b/tools/marvin/marvin/integration/lib/generateBase.py
@@ -17,6 +17,7 @@
 
 import marvin
 from marvin.cloudstackAPI import *
+import os
 
 # Add verbs in grammar - same as cloudmonkey
 grammar = ['create', 'list', 'delete', 'update',
@@ -28,6 +29,9 @@ grammar = ['create', 'list', 'delete', 'update',
            'copy', 'extract', 'migrate', 'restore', 'suspend',
            'get', 'query', 'prepare', 'deploy', 'upload', 'lock', 'disassociate']
 
+aslv2 = ""
+
+
 def get_api_cmds():
     api_classes = __import__('marvin.cloudstackAPI')
 
@@ -86,15 +90,19 @@ def get_actionable_entities():
 def write_entity_classes(entities):
     tabspace = '    '
     classlist = []
+    #TODO: Add license header for ASLv2
     code = ''
     for entity, actions in entities.iteritems():
         code += 'class %s:'%entity
         for action, args in actions.iteritems():
             code += '\n\n'
             code += tabspace
-            code += 'def %s(self, apiclient, %sFactory=None'%(action, entity)
+            if action.startswith('create'):
+                code += 'def %s(self, apiclient, %sFactory'%(action, entity)
+            else:
+                code += 'def %s(self, apiclient'%(action)
             if len(args[0]) > 0:
-                code += ', ' + ', '.join(args[0])
+                code += ', ' + ', '.join(list(set(args[0])))
             if len(args[1]) > 0:
                 code += ', **kwargs):\n'
             else:
@@ -103,8 +111,32 @@ def write_entity_classes(entities):
             code += 'pass'
         code += '\n\n'
         classlist.append(code)
+        write_entity_factory(entity, actions)
     return list(set(classlist))
 
+def write_entity_factory(entity, actions):
+    tabspace = '    '
+    #TODO: Add license header for ASLv2
+    code = ''
+    if 'create' not in actions:
+        return
+    factory_defaults = actions['create']
+    if os.path.exists("./factory/%sFactory.py"%entity):
+        for arg in factory_defaults[0]:
+            code += tabspace + '%s = None\n'%arg
+        with open("./factory/%sFactory.py"%entity, "a") as writer:
+            writer.write(code)
+    else:
+        code += 'import factory\n'
+        code += 'from marvin.integration.lib.newbase import %s\n'%entity
+        code += 'class %sFactory(factory.Factory):'%entity
+        code += '\n\n'
+        code += tabspace + 'FACTORY_FOR = %s\n\n'%entity
+        for arg in factory_defaults[0]:
+            code += tabspace + '%s = None\n'%arg
+        with open("./factory/%sFactory.py"%entity, "w") as writer:
+            writer.write(code)
+
 if __name__=='__main__':
     entities = get_actionable_entities()
     clslist = write_entity_classes(entities)