class ListLogicalPartition:
    
    def __init__(self):
        """
        initializes root and content-type
        """
        self.content_type = CONTENT_TYPE
        self.root = ROOT
        self.headers_obj = HmcHeaders.HmcHeaders("uom")
        
    def list_LogicalPartition(self, ip, uuid, session_id):
        """
        returns the list of available logicalpartition objects
         Args:
           ip : ip address of HMC
           uuid : UUID of the Logical Partition
           session_id : session to be used
        """
        log_object.log_debug("list of Lpar started")
        listing_object = ListModule.ListModule()
        object_list = listing_object.listing("uom",ip,self.root,self.content_type,"LogicalPartition",session_id,uuid)
        log_object.log_debug("Returns Logical Partition objects to the main module")
        return object_list
    
    def print_logicalpartition_attributes(self,logicalpartition_object):
        """
        prints the details of the given LogicalPartition object to the console
        """
        try:
            print("\n")
            print("PartitionName".ljust(35),":",logicalpartition_object.PartitionName.value())
            print("PartitionID".ljust(35),":",logicalpartition_object.PartitionID.value())
            print("PartitionType".ljust(35),":",logicalpartition_object.PartitionType.value())
            print("PartitionState".ljust(35),":",logicalpartition_object.PartitionState.value())
            print("MigrationState".ljust(35),":",logicalpartition_object.MigrationState.value())
            print("PartitionUUID".ljust(35),":",logicalpartition_object.PartitionUUID.value())
            print("AssociatedManagedSystem".ljust(35),":",logicalpartition_object.AssociatedManagedSystem.href)
            print("IsVirtualServiceAttentionLEDOn".ljust(35),":",logicalpartition_object.IsVirtualServiceAttentionLEDOn.value())
            print("Maximum Memory".ljust(35),":",logicalpartition_object.PartitionMemoryConfiguration.MaximumMemory.value())
            print("Desired Memory".ljust(35),":",logicalpartition_object.PartitionMemoryConfiguration.DesiredMemory.value())
            print("Minimum Memory".ljust(35),":",logicalpartition_object.PartitionMemoryConfiguration.MinimumMemory.value())
            print("HasDedicatedProcessors".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.HasDedicatedProcessors.value())
            if logicalpartition_object.PartitionProcessorConfiguration.HasDedicatedProcessors.value():
                print("Maximum Processors".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      DedicatedProcessorConfiguration.MaximumProcessors.value())
                print("Desired Processors".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      DedicatedProcessorConfiguration.DesiredProcessors.value())
                print("Minimum Processors".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      DedicatedProcessorConfiguration.MinimumProcessors.value())
            else:
                print("Maximum ProcessingUnits".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      SharedProcessorConfiguration.MaximumProcessingUnits.value())
                print("Desired ProcessingUnits".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      SharedProcessorConfiguration.DesiredProcessingUnits.value())
                print("Minimum ProcessingUnits".ljust(35),":",logicalpartition_object.PartitionProcessorConfiguration.\
                                      SharedProcessorConfiguration.MinimumProcessingUnits.value())
        except Exception as e:
            self.log_object.log_info("Nonetype object found") class DeleteLogicalPartition:
    
    def __init__(self):
        """
        initializes root ans content-type
        """
        self.content_type = CONTENT_TYPE
        self.root = ROOT
        
    def delete_LogicalPartition(self,ip,uuid,logicalpartition_object,session_id):
        """
        Deletes the provided LogicalPartition
        Args:
           ip : ip Address of HMC
           uuid : ManagedSystemUUID
           logicalpartition_object : object of LogicalPartition to be deleted
           session_id : to access the session
        """
        log_object.log_debug("lpar state --- %s"%(logicalpartition_object.PartitionState.value()))
        if logicalpartition_object.PartitionState.value() == "not activated":
            request_obj = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
            request_obj.HTTPDelete(append=str(uuid)+"/LogicalPartition/"+str(logicalpartition_object.PartitionUUID.value()))
            if request_obj.response_b:
                log_object.log_debug("Partition Deleted Successfully")
                print("\nPartition Deleted Successfully")
        else :
            log_object.log_warn("LogicalPartition is in Running State...Shutdown the partition before deleting.") class ListSRIOVLogicalPort(object):

    def __init__(self):
        """
        initializes root and content-type
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE

    def list_sriov_logical_port(self, ip, logicalpartition_uuid, x_api_session):
        """
        returns a list of SRIOV Ethernet Logical Ports
        Args:
            ip : ip address of HMC
            logicalpartition_uuid : UUID of the Logical Partition
            x_api_session : session to be used
        """
        log.log_debug("list of SRIOVLogical Ports started")
        list_object = ListModule.ListModule()
        object_list = list_object.listing("uom", ip , self.root,
                            self.content_type, "SRIOVEthernetLogicalPort",
                            x_api_session, logicalpartition_uuid)
        log.log_debug("list of SRIOVLogical Ports returned")
        return object_list
    
    def print_sriov_logical_port(self,objects):
        """
        Prints the details of the SRIOV Logical Port to the screen
        """
        print("\n")
        print("AdapterID".ljust(35),":",objects.AdapterID.value())
        print("Capacity".ljust(35),":",objects.ConfiguredCapacity.value())
        print("AllowedVLANs".ljust(35),":",objects.AllowedVLANs.value())
        print("ConfigurationID".ljust(35),":",objects.ConfigurationID.value())
        print("PortVLANID".ljust(35),":",objects.PortVLANID.value()) class CreateSRIOVLogicalPort(object):

    def __init__(self):
        """
        initializes root and content-type
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE

    def create_sriov_logicalport(self, ip, logicalpartition_uuid, x_api_session):
        """
        Creates SRIOV Logical Port for a given LogicaPartition
        Args:
            ip:ip address of hmc
            logicalpartition_uuid : UUID of partition the LoicalPort to be created
            x_api_session :session to be used
        """
        log.log_debug("starting SRIOV LogicalPort creation")
        header_object = HmcHeaders.HmcHeaders("web")
        ns = header_object.ns["xmlns"]
        sriov_logical_port_object = UOM.SRIOVEthernetLogicalPort()
        sriov_logical_port_object.AdapterID = ADAPTER_ID
        sriov_logical_port_object.PhysicalPortID = PHYSICALPORT_ID
        sriov_logical_port_object.schemaVersion = SCHEMA_VER
        xml = sriov_logical_port_object.toxml()
        http_object = HTTPClient.HTTPClient("uom", ip, self.root, self.content_type, x_api_session)
        http_object.HTTPPut(xml, append = logicalpartition_uuid+"/SRIOVEthernetLogicalPort")
        log.log_debug("response of SRIOV logical port creation %s"%(http_object.response))
        if http_object.response_b:
            print("SRIOV Logical Port created successfully")
        else :
            root = etree.fromstring(http_object.response.content)
            error = root.findall(".//{%s}Message"%(ns))[0]
            log.log_error(error.text) class ClearSRIOVLogicalPortStatistics(JobStatus):
    
    def __init__(self):
        """
        initializes root and content-type
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE

    def clear_sriov_logicalport_statistics(self, ip, logicalpartition_uuid, sriov_logicalport_uuid, x_api_session):
        """
        clear the statistical data stored for the selected SRIOV LogicalPort
        Args:
           ip : ip address of HMC
           logicalparrtition_uuid : UUID of Logical Partition in which
                                    SRIOV Logical Port statistics are to be cleared
           sriov_logicalport_uuid : UUID of SRIOV ethernet Logical Port for which statistics to be cleared
           x_api_session : session to be used
        """
        super().__init__(ip, self.root, self.content_type, x_api_session)
        directory = os.path.dirname(__file__)
        xml = open(directory+"/data/clearstatistics.xml").read()
        http_object = HTTPClient.HTTPClient("uom", ip,
                                            self.root, self.content_type,
                                            x_api_session)
        url_append = logicalpartition_uuid+"/SRIOVEthernetLogicalPort/"+sriov_logicalport_uuid+"/do/ClearStatistics"
        http_object.HTTPPut(xml, append = url_append)
        if http_object.response_b:
            self.get_job_status(http_object) class ModifySRIOVEthernetLogicalPort(object):
    def __init__(self):
        """
        initializes root and content-type
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def modify_sriov_logicalport(self, ip, lpar_uuid, sriov_object, x_api_session):
        """
        Modifies the portvlan id of the selected sriov object
        Args:
          ip : ip address of hmc
          lpar_uuid : Logical Partition UUID on which the selected
                      SRIOV Logical Port is to be modified
          sriov_object : The SRIOV Logical port object to be modified
          x_api_session : session to be used
        """
        header = HmcHeaders.HmcHeaders("uom")
        ns = header.ns["xmlns"]
        sriov_object.PortVLANID = PORT_VLAN_ID
        xml = sriov_object.toxml()
        http_object = HTTPClient.HTTPClient("uom", ip,
                                            self.root, self.content_type,
                                            x_api_session)
        sriov_id = sriov_object.Metadata.Atom.AtomID.value()
        http_object.HTTPPost(xml,append=lpar_uuid+"/SRIOVEthernetLogicalPort/"+sriov_id)
        print("\nProcessing ...This may take few seconds")
        log.log_debug("Modification of SRIOV Logical Port Post Performed.Waiting for 60 seconds")
        time.sleep(60)
        http_object.HTTPGet(append=lpar_uuid+"/SRIOVEthernetLogicalPort/"+sriov_id)
        if http_object.response_b:
              root = etree.fromstring(http_object.response.content)
              if root.findall(".//{%s}PortVLANID"%(ns))[0].text == str(sriov_object.PortVLANID.value()):
                  print("\n SRIOVEthernetLogicalPort PortVLANID is modified successfully")
                  log.log_debug("SRIOVEthernetLogicalPort PortVLANID is modified successfully")
              else:
                   log.log_error("Error occured while updating SRIOVEthernetLogicalPort") class ListVirtualFibreChannelClientAdapter:
    """
    List the details of the virtual fibre channel adapter
    for a given logical partition
    """
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def list_virtualfibrechannel_clientadapter(self, ip, logicalpartition_id, x_api_session):
        """
        returns the list of virtual fibre channel adapter available in the
        client partition
        Args:
           ip : ip address of HMC
           logicalpartition_id : UUID of the Logical Partition
           x_api_session : session to be used
        """
        log.log_debug("fc adarpter object list is started")
        list_object = ListModule.ListModule()
        object_list = list_object.listing("uom", ip, self.root, self.content_type,
                            "VirtualFibreChannelClientAdapter", x_api_session,
                            logicalpartition_id)
        log.log_debug("fc adarpter object list is returned")
        return object_list
    
    def print_virtualfibrechannel_attributes(self,objects):
        """
        print the details of the given virtual fibre channel adapter
        """
        print("\n")
        print("LocalPartitionID".ljust(35),":",objects.LocalPartitionID.value())
        print("VirtualSlotNumber".ljust(35),":",objects.VirtualSlotNumber.value())
        print("RequiredAdapter".ljust(35),":",objects.RequiredAdapter.value())
        print("ConnectingPartitionID".ljust(35),":",objects.ConnectingPartitionID.value())
        print("ConnectingVirtualSlotNumber".ljust(35),":",objects.ConnectingVirtualSlotNumber.value())
        print("WWPNs".ljust(35),":",objects.WWPNs.value()) class CreateVirtualFibreChannelClientAdapter:
    """
    creates a virtual fibre channel adapter on a given logical partition
    """
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def create_virtualfibrechannel_clientadapter(self, ip, logicalpartition_uuid, x_api_session):
        """
        Args:
            ip: ip address of hmc
            logicalpartition_uuid:UUID of Logical partition on which virtual fc
            adapter is to be created
            x_api_session:session used to create virtual fc adapter
        """
        log.log_debug("creation of fc adapter started ")
        virtualfibrechannel_object = UOM.VirtualFibreChannelClientAdapter()
        virtualfibrechannel_object.AdapterType = ADAPTER_TYPE
        virtualfibrechannel_object.ConnectingPartitionID = PARTITION_ID
        virtualfibrechannel_object.ConnectingVirtualSlotNumber = SLOT_NUMBER
        virtualfibrechannel_object.schemaVersion = SCHEMA_VER
        pyxb.RequireValidWhenGenerating(True)
        xml = virtualfibrechannel_object.toxml()
        http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                            self.content_type, x_api_session)
        http_object.HTTPPut(xml,append=logicalpartition_uuid+"/VirtualFibreChannelClientAdapter")
        log.log_debug("response status for scsi creation --- %s"%(http_object.response))
        if http_object.response_b:
            print("VirtualFibreChannelClientAdapter created successfully")
            log.log_debug("VirtualFibreChannelClientAdapter created successfully")
        else :
            log.log_error("Error in VirtualFibreChannelClientAdapter creation.Verify the attribute values") class ListVirtualSCSIClientAdapter:
    """
    List the details of the virtual SCSI adapter
    for a given logical partition
    """
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def list_virtualscsi_clientadapter(self, ip, logicalpartition_id, x_api_session):
        """
        returns the list of virtual SCSI adapter available in the
        client partition
         Args:
           ip : ip address of HMC
           logicalpartition_id : UUID of the Logical Partition
           x_api_session : session to be used
        """
        log.log_debug("List of vscsi adapter started")
        list_object = ListModule.ListModule()
        object_list = list_object.listing("uom", ip, self.root, self.content_type,
                            "VirtualSCSIClientAdapter", x_api_session,
                            logicalpartition_id)
        log.log_debug("List of vscsi adapter returned")
        return object_list
    
    def print_vscsi_attributes(self,objects):
        """
        print the details of the given virtual SCSI adapter
        """
        print("\n")
        print("LocalPartitionID".ljust(35),":",objects.LocalPartitionID.value())
        print("VirtualSlotNumber".ljust(35),":",objects.VirtualSlotNumber.value())
        print("RequiredAdapter".ljust(35),":",objects.RequiredAdapter.value())
        print("RemoteLogicalPartitionID".ljust(35),":",objects.RemoteLogicalPartitionID.value())
        print("RemoteSlotNumber".ljust(35),":",objects.RemoteSlotNumber.value()) class CreateVirtualSCSIClientAdapter:
    """
    creates a virtual SCSI adapter on a given logical partition
    """
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def create_vscsi_clientadapter(self, ip, logicalpartition_uuid, x_api_session):
        """
        Args:
            ip: ip address of hmc
            logicalpartition_uuid:UUID of Logical partition on which virtual SCSI
            adapter is to be created
            x_api_session:session used to create virtual SCSI adapter
        """
        log.log_debug("creation of scsi adapter started")
        vscsi_object = UOM.VirtualSCSIClientAdapter()
        vscsi_object.AdapterType = ADAPTER_TYPE
        vscsi_object.RemoteLogicalPartitionID = PARTITION_ID
        vscsi_object.RemoteSlotNumber = SLOT_NUMBER
        vscsi_object.schemaVersion = SCHEMA_VER
        pyxb.RequireValidWhenGenerating(True)
        xml = vscsi_object.toxml()
        http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                            self.content_type, x_api_session)
        http_object.HTTPPut(xml,append=logicalpartition_uuid+"/VirtualSCSIClientAdapter")
        log.log_debug("response of create scsi adapter --- %s"%(http_object.response))
        if http_object.response_b:
            print("VirtualSCSIClientAdapter created successfully")
            log.log_debug("VirtualSCSIClientAdapter created successfully")
        else :
           log.log_error("Error in VirtualSCSIClientAdapter creation.Verify the attribute values") class CreateClientNetworkAdapter:
    """
    creates a client network adapter with next adapter id
    This will update the LPAR and put a new CNA on it.  If the LPAR is active
    can only perform and if there is an active RMC connection.  If the LPAR is
    powered off, then it will update it offline.
    """
    
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def create_clientnetwork_adapter(self, ip, logicalpartition_id, x_api_session):
        """
        Args:
           ip:ip address of the hmc
           logicalpartition_id:the uuid of the logical partition on which network adapter
           is to be created
           x_api_session:session used to create network adapter
        """
        log.log_debug("create client network adapter starting")
        pyxb.RequireValidWhenGenerating(True)
        clientnetwork_adapter_object = UOM.ClientNetworkAdapter()
        clientnetwork_adapter_object.PortVLANID = PORT_VLAN_ID
        clientnetwork_adapter_object.schemaVersion = SCHEMA_VER
        xml = clientnetwork_adapter_object.toxml()
        http_object = HTTPClient.HTTPClient("uom", ip, self.root, self.content_type, x_api_session)
        http_object.HTTPPut(xml,append= logicalpartition_id+"/ClientNetworkAdapter")
        log.log_debug("response of create client network adapter --- %s"%(http_object.response))
        if http_object.response_b:
            print("ClientNetworkAdapter Created successfully")
            log.log_debug("ClientNetworkAdapter Created successfully")
        else :
            log.log_error("Error in ClientNetworkAdapter Creation") class ListClientNetworkAdapter:
    """
    List the details of existing client network adapter
    """
    
    def __init__(self):
        """
        assign the root and content_type for request
        """
        self.root = ROOT
        self.content_type = CONTENT_TYPE
        
    def list_clientnetwork_adapter(self, ip, logicalpartition_id, x_api_session):
        """
        returns a list client network adapters available in the given logical partition
        Args:
          ip : ip address of HMC
          logicalpartition_object : object of Logical Partition in which client Network Adapter
                                    is to be created
          x_api_session : session to be used
        """
        log.log_debug("client network adapter object list is started")
        list_object_list = ListModule.ListModule()
        object_list = list_object_list.listing("uom", ip,
                                 self.root, self.content_type,
                                 "ClientNetworkAdapter", x_api_session,
                                 logicalpartition_id)
        log.log_debug("client network adapter object list is returned")
        
        return object_list
    
    def print_clientnetwork_adapter_attributes(self,objects):
        """
        prints the details of the given client network adapter given
        """
        print("\n")
        print("VirtualSlotNumber".ljust(35),":",objects.VirtualSlotNumber.value())
        print("VirtualSwitchID".ljust(35),":",objects.VirtualSwitchID.value())
        print("PortVLANID".ljust(35),":",objects.PortVLANID.value())
        print("RequiredAdapter".ljust(35),":",objects.RequiredAdapter.value())                                 class PowerOnPartition(JobStatus):
    
    def __init__(self, partition_type):
        """
        initializes root and content_type
        Args:
            partition_type : type of  object Logical Partition or VirtualIOServer
        """
        self.content_type = CONTENT_TYPE
        self.root = partition_type
        self.headers_obj = HmcHeaders.HmcHeaders("web")
        directory_path=os.path.dirname(__file__)
        self.input = open(directory_path+"/data/poweron_lpar.xml","r").read()
        
    def poweron_Partition(self, ip, logicalpartition_object, session_id):
        """
        performs poweron operation for the provided LogicalPartition object
        Args:
           ip : ip address of HMC
           logicalpartition_object : object of the logical partition to be activated
           session_id : session to be used
        """
        super().__init__(ip, self.root, self.content_type, session_id)
        log_object.log_debug("Power on of lpar started")
        namespace = self.headers_obj.ns["xmlns"]
        logicalpartitionprofile_object = ListLogicalPartitionProfile.ListLogicalPartitionProfile(self.root)
        object_list = logicalpartitionprofile_object.list_LogicalPartitionProfile(ip,logicalpartition_object.PartitionUUID.value(),session_id)
        ProfileUUID = object_list[0].Metadata.Atom.AtomID.value()
        inputpayload = self.input.format(self.root, ProfileUUID)
        logicalpartition_uuid = logicalpartition_object.PartitionUUID.value()
        request_object = HTTPClient.HTTPClient("uom", ip, self.root, self.content_type, session_id)
        request_object.HTTPPut(payload=inputpayload, append=str(logicalpartition_uuid)+"/do/PowerOn")
        log_object.log_debug("response of lpar poweron --- %s"%(request_object.response))
        if request_object.response_b:
            self.get_job_status(request_object) class PowerOffPartition(JobStatus):
    
    def __init__(self, partition_type):
        """
        initializes root and content_type
        Args:
            partition_type : type of  object Logical Partition or VirtualIOServer
        """
        self.content_type = CONTENT_TYPE
        self.root = partition_type
        self.headers_obj = HmcHeaders.HmcHeaders("web")
        directory_path=os.path.dirname(__file__)
        self.input = open(directory_path+"\data\poweroff_lpar.xml","r").read()
        self.input = self.input.format(partition_type)
        
    def poweroff_Partition(self, ip, logicalpartition_object, session_id):
        """
        performs the poweroff operation for the provided LogicalPartition object
        Args:
           ip : ip address of HMC
           logicalpartition_object : object of logicalpartition to be deactivated
           session_id : session to be used
        """
        super().__init__(ip, self.root, self.content_type, session_id)
        log_object.log_debug("power off of lpar started")
        namespace = self.headers_obj.ns["xmlns"]
        logicalpartition_uuid = logicalpartition_object.PartitionUUID.value()
        request_object = HTTPClient.HTTPClient("uom", ip, self.root, self.content_type, session_id)
        request_object.HTTPPut(payload=self.input, append=str(logicalpartition_uuid)+"/do/PowerOff")
        log_object.log_debug("response of power off job request --- %s"%(request_object.response))
        if request_object.response_b:
            self.get_job_status(request_object) class ModifyPartition:
    """
    class provides definitions for Modifying LogicalPartition 
    """
    
    def __init__(self, partition_type):
        """
        initializes the content-type and root
        Args:
            partition_type : type of  object Logical Partition or VirtualIOServer
        """
        
        self.content_type = CONTENT_TYPE%(partition_type)
        self.root = partition_type
        self.headers_obj = HmcHeaders.HmcHeaders("uom")
        
    def modify_Partition(self, ip, logicalpartition_object, session_id):
            """
            Modifies the Memory attributes of provided logicalpartition object
            Args:
               ip : IP address of HMC
               logicalpartition_object : the object of LogicalPartition
                                         to be modified
               session_id : session to be used
            """
            log_object.log_debug("modification of lpar started ")
            logicalpartition_object.PartitionMemoryConfiguration.DesiredMemory = DES_MEMORY
            logicalpartition_object.PartitionMemoryConfiguration.MaximumMemory = MAX_MEMORY
            logicalpartition_object.PartitionMemoryConfiguration.MinimumMemory = MIN_MEMORY
            inputpayload = logicalpartition_object.toxml("utf-8")
            request_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
            request_object.HTTPPost(payload=inputpayload,append=str(logicalpartition_object.PartitionUUID.value()))
            log_object.log_debug("response of lpar modification --- %s"%(request_object.response))
            if request_object.response_b:
                log_object.log_debug("updations to partition are made successfully")
                return True
            else:
                return False class CreatePartition:
    """
    class provides definitions for LogicalPartition Creation
    """
    
    def __init__(self, partition_type):
        """
        initializes the content-type and root
        Args:
            partition_type : type of  object Logical Partition or VirtualIOServer
        """
        self.type = partition_type
        self.content_type = CONTENT_TYPE%(partition_type)
        self.root = ROOT
        self.headers_obj = HmcHeaders.HmcHeaders("uom")
        
    def create_Partition(self,ip,uuid,session_id):
            """
            Args:
              ip:ip address of HMC
              uuid:ManagedSystemUUID
              session_id:to access the session
            Returns:
              Returns the created LogicalPartition object
            """
            log_object.log_debug("creation of logical partition started")
            obj = eval(self.type)()
            ns = self.headers_obj.ns
            obj.schemaVersion = SCHEMA_VER
            pyxb.RequireValidWhenGenerating(True)
            obj.PartitionMemoryConfiguration = pyxb.BIND()
            obj.PartitionMemoryConfiguration.schemaVersion = SCHEMA_VER
            obj.PartitionMemoryConfiguration.DesiredMemory = DES_MEMORY
            obj.PartitionMemoryConfiguration.MaximumMemory = MAX_MEMORY
            obj.PartitionMemoryConfiguration.MinimumMemory = MIN_MEMORY
            obj.PartitionProcessorConfiguration = pyxb.BIND()
            obj.PartitionProcessorConfiguration.schemaVersion = SCHEMA_VER
            obj.PartitionProcessorConfiguration.HasDedicatedProcessors = DEDICATED_PROCESSORS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration = pyxb.BIND()
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.schemaVersion = SCHEMA_VER
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.DesiredProcessingUnits = DES_PROC_UNITS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.DesiredVirtualProcessors = DES_VIRTUAL_PROCESSORS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.MaximumProcessingUnits = MAX_PROC_UNITS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.MaximumVirtualProcessors = MAX_VIRTUAL_PROCESSORS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.MinimumProcessingUnits = MIN_PROC_UNITS
            obj.PartitionProcessorConfiguration.SharedProcessorConfiguration.MinimumVirtualProcessors = MIN_VIRTUAL_PROCESSORS
            obj.PartitionProcessorConfiguration.SharingMode = SHARING_MODE
            if self.type == "VirtualIOServer":
                obj.PartitionType = "Virtual IO Server"
                partition_name = PARTITION_NAME%("VIOS")+""+time.strftime("%d%m%y-%X")
            else:
                obj.PartitionType = "AIX/Linux"
                partition_name = PARTITION_NAME%("LPAR")+""+time.strftime("%d%m%y-%X")
            obj.PartitionName = partition_name
            xmlobject = obj.toDOM()
            xmlobject.documentElement.setAttribute("xmlns",ns["xmlns"])
            xmlpayload = xmlobject.toxml("utf-8")
            request_obj = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
            request_obj.HTTPPut(xmlpayload,append=str(uuid)+"/"+self.type)
            log_object.log_debug("response of lpar creation -- %s"%(request_obj.response))
            if request_obj.response_b:
                root = etree.fromstring(request_obj.response.content)
                entry = root.findall(".//%s:%s"%(self.type,self.type),
                                     namespaces={self.type: ns["xmlns"]})
                xmlstring = etree.tostring(entry[0])
                xml_object = CreateFromDocument(xmlstring)
                log_object.log_debug("partition created successfully")
                return xml_object class ListLogicalPartitionProfile:
    """
    ListLogicalPartitionProfile provides the definitions
    to return the list of
    LogicalPartitionProfile objects available in the
    given vios and contains the
    print definition to print the LogicalPartitionProfile
    attribute details.
    """
     
    def __init__(self,root):        
        
        self.content_type = CONTENT_TYPE
        self.root=root
        
    def list_LogicalPartitionProfile(self,ip,uuid,session_id):
        """
        Accessed with ListLogicalPartitionProfile object
        Args:
              ip:ip address of the hmc
              uuid:vios uuid
              session_id:session to access the vios
        Returns:
              object_list containing the list of available LogicalPartitionProfile Objects
        """
        log_object.log_debug("List of Logical Partition Profile Started")
        listing_object = ListModule.ListModule()
        object_list = listing_object.listing("uom", ip,
                                                  self.root,
                                                  self.content_type, "LogicalPartitionProfile",
                                                  session_id, uuid)
        log_object.log_debug("Returns Logical Partition Profile" +
                                  "objects to the main module")
        return object_list
    
    def print_logicalpartitionprofile_attributes(self, profile_object):
        """
        Accessed with ListLogicalPartitionProfile object

        Args:
            object_list:the selected object choice from src.the available LogicalPartitionProfile objects.
        """
        
        print("\n")
        print("ProfileName".ljust(35),":",profile_object.ProfileName.value())
        print("ProfileType".ljust(35),":",profile_object.ProfileType.value())
        print("Maximum Memory".ljust(35),":",profile_object.ProfileMemory.MaximumMemory.value())
        print("Desired Memory".ljust(35),":",profile_object.ProfileMemory.DesiredMemory.value())
        print("Minimum Memory".ljust(35),":",profile_object.ProfileMemory.MinimumMemory.value())
        print("HasDedicatedProcessors".ljust(35),":",
              profile_object.ProcessorAttributes.HasDedicatedProcessors.value())
        if profile_object.ProcessorAttributes.HasDedicatedProcessors.value():
            print("Maximum Processors".ljust(35),":",profile_object.ProcessorAttributes.\
                                  DedicatedProcessorConfiguration.MaximumProcessors.value())
            print("Desired Processors".ljust(35),":",profile_object.ProcessorAttributes.\
                                  DedicatedProcessorConfiguration.DesiredProcessors.value())
            print("Minimum Processors".ljust(35),":",profile_object.ProcessorAttributes.\
                                  DedicatedProcessorConfiguration.MinimumProcessors.value())
        else:
            print("Maximum ProcessingUnits".ljust(35),":",profile_object.ProcessorAttributes.\
                                  SharedProcessorConfiguration.MaximumProcessingUnits.value())
            print("Desired ProcessingUnits".ljust(35),":",profile_object.ProcessorAttributes.\
                                  SharedProcessorConfiguration.DesiredProcessingUnits.value())
            print("Minimum ProcessingUnits".ljust(35),":",profile_object.ProcessorAttributes.\
                                  SharedProcessorConfiguration.MinimumProcessingUnits.value()) class CreateLogicalPartitionProfile:
    """
    class provides definitions for LogicalPartitionProfile Creation
    """
    
    def __init__(self,root):
        """
        initializes the content-type and root
        """
        
        self.content_type = CONTENT_TYPE
        self.root = root
        self.headers_obj = HmcHeaders.HmcHeaders("uom")
        
    def create_LogicalPartitionProfile(self, ip, logicalpartition_object, session_id):
        """
        Assign values to the profile object and creates the profile to the given vios
        Args:
           ip : ip address of hmc
           logicalpartition_object : VIOS/Logical Partition object on which
                                     profile should be created
           session_id : session to be used
        """
        log_object.log_debug("creation of lpar profile started")
        ns = self.headers_obj.ns
        logicalpartitionprofile_object = UOM.LogicalPartitionProfile()
        pyxb.RequireValidWhenGenerating(True)
        logicalpartitionprofile_object.ProfileName = PROFILE_NAME%(time.strftime("%d%m%y-%X"))
        logicalpartitionprofile_object.ProfileType = PROFILE_TYPE
        logicalpartitionprofile_object.schemaVersion = SCHEMA_VER
        logicalpartitionprofile_object.ProfileMemory = pyxb.BIND()
        logicalpartitionprofile_object.ProfileMemory.schemaVersion = SCHEMA_VER
        logicalpartitionprofile_object.ProfileMemory.MaximumMemory = MAX_MEMORY
        logicalpartitionprofile_object.ProfileMemory.MinimumMemory = MIN_MEMORY
        logicalpartitionprofile_object.ProfileMemory.DesiredMemory = DES_MEMORY
        xmlobject = logicalpartitionprofile_object.toDOM()
        xmlobject.documentElement.setAttribute("xmlns",ns["xmlns"])
        xmlpayload = xmlobject.toxml("utf-8")
        HTTPClient_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
        HTTPClient_object.HTTPPut(payload=xmlpayload,append=str(logicalpartition_object.PartitionUUID.value())+"/LogicalPartitionProfile")
        log_object.log_debug("response of profile creation -- %s"%(HTTPClient_object.response))
        if HTTPClient_object.response_b:
            root = etree.fromstring(HTTPClient_object.response.content)
            entry = root.findall(".//LogicalPartitionProfile:LogicalPartitionProfile",
                                     namespaces={"LogicalPartitionProfile": ns["xmlns"]})
            xmlstring = etree.tostring(entry[0])
            xml_object = UOM.CreateFromDocument(xmlstring)
            log_object.log_debug("created partition successfully")
            return xml_object
        else: 
            log_object.log_error("Error in Profile creation") class ModifyLogicalPartitionProfile:
    """
    class provides definitions for Modifying LogicalPartitionProfile
    """
    
    def __init__(self,root):
        """
        initializes the content-type and root
        """
        
        self.content_type = CONTENT_TYPE
        self.root = root
        self.headers_obj = HmcHeaders.HmcHeaders("uom")
        
    def modify_LogicalPartitionProfile(self, ip, logicalpartition_uuid, logicalpartitionprofile_object, session_id):
            """
            Modifies the Memory attributes of provided logicalpartitionprofile object
            Args:
               ip : IP address of HMC
               logicalpartition_uuid : the Logical partition uuid under which the profile to be modified
               logicalpartitionprofile_object : the Logical partition profile uuid which is to be modified
               session_id : session to be used
            """
            log_object.log_debug("LPAR profile modification started")
            logicalpartitionprofile_object.ProfileMemory.DesiredMemory = 512
            logicalpartitionprofile_object.ProfileMemory.MaximumMemory = 512
            logicalpartitionprofile_object.ProfileMemory.MinimumMemory = 512
            inputpayload = logicalpartitionprofile_object.toxml("utf-8")
            profileuuid = str(logicalpartitionprofile_object.Metadata.Atom.AtomID.value())
            request_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
            request_object.HTTPPost(payload=inputpayload,append=str(logicalpartition_uuid)+"/LogicalPartitionProfile/%s" \
                                                                    %(profileuuid))
            log_object.log_debug("response of profile modification --- %s"%(request_object.response))
            if request_object.response_b:
                log_object.log_debug("partitions are updated successfully")
                return True
            else:
                return False
