Esempio n. 1
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)
Esempio n. 2
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")