コード例 #1
0
 def create_virtualnetwork(self, ip, managedsystem_uuid, x_api_session, virtualswitch_object):
     """
     create a virtual network in a given managed system
     Args:
         ip:ip address of hmc
         managedsystem_uuid:UUID of managedsystem
         x_api_session:session to be used
         virtualswitch_object:Virtual switch object to be used for virtual network
     Returns:
         boolean value
     """
     log.log_debug("virtual network creation started")
     pyxb.RequireValidWhenGenerating(True)
     virtual_network_object = UOM.VirtualNetwork()
     virtual_network_object.schemaVersion = SCHEMA_VER
     virtual_network_object.AssociatedSwitch = pyxb.BIND()
     virtual_network_object.AssociatedSwitch.href = "https://%s:12443/rest/api/uom/ManagedSystem/%s/VirtualSwitch/%s"\
                                                    %(ip,managedsystem_uuid,virtualswitch_object.Metadata.Atom.AtomID.value())
     virtual_network_object.AssociatedSwitch.rel = "related"
     virtual_network_object.NetworkVLANID = NETWORK_VLAN_ID 
     virtual_network_object.NetworkName = "VLAN%s-%s"%(virtual_network_object.NetworkVLANID.value(),virtualswitch_object.SwitchName.value())
     virtual_network_object.VswitchID = virtualswitch_object.SwitchID.value()
     virtual_network_object.TaggedNetwork = TAGGED_NETWORK
     xml = virtual_network_object.toxml()
     http_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,x_api_session)
     http_object.HTTPPut(xml,append=managedsystem_uuid+"/VirtualNetwork")
     log.log_debug("virtualnetwork creation response -- %s"%(http_object.response))
     if http_object.response_b:
         return True
     else :
         return False
コード例 #2
0
 def add_loadgroup(self, ip, managedsystem_uuid, session_id, networkbridge_object, virtualnetwork_object):
     """
     addition of a Loadgroup
     Args:
         ip:ip address of hmc
         managedsystem_uuid:UUID of the managedsystem
         session_id:session to be used
         networkbridge_object:networkbridge object to be modified
         vrtualnetwork_object:virtual network object on which Loadgroup is to be added
     Returns:
          boolen value
     """
     log.log_debug("addition of load group started")
     link = "https://"+ip+":12443/rest/api/uom/ManagedSystem/"+managedsystem_uuid+"/VirtualNetwork/"+virtualnetwork_object.Metadata.Atom.AtomID.value()
     loadgroup_object = UOM.LoadGroup()
     loadgroup_object.PortVLANID = virtualnetwork_object.NetworkVLANID.value()
     loadgroup_object.VirtualNetworks = pyxb.BIND()
     loadgroup_object.VirtualNetworks.link.append(UOM.AtomLink_Type(rel="related",href=link))
     loadgroup_object.schemaVersion = SCHEMA_VER
     networkbridge_object.LoadGroups.LoadGroup.append(loadgroup_object)
     xml = networkbridge_object.toxml()
     httpclient_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,session_id)
     httpclient_object.HTTPPost(xml,append=str(managedsystem_uuid)+"/NetworkBridge/"+networkbridge_object.Metadata.Atom.AtomID.value())
     log.log_debug("reponse for addition of loadgroup -- %s"%(httpclient_object.response))
     if  httpclient_object.response_b:
         return True
     else:
         return False
コード例 #3
0
 def create_volumegroup(self, ip, virtualioserver_uuid, x_api_session):
     """
     Args:
         ip:ip address of hmc
         virtualioserver_uuid:UUID of VirtualIOServer
         x_api_session:session to be used
     """
     log.log_debug("create volume group started")
     pyxb.RequireValidWhenGenerating(True)
     volumegroup_object = UOM.VolumeGroup()
     volumegroup_object.schemaVersion = SCHEMA_VER
     volumegroup_object.GroupName = VOLUMEGROUP_NAME
     physicalvolume_object = UOM.PhysicalVolume()
     physicalvolume_object.VolumeName = PHYSICALVOLUME_NAME
     physicalvolume_object.schemaVersion = SCHEMA_VER
     volumegroup_object.PhysicalVolumes = pyxb.BIND()
     volumegroup_object.PhysicalVolumes.schemaVersion = SCHEMA_VER
     volumegroup_object.PhysicalVolumes.append(physicalvolume_object)
     xml = volumegroup_object.toxml()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, x_api_session)
     http_object.HTTPPut(xml, append=virtualioserver_uuid + "/VolumeGroup")
     log.log_debug("response of volume group creation -- %s" %
                   (http_object.response))
     if http_object.response_b:
         print("VolumeGroup Created Successfully")
         log.log_debug("VolumeGroup Created Successfully")
     else:
         log.log_error(
             "Error in VolumeGroup creation.Verify the attribute values")