from src.main.HmcRestClient import *
from src.logical_partition import ListLogicalPartition, \
                                  DeleteLogicalPartition
from src.logical_partition.sriov_logical_port import ListSRIOVLogicalPort, \
                                                    CreateSRIOVLogicalPort, \
                                                    ClearSRIOVLogicalPortStatistics, \
                                                    ModifySRIOVEthernetLogicalPort
from src.logical_partition.virtual_fibrechannel_client_adapter  import ListVirtualFibreChannelClientAdapter, \
                                                                       CreateVirtualFibreChannelClientAdapter
from src.logical_partition.vscsi_client_adapter import ListVirtualSCSIClientAdapter, \
                                                       CreateVirtualSCSIClientAdapter
from src.logical_partition.client_network_adapter import CreateClientNetworkAdapter, \
                                                         ListClientNetworkAdapter
from src.partition_operation_util import PowerOnPartition,\
                                     PowerOffPartition,\
                                     ModifyPartition, \
                                     CreatePartition
from src.logical_partition_profile import ListLogicalPartitionProfile,\
                                          CreateLogicalPartitionProfile,\
                                          ModifyLogicalPartitionProfile
import sys
import os
# Copyright 2015, 2016 IBM Corp.
#
# All Rights Reserved.
#
#    Licensed 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.



                                                    


                                                         


