Ejemplo n.º 1
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     try:
         return import_string("pyvisdk.mo.{}.{}".format(
             camel_to_under(class_name), class_name))
     except ImportError:
         raise ValueError(class_name)
 def save_data_modules_to_disk(self):
     from pyvisdk.utils import camel_to_under
     self._write_data_object_types_file()
     for name, content in self.generate_data_type_modules().items():
         with open(
                 join(DATA_MODULES_DIR,
                      '{}.py'.format(camel_to_under(name))), 'w') as fd:
             fd.write(content)
Ejemplo n.º 3
0
 def _create_do_obj(self, class_name, obj_content, parent):
     mod_name = 'pyvisdk.do.%s' % camel_to_under(class_name)
     importlib.import_module(mod_name)
     do = eval('%s.%s' % (mod_name, class_name))
         
     kwargs = {}
     for attr_name in filter(lambda x: not x.startswith('_'), dir(obj_content)):
         attr_data = eval('obj_content.%s' % attr_name)
         kwargs[attr_name] = self._parse_object_content(attr_data, parent=do)
         
     rv = do(self, **kwargs)
     return rv
Ejemplo n.º 4
0
def import_handler(name):
    from pyvisdk.utils import camel_to_under
    from brownie.importing import import_string
    return import_string('{}.ha_cli_handler_{}.{}'.format(__name__, camel_to_under(name), name))
Ejemplo n.º 5
0
def import_handler(name):
    from pyvisdk.utils import camel_to_under
    from brownie.importing import import_string
    return import_string('{}.ha_cli_handler_{}.{}'.format(
        __name__, camel_to_under(name), name))
Ejemplo n.º 6
0
 def _parse_object_content(self, obj_content, parent=None):
     rv = None
     class_name = obj_content.__class__.__name__
     class_name_upper = class_name[0].upper()+class_name[1:]
     if isinstance(obj_content, list):
         rv = []
         for obj in obj_content:
             rv.append( self._parse_object_content(obj, parent) )
     
     elif type(obj_content) == types.NoneType:
         return obj_content
     
     elif issubclass(obj_content.__class__, pyvisdk.base.base_entity.BaseEntity):
         rv = obj_content
         
     elif class_name == 'ObjectContent':
         # create the managed object
         if not parent:
             rv = self._create_mo_obj(class_name, obj_content, parent)
         else:
             rv = []
             # now, run through the propSet
             if hasattr(obj_content, "propSet"):
                 for prop in obj_content.propSet:
                     rv.append(self._parse_object_content(prop.val))
             if len(rv) == 1:
                 rv = rv[0]
             
     elif class_name == "ManagedObjectReference":
         # managed object reference is too generic, so we get to the real type
         mo_f = eval('pyvisdk.mo.%s' % obj_content._type)
         rv = mo_f(self, ref=obj_content)
         
     elif class_name in DataObjectTypes:
         rv = self._create_do_obj(class_name, obj_content, parent)
         
     elif class_name == 'Text':
         rv = str(obj_content)
         
     elif class_name in ['long', 'bool', 'int', 'datetime', 'str']:
         return obj_content
    
     elif "ArrayOf" in class_name:
         rv = []
         _type = class_name[7:]
         _list = getattr(obj_content, _type)
         for obj in _list:
             rv.append( self._parse_object_content(obj, parent) )
             
     elif hasattr(obj_content, 'value') and hasattr(obj_content, '_type'):
         name = obj_content._type
         mod_name = 'pyvisdk.mo.%s' % camel_to_under(name)
         importlib.import_module(mod_name)
         mo = eval('%s.%s' % (mod_name, name))
         rv = mo(self, ref=obj_content)
         
     # TODO: ArrayOf....  ArrayOfManagedObjectReference ArrayOfAlarmState ArrayOfString ArrayOfInt ArrayOfPermission
     # TODO: val datetime datastore  entity host vm key
    
     elif class_name_upper in DataObjectTypes:
         rv = self._create_do_obj(class_name_upper, obj_content, parent)
         
     #elif class_name_upper in ManagedObjectTypes:
     #    rv = self._create_mo_obj(class_name_upper, obj_content, parent)
         
     else:
         log.warning("Unknown content type: %s" % class_name)
         rv = obj_content
     
     return rv
Ejemplo n.º 7
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     try:
         return import_string("pyvisdk.mo.{}.{}".format(camel_to_under(class_name), class_name))
     except ImportError:
         raise ValueError(class_name)
Ejemplo n.º 8
0
 def save_data_modules_to_disk(self):
     from pyvisdk.utils import camel_to_under
     self._write_data_object_types_file()
     for name, content in self.generate_data_type_modules().items():
         with open(join(DATA_MODULES_DIR, '{}.py'.format(camel_to_under(name))), 'w') as fd:
             fd.write(content)
Ejemplo n.º 9
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     return import_string("pyvisdk.mo.{}.{}".format(
         camel_to_under(class_name), class_name))