コード例 #4
0
 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"
         )
コード例 #5
0
 def modify_virtualnetwork(self, ip, managedsystem_uuid, session_id,
                           virtualnetwork_object):
     """
     Modifies the name of the selected Virtual Network
     Args:
         ip:ip address of hmc
         managedsystem_uuid:UUID of managedsystem
         x_api_session:session to be used
         virtualnetwork_object:virtual network object to be modified
     Returns:
         boolean value
     """
     log.log_debug("virtual network modification started")
     virtualnetwork_object.NetworkName = "VLAN%s-%s" % (
         virtualnetwork_object.NetworkVLANID.value(),
         virtualnetwork_object.VswitchID.value())
     virtualnetwork_id = virtualnetwork_object.Metadata.Atom.AtomID.value()
     xml = virtualnetwork_object.toxml()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, session_id)
     http_object.HTTPPost(xml,
                          append=managedsystem_uuid + "/VirtualNetwork/" +
                          virtualnetwork_id)
     log.log_debug("response of virtual network modification -- %s" %
                   (http_object.response))
     if http_object.response_b:
         return True
     else:
         return False
コード例 #6
0
 def delete_logicalunit(self, ip, ssp_object, x_api_session,
                        logicalunit_name):
     """
     Args:
         ip:ip address of the hmc
         ssp_object:ssp object from which Logical unit is to
                    be deleted
         x_api_session:session to be used to delete Logical unit
         logicalunit_name:name of the Logical Unit to be deleted
     """
     log.log_debug("Invoking delete Logical Unit")
     ssp_id = ssp_object.Metadata.Atom.AtomID.value()
     log.log_debug("LU to be removed -- %s" % (logicalunit_name))
     for logicalunit in ssp_object.LogicalUnits.LogicalUnit:
         if logicalunit.UnitName.value() == logicalunit_name:
             ssp_object.LogicalUnits.LogicalUnit.remove(logicalunit)
             http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                                 self.content_type,
                                                 x_api_session)
             xml = ssp_object.toxml()
             http_object.HTTPPost(xml, append=ssp_id)
             log.log_debug("response status code for delete LU --- %s" %
                           (http_object.response))
             if http_object.response_b:
                 print("\nLogical unit %s is removed successfully" %
                       (logicalunit_name))
                 log.log_debug("Logical unit %s is removed successfully" %
                               (logicalunit_name))
             return
     log.log_error("\nProvided LogicalUnit name is not available")