####################
# LOGICAL PARTITON
####################

directory = os.path.dirname(os.path.dirname(__file__))
def logicalpartition_children(n1, managedsystem_uuid, ip, x_api_session):
    """
    This function provides a detailed view of the Logical Partitions

    Args:
     n1 : variable for client selected choices
     managedsystem_uuid : The unique id of the Managed system
     ip: ip address of hmc
     x_api_session : session to be used

    """
    os.system("cls")
    n = n1
    if n == 1:
        #Logical Partition operations
        while True:
            print ("\n\n","LogicalPartition operations".center(50))
            print_list = ['List','Create','Delete','Poweron',
                         'Poweroff','Modify','Return to LogicalPartition Menu',
                          'Return to ManagedSystem Menu','Return to MainMenu','Help','Exit']
            #select any one Logical partition operation
            x = int(print_obj.print_on_screen(print_list))
            listlogicalpartition_object = ListLogicalPartition.ListLogicalPartition()
            object_list = listlogicalpartition_object.\
                              list_LogicalPartition(ip, managedsystem_uuid,
                                                     x_api_session)                              
            if x == 1:
                # object creation and method call to List Logical Partition
                print("\nAvailable LogicalPartitions :")
                selected_logicalpartition_object = get_selectedobject(object_list)
                if selected_logicalpartition_object != None:
                    listlogicalpartition_object.print_logicalpartition_attributes(selected_logicalpartition_object)
                
            elif x == 2:
                #object creation and method call to create Logicalpartition
                 try:
                     print("\nLogical Partition will be created with Following configruations,\n maximum,mimimum and desired memory = 256",
                           "\nShared processors,Minimum,Desired and maximum processing units = 0.5,\npartition type = AIX/Linux")

                     logicalpartition_object = CreatePartition.CreatePartition("LogicalPartition")