def create_folder(viserver, root_folder, new_name): request = VI.CreateFolderRequestMsg() _this = request.new__this(root_folder) _this.set_attribute_type(root_folder.get_attribute_type()) request.set_element__this(_this) request.set_element_name(new_name) viserver._proxy.CreateFolder(request)
def createFolder(vm_folder, folder_name): try: request = VI.CreateFolderRequestMsg() _this = request.new__this(vm_folder) _this.set_attribute_type(vm_folder.get_attribute_type()) request.set_element__this(_this) request.set_element_name(folder_name) server._proxy.CreateFolder(request) except pysphere.ZSI.FaultException, e: pass
def FloderCheck(self,folder_name,parent_folder_name='vm'): dc_id = self.__order.resource.node.dc.datacenter_id nf = [ x for x,y in self.__s.get_datacenters().items() if x ==dc_id] nfmor = nf[0] if len(nf) > 0 else None folders = self.__s._retrieve_properties_traversal(property_names=['name'], from_node=nfmor, obj_type='Folder') folder = list() rs = None for f in folders: folder.append(f.PropSet[0].Val) if f.PropSet[0].Val == parent_folder_name: vm_folder = f.Obj if f.PropSet[0].Val == folder_name: rs = f.Obj if rs is None: request = VI.CreateFolderRequestMsg() _this = request.new__this(vm_folder) _this.set_attribute_type(vm_folder.get_attribute_type()) request.set_element__this(_this) request.set_element_name(folder_name) rs = self.__s._proxy.CreateFolder(request) return rs
#VMs should be created by a folder, in ESX always uses the vm folder vmfmor = [ k for k, v in s._get_managed_objects(MORTypes.Folder).items() if v == "vm" ][0] print "vmfmor = %s" % vmfmor #look for the resource pool whose path is rp_path rpmor = [k for k, v in s.get_resource_pools().items() if v == rp_path][0] print "rpmor = %s" % rpmor #ESXs have just one host, so use that one hostmor = s.get_hosts().keys()[0] print "hostmor = %s" % hostmor create_folder_request = VI.CreateFolderRequestMsg() config = VI.folder #config = create_folder_request.new_config() create_folder_request.set_element_config(config) files = config.new_files() files.set_element_vmPathName("[%s] %s" % (DATASTORE, folder_name)) config.set_element_files(files) #CREATE THE VM taskmor = s._proxy.CreateVM_Task(create_folder_request)._returnval task = VITask(taskmor, s) task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR]) if task.get_state() == task.STATE_ERROR: print "Error creating Folder: %s" % task.get_error_message() s.disconnect()