コード例 #7
0
    def create_cluster(self, ip, x_api_session, vios_id):
        """
        xml for cluster and shared storage pool are created
        from python objects and are inserted in to job request
        input xml.
        Args:
            ip:ip address of hmc
            x_api_session:session used to create cluster
            vios_id:UUID of vios to be added to the cluster
        """
        super().__init__(ip, self.root, self.content_type, x_api_session)
        log.log_debug("Invoking create cluster")
        directory = os.path.dirname(__file__) + "/data/create_cluster.xml"
        xml = open(directory).read()
        link = "https://" + ip + ":12443/rest/api/uom/VirtualIOServer/" + vios_id
        log.log_debug("Link of vios to be added to cluster %s" % (link))
        cluster_object = UOM.Cluster()
        cluster_object.ClusterName = CLUSTER_NAME % (
            time.strftime("%d%m%y-%X"))
        cluster_object.schemaVersion = SCHEMA_VER

        physicalvolume_object = UOM.PhysicalVolume()
        physicalvolume_object.VolumeName = PHYSICAL_VOLUME_REPODISK
        physicalvolume_object.schemaVersion = SCHEMA_VER
        cluster_object.RepositoryDisk = pyxb.BIND()
        cluster_object.RepositoryDisk.schemaVersion = SCHEMA_VER
        cluster_object.RepositoryDisk.PhysicalVolume.append(
            physicalvolume_object)

        cluster_object.Node = pyxb.BIND()
        node_object = UOM.Node()
        node_object.HostName = HOST_NAME
        node_object.VirtualIOServer = pyxb.BIND()
        node_object.VirtualIOServer.href = link
        node_object.VirtualIOServer.rel = "related"
        node_object.schemaVersion = SCHEMA_VER
        cluster_object.Node.schemaVersion = SCHEMA_VER
        cluster_object.Node.Node.append(node_object)
        cluster_xml = cluster_object.toxml()

        ssp_object = UOM.SharedStoragePool()
        ssp_object.schemaVersion = SCHEMA_VER
        physicalvolume_object.VolumeName = PHYSICAL_VOLUME_SSP1
        ssp_object.PhysicalVolumes = pyxb.BIND()
        ssp_object.PhysicalVolumes.schemaVersion = SCHEMA_VER
        ssp_object.PhysicalVolumes.PhysicalVolume.append(physicalvolume_object)
        physicalvolume_object.VolumeName = PHYSICAL_VOLUME_SSP2
        ssp_object.PhysicalVolumes.PhysicalVolume.append(physicalvolume_object)
        ssp_object.StoragePoolName = POOL_NAME
        sspxml = ssp_object.toxml()

        xml = xml % (cluster_xml, sspxml)

        http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                            self.content_type, x_api_session)
        http_object.HTTPPut(xml, append="/do/create")
        log.log_debug("HTTP response for creating cluster -- %s" %
                      (http_object.response))
        if http_object.response_b:
            self.get_job_status(http_object)
コード例 #8
0
 def add_physicalvolume(self, ip, x_api_session, ssp_object,
                        physicalvolume_object):
     """
     adds a physical volume to the selected ssp
     Args:
         ip:ip address of hmc
         x_api_session:session to be used
         ssp_object:shared storage pool object to be modified
         physicalvolume_object:physical volume object to be added to shared storage pool
     """
     log.log_debug("add physical volume to ssp invoked")
     ssp_uuid = ssp_object.Metadata.Atom.AtomID.value()
     ssp_object.PhysicalVolumes.PhysicalVolume.append(physicalvolume_object)
     xml = ssp_object.toxml()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, x_api_session)
     http_object.HTTPPost(xml, append=ssp_uuid)
     log.log_debug("response of adding a physical volume to ssp -- %s" %
                   (http_object.response))
     if http_object.response_b:
         print(
             "\nPhysicalVolume added to the SharedStoragePool Successfully")
         log.log_debug(
             "PhysicalVolume added to the SharedStoragePool Successfully")
     else:
         log.log_error(
             "\nVerify whether the physical volume tried to add is free.")
コード例 #9
0
 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
コード例 #10
0
 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."
         )
コード例 #11
0
    def get_job_status(self, http_object):
            """
            performs the get of job status and verifies whether
            the job request is completetd successfully
            Args:
              http_object : HTTP Request object of a job request
            """
            

            root = etree.fromstring(http_object.response.content)
            job_id = root.findall(".//{%s}JobID"%(self.ns))[0].text
            http_job_object = HTTPClient.HTTPClient("uom", self.ip,
                                                "jobs", self.content_type,
                                                self.session )
            job_status = " "
            print("Processing...")
            while job_status != "COMPLETED_OK" or job_status != "COMPLETED_WITH_WARNINGS":
                http_job_object.HTTPGet(append=job_id)
                if http_job_object.response_b:
                    root = etree.fromstring(http_job_object.response.content)
                    job_status = root.findall(".//{%s}Status"%(self.ns))[0].text
                    if job_status == "FAILED_BEFORE_COMPLETION" or job_status == "COMPLETED_WITH_ERROR":
                        try:
                            error = root.findall(".//{%s}Message"%(self.ns))[0].text
                            log.log_error(error)
                        except IndexError:
                            log.log_error("An error occured while performing job request")
                        break
            print("Job Status :",job_status)
コード例 #12
0
 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)
コード例 #13
0
 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")
コード例 #14
0
    def get_processedmetrics(self):
        """
        Downloads the json files for ManagedSystem and LogicalPartition
        """

        choice = "y"
        try:
            while choice == "y":
                HTTP_object = HTTPClient.HTTPClient(self.service, self.ip,
                                                    self.root,
                                                    self.content_type,
                                                    self.x_api_session)
                # Make a get request for processedmetrics
                HTTP_object.HTTPGet(append=self.managedsystem_id +
                                    "/ProcessedMetrics")
                if not HTTP_object.response_b:
                    log_object.log_warn("Long Term Monitor not Enabled\n")
                    return
                # The response of the get request is parsed using feedparser
                feedparser_processed_metrics = feedparser.parse(
                    HTTP_object.response.text)
                print(
                    "Processed Metrics: Downloads the json files for the ManagedSystem and Logicalpartitions available in the ManagaedSystem"
                )
                self.json_download_managedsystem(HTTP_object,
                                                 feedparser_processed_metrics)
                self.json_download_logicalpartitions(
                    HTTP_object, feedparser_processed_metrics)

                print("Sleeps for 30 seconds")
                time.sleep(30)
                print("Refreshing after 30 seconds")
        except KeyboardInterrupt:
            return
コード例 #15
0
 def add_node(self, ip, x_api_session, cluster_object, vios_id):
     """
     Args:
         ip: ip address of hmc
         x_api_session: session to be used for adding a node
         cluster_object:cluster object into which the node is to be added
         vios_id:UUID of the vios to be added
     """
     log.log_debug("adding a node to a cluster process starting")
     link = "https://" + ip + ":12443/rest/api/uom/VirtualIOServer/" + vios_id
     log.log_debug("vios to be added to the cluster -- %s" % (link))
     node_object = UOM.Node()
     node_object.HostName = NODE_HOST_NAME
     node_object.VirtualIOServer = pyxb.BIND()
     node_object.VirtualIOServer.href = link
     node_object.VirtualIOServer.rel = "related"
     node_object.schemaVersion = SCHEMA_VER
     cluster_object.Node.schemaVersion = SCHEMA_VER
     cluster_object.Node.Node.append(node_object)
     cluster_xml = cluster_object.toxml()
     cluster_id = cluster_object.Metadata.Atom.AtomID.value()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, x_api_session)
     http_object.HTTPPost(cluster_xml, append=cluster_id)
     log.log_debug("response for adding a node to cluster --- %s" %
                   (http_object.response))
     if http_object.response_b:
         print("Node is added to the cluster successfully")
         log.log_debug("node added successfully")
     else:
         log.log_error("Error occured while adding a node to the cluster")
コード例 #16
0
 def get_longtermmonitor(self,object_list):
     '''
     This function collects the long term monitor metrics of the HMC
     '''
     choice="y"
     while choice=="y":
             flag = 6
             HTTP_object =HTTPClient.HTTPClient(self.service, self.ip, self.root, self.content_type, self.x_api_session)
             # Make a get request for Long Term Monitor
             HTTP_object.HTTPGet(append=self.managedsystem_id+"/RawMetrics/LongTermMonitor")
             if not HTTP_object.response_b:
                 log_object.log_warn("Long Term Monitor not Enabled\n")
                 return
             # The response of the get request is parsed using feedparser
             feedparser_LTM = feedparser.parse(HTTP_object.response.text)
             print("\n*******Options for Long Term Monitor Metrics*********\n")
             option = input("This happens in a loop that repeats every 30 seconds \n 1.Download all the available json files \n 2.Download the recently generated json files \n 3.quit\n choose an option: ")
             if option=="1":
                 flag = self.json_download_all_files(HTTP_object,feedparser_LTM,object_list)
                 if flag == 5:
                     continue
                 elif flag == 6:
                     print("Sleeps for 30 seconds")
                     time.sleep(30)
                     print("Refreshing after 30 seconds")
             elif option=="2":
                 self.json_download_recent_files_phyp(HTTP_object,feedparser_LTM,object_list)
                 #print(object_list)
                 self.json_download_recent_files_vios(HTTP_object,feedparser_LTM,object_list)
                 print("Sleeps for 30 seconds")
                 time.sleep(30)
                 print("Refreshing after 30 seconds")
             elif option == "3":
                 choice = "n"
コード例 #17
0
 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
コード例 #18
0
 def change_sriov_adaptermode(self, ip, managedsystem_uuid, adapter_object,
                              x_api_session):
     """
     Changes the adapter mode from shared to dedicated and dedicated to shared
     Args:
         ip : ip address of HMC
         managedsystem_uuid : UUID of the Managedsystem
         adapter_object : object of SRIOV Adapter to change the mode
         x_api_session : session to be used
     """
     super().__init__(ip, self.root, self.content_type, x_api_session)
     directory = os.path.dirname(__file__)
     adapter_id = adapter_object.AdapterID.value()
     if adapter_object.AdapterMode == "Dedicated":
         xml = open(directory +
                    "/data/dedicated_to_shared_adaptermode.xml").read()
     else:
         xml = open(directory +
                    "/data/shared_to_dedicated_adaptermode.xml").read()
     xml = xml % (adapter_id)
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, x_api_session)
     http_object.HTTPPut(xml,
                         append="/" + managedsystem_uuid +
                         "/do/ModifySRIOVAdapterMode")
     if http_object.response_b:
         self.get_job_status(http_object)
コード例 #19
0
 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)
コード例 #20
0
 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
コード例 #21
0
 def __init__(self, ip, x_api_session):
     self.service = 'web'
     self.root = 'Logon'
     self.content_type = 'application/vnd.ibm.powervm.web+xml'
     # PERFORMS HTTP DELETE METHOD USING CURRENT X_API_SESSION
     request_object = HTTPClient.HTTPClient(self.service, ip, self.root,
                                            self.content_type,
                                            x_api_session)
     request_object.HTTPDelete()
     # PRINTS THE STATUS MESSAGE FOR DELETE METHOD
     print("Logoff Successful!!!")
コード例 #22
0
    def set_managedsystempcmpreference(self):
        ''' This function is used to set/update the existing PCM Preferences of the Managed System '''

        get_managedsystempcmpreference_object1 = self.get_managedsystempcmpreference(
        )
        pyxb.RequireValidWhenGenerating(True)
        print("options for set/update Managed System Pcm Preferences \n")
        option = eval(
            input(
                " Choose an option \n 1.ComputeLTM \n 2.ComputeLTM + Long term monitor \n 3.ComputeLTM + Long term monitor + AggregationEnabled \n"
            ))

        if option == "1":
            get_managedsystempcmpreference_object1.ComputeLTMEnabled = "true"
            get_managedsystempcmpreference_object1.ComputeLTMEnabled.ksv = "V1_1_0"

            get_managedsystempcmpreference_object1.AggregationEnabled = "false"
            get_managedsystempcmpreference_object1.LongTermMonitorEnabled = "false"

        elif option == "2":
            get_managedsystempcmpreference_object1.LongTermMonitorEnabled = "true"
            get_managedsystempcmpreference_object1.ComputeLTMEnabled = "true"
            get_managedsystempcmpreference_object1.ComputeLTMEnabled.ksv = "V1_1_0"

            get_managedsystempcmpreference_object1.LongTermMonitorEnabled = "false"

        elif option == "3":
            get_managedsystempcmpreference_object1.AggregationEnabled = "true"
            get_managedsystempcmpreference_object1.LongTermMonitorEnabled = "true"
            get_managedsystempcmpreference_object1.ComputeLTMEnabled = "true"
            get_managedsystempcmpreference_object1.ComputeLTMEnabled.ksv = "V1_1_0"

        short_term_monitor = eval(
            input("do u want to enable ShortTermMonitorEnabled ? y/n\n"))
        if short_term_monitor == "y":
            get_managedsystempcmpreference_object1.ShortTermMonitorEnabled = "true"
        else:
            get_managedsystempcmpreference_object1.ShortTermMonitorEnabled = "false"

        # genarating the xml request body for the post reqeust by using ToXml method
        post_payload = ToXml.ToXml(get_managedsystempcmpreference_object1)
        HTTP_object = HTTPClient.HTTPClient(self.service, self.ip, self.root,
                                            "application/xml",
                                            self.x_api_session)
        # perform the post request for managed system pcm preferences
        HTTP_object.HTTPPost(post_payload,
                             append=self.managedsystem_id + "/preferences")
        log_object.log_debug(
            "response code for set_managedsystempcmpreference %s" %
            (HTTP_object.response))
        if HTTP_object.response.status_code == 200:
            self.print_managedsystempcmpreference(
                get_managedsystempcmpreference_object1)
コード例 #23
0
def sendrequest(xml, ip, root, content_type, x_api_session, vios_uuid,
                volumegroup_id):
    """
        performs the HTTPPost request with modified volume group
        """
    http_object = HTTPClient.HTTPClient("uom", ip, root, content_type,
                                        x_api_session)
    http_object.HTTPPost(xml,
                         append=vios_uuid + "/VolumeGroup/" + volumegroup_id)
    if http_object.response_b:
        return True
    else:
        return False
コード例 #24
0
    def __init__(self, ip, x_api_session, managedsystem_uuid):
        """
        Creates HTTP Request object to perform Remove Connection operation
        Args:
          ip : ip address of HMC
          x_api_session : session to be used
          managedsystem_uuid : UUID of managedsystem to remove connection
        """

        self.managedsystem_uuid = managedsystem_uuid
        self.request_obj = HTTPClient.HTTPClient(
            'uom',
            ip,
            'ManagedSystem',
            content_type='application/vnd.ibm.powervm.web+xml; type=JobRequest',
            session_id=x_api_session)
コード例 #25
0
 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")
コード例 #26
0
    def get_managedsystempcmpreference(self):
        ''' This function is used to get the PCM Preferences of the Managed System '''

        HTTP_object = HTTPClient.HTTPClient(
            self.service, self.ip, self.root,
            "application/vnd.ibm.powervm.pcm.xml", self.x_api_session)
        # perform the get request for Managed System Pcm Preferences
        HTTP_object.HTTPGet(append=self.managedsystem_id + "/preferences")
        log_object.log_debug(
            "response code for get_managedsystempcmpreference %s" %
            (HTTP_object.response))
        response_content = HTTP_object.response.text
        xml = CreateFromDocument.xpath(response_content)
        # Create the python object using CreateFromDocument function
        get_managedsystempcmpreference_object = ManagedSystemPcmPreferences.CreateFromDocument(
            xml)
        # Return the above created object to the main program
        return get_managedsystempcmpreference_object
コード例 #27
0
 def delete_cluster(self, ip, cluster_id, x_api_session):
     """
     Args:
         ip:represents the ip address
         cluster_id:UUID of the cluster to be deleted
         x_api_session:session to be used for request
     
     """
     super().__init__(ip, self.root, self.content_type, x_api_session)
     log.log_debug("Invoking delete cluster")
     header_object = HmcHeaders.HmcHeaders("web")
     ns = header_object.ns["xmlns"]
     directory = os.path.dirname(__file__)
     xml = open(directory+"/data/delete_cluster.xml").read()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root, self.content_type, x_api_session)
     http_object.HTTPPut(xml,append=cluster_id+"/do/Delete")
     log.log_debug("HTTP response for deleting cluster -- %s"%(http_object.response))
     if http_object.response_b:
        self.get_job_status(http_object)
コード例 #28
0
 def create_virtualswitch(self, ip, managedsystem_uuid, x_api_session):
     """
     Args:
         ip:ip address of hmc
         managedsystem_uuid:UUID of managedsystem
         x_api_session:session to be used
     """
     log.log_debug("creation of virtual switch started")
     pyxb.RequireValidWhenGenerating(True)
     virtualswitch_object = UOM.VirtualSwitch()
     virtualswitch_object.schemaVersion = SCHEMA_VER
     virtualswitch_object.SwitchName = SWITCH_NAME
     xml = virtualswitch_object.toxml()
     http_object = HTTPClient.HTTPClient("uom",ip,self.root,self.content_type,x_api_session)
     http_object.HTTPPut(xml,append=managedsystem_uuid+"/VirtualSwitch")
     log.log_debug("response for creation of virtual switch -- %s"%(http_object.response))
     if http_object.response_b:
         return True
     else:
         return False
コード例 #29
0
 def create_logicalunit(self, ip, x_api_session, cluster_object):
     """
     Args:
         ip:represents the ip address
         x_api_session:session to be used for request
         cluster_object:Cluster object for which logical unit to be created
     """
     super().__init__(ip, self.root, self.content_type, x_api_session)
     log.log_debug("Invoking create logical unit")
     directory = os.path.dirname(__file__)
     xml = open(directory + "/data/create_logicalunit.xml").read() % (
         UNIT_NAME, UNIT_SIZE, UNIT_TYPE)
     cluster_id = cluster_object.Metadata.Atom.AtomID.value()
     http_object = HTTPClient.HTTPClient("uom", ip, self.root,
                                         self.content_type, x_api_session)
     http_object.HTTPPut(xml, append=cluster_id + "/do/CreateLogicalUnit")
     log.log_debug("Response of create logical unit -- %s" %
                   (http_object.response))
     if http_object.response_b:
         self.get_job_status(http_object)
コード例 #30
0
 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")