示例#1
0
    def add_mdisk(self, instance_name, diskpool, vdev, size, fmt=None):
        """Add a 3390 mdisk for a z/VM user.
    
        NOTE: No read, write and multi password specified, and
        access mode default as 'MR'.
    
        """
        disk_type = CONF.zvm_diskpool_type
        if (disk_type == 'ECKD'):
            action = '--add3390'
        elif (disk_type == 'FBA'):
            action = '--add9336'
        else:
            errmsg = ("Disk type %s is not supported.") % disk_type
            LOG.error(errmsg)
            raise ZVMException(msg=errmsg)

        if fmt:
            body = [
                " ".join([
                    action, diskpool, vdev, size, "MR", "''", "''", "''", fmt
                ])
            ]
        else:
            body = [" ".join([action, diskpool, vdev, size])]
        url = zvmutils.get_xcat_url().chvm('/' + instance_name)
        zvmutils.xcat_request("PUT", url, body)
示例#2
0
def delete_volume(volume_uuid):
    """Delete a volume.

    Input parameters:
    :volume_uuid:    volume uuid in zVM
    """
    volumeops = _get_volumeops()
    volume_info = volumeops.get_volume_info(volume_uuid)
    # Check volume status
    if (volume_info is None):
        msg = ("Volume %s does not exist.") % volume_uuid
        raise zvmutils.ZVMException(msg)
    if (volume_info['status'] == 'in-use'):
        msg = ("Cann't delete volume %(uuid)s, attached to "
               "instance %(vm)s" % {
                   'uuid': volume_uuid,
                   'vm': volume_info['userid']
               })
        raise zvmutils.ZVMException(msg)
    # Delete volume from volume manager user
    action = '--removedisk'
    vdev = volume_uuid
    body = [" ".join([action, vdev])]
    url = zvmutils.get_xcat_url().chvm('/' + CONF.volume_mgr_node)
    zvmutils.xcat_request("PUT", url, body)
    # Delete volume from volume management file
    volumeops.delete_volume_info(volume_uuid)
示例#3
0
    def create_userid(self, instance_name, cpu, memory, image_name):
        """Create z/VM userid into user directory for a z/VM instance."""
        LOG.debug("Creating the z/VM user entry for instance %s" %
                  instance_name)

        kwprofile = 'profile=%s' % const.ZVM_USER_PROFILE
        body = [
            kwprofile,
            'password=%s' % CONF.zvm_user_default_password,
            'cpu=%i' % cpu,
            'memory=%im' % memory,
            'privilege=%s' % const.ZVM_USER_DEFAULT_PRIVILEGE,
            'ipl=%s' % CONF.zvm_user_root_vdev,
            'imagename=%s' % image_name
        ]

        url = zvmutils.get_xcat_url().mkvm('/' + instance_name)

        try:
            zvmutils.xcat_request("POST", url, body)
            size = CONF.root_disk_units
            # Add root disk and set ipl
            self.add_mdisk(instance_name, CONF.zvm_diskpool,
                           CONF.zvm_user_root_vdev, size)
            self.set_ipl(instance_name, CONF.zvm_user_root_vdev)

        except Exception as err:
            msg = ("Failed to create z/VM userid: %s") % err
            LOG.error(msg)
            raise ZVMException(msg=err)
示例#4
0
def create_volume(size):
    """Create a volume.

    Input parameters:
    :size:           size

    Output parameters:
    :volume_uuid:    volume uuid in zVM
    """
    volumeops = _get_volumeops()
    volume_uuid = ""

    action = '--add9336'
    diskpool = CONF.volume_diskpool
    vdev = volumeops.get_free_mgr_vdev()
    multipass = const.VOLUME_MULTI_PASS
    fmt = CONF.volume_filesystem
    body = [
        " ".join([
            action, diskpool, vdev,
            str(size), "MR", "read", "write", multipass, fmt
        ])
    ]
    url = zvmutils.get_xcat_url().chvm('/' + CONF.volume_mgr_node)
    # Update the volume management file before sending xcat request
    volumeops.add_volume_info(" ".join(
        [vdev, "free", CONF.volume_mgr_userid, vdev]))
    zvmutils.xcat_request("PUT", url, body)
    volume_uuid = vdev
    return volume_uuid
示例#5
0
 def delete_xcat_node(self, instance_name):
     """Remove xCAT node for z/VM instance."""
     url = self._xcat_url.rmdef('/' + instance_name)
     try:
         zvmutils.xcat_request("DELETE", url)
     except Exception as err:
         if err.format_message().__contains__("Could not find an object"):
             # The xCAT node not exist
             return
         else:
             raise err
示例#6
0
 def _delete_userid(self, url):
     try:
         zvmutils.xcat_request("DELETE", url)
     except Exception as err:
         emsg = err.format_message()
         LOG.debug("error emsg in delete_userid: %s", emsg)
         if (emsg.__contains__("Return Code: 400")
                 and emsg.__contains__("Reason Code: 4")):
             # zVM user definition not found, delete xCAT node directly
             self.delete_xcat_node()
         else:
             raise
示例#7
0
    def delete_image(self, image_name):
        """"Invoke xCAT REST API to delete a image."""
        url = self._xcat_url.rmimage('/' + image_name)
        try:
            zvmutils.xcat_request("DELETE", url)
        except zvmutils.ZVMException:
            LOG.warn(("Failed to delete image file %s from xCAT") % image_name)

        url = self._xcat_url.rmobject('/' + image_name)
        try:
            zvmutils.xcat_request("DELETE", url)
        except zvmutils.ZVMException:
            LOG.warn(("Failed to delete image definition %s from xCAT") %
                     image_name)
        LOG.info('Image %s successfully deleted' % image_name)
示例#8
0
    def list_instances(self):
        """Return the names of all the instances known to the virtualization
        layer, as a list.
        """
        zvm_host = CONF.zvm_host
        hcp_base = CONF.zhcp

        url = self._xcat_url.tabdump("/zvm")
        res_dict = zvmutils.xcat_request("GET", url)

        instances = []

        with zvmutils.expect_invalid_xcat_resp_data(res_dict):
            data_entries = res_dict['data'][0][1:]
            for data in data_entries:
                l = data.split(",")
                node, hcp = l[0].strip("\""), l[1].strip("\"")
                hcp_short = hcp_base.partition('.')[0]

                # zvm host and zhcp are not included in the list
                if (hcp.upper() == hcp_base.upper() and node.upper()
                        not in (zvm_host.upper(), hcp_short.upper(),
                                CONF.zvm_xcat_master.upper())):
                    instances.append(node)

        return instances
示例#9
0
 def capture_instance(self, instance_name):
     """Invoke xCAT REST API to capture a instance."""
     LOG.info('Begin to capture instance %s' % instance_name)
     url = self._xcat_url.capture()
     nodename = instance_name
     image_id = str(uuid.uuid1())
     image_uuid = image_id.replace('-', '_')
     profile = image_uuid
     body = ['nodename=' + nodename, 'profile=' + profile]
     res = zvmutils.xcat_request("POST", url, body)
     LOG.info(res['info'][3][0])
     image_name = res['info'][3][0].split('(')[1].split(')')[0]
     return image_name
示例#10
0
    def is_reachable(self, instance_name):
        """Return True is the instance is reachable."""
        url = self._xcat_url.nodestat('/' + instance_name)
        LOG.debug('Get instance status of %s', instance_name)
        res_dict = zvmutils.xcat_request("GET", url)

        with zvmutils.expect_invalid_xcat_resp_data(res_dict):
            status = res_dict['node'][0][0]['data'][0]

        if status is not None:
            if status.__contains__('sshd'):
                return True

        return False
示例#11
0
 def set_ipl(self, instance_name, ipl_state):
     body = ["--setipl %s" % ipl_state]
     url = zvmutils.get_xcat_url().chvm('/' + instance_name)
     zvmutils.xcat_request("PUT", url, body)
示例#12
0
 def _lsvm(self, instance_name):
     url = self._xcat_url.lsvm('/' + instance_name)
     resp_info = zvmutils.xcat_request("GET", url)['info'][0][0]
     return resp_info.split('\n')
示例#13
0
 def _lsdef(self, instance_name):
     url = self._xcat_url.lsdef_node('/' + instance_name)
     resp_info = zvmutils.xcat_request("GET", url)['info'][0]
     return resp_info
示例#14
0
 def _power_state(self, instance_name, method, state):
     """Invoke xCAT REST API to set/get power state for a instance."""
     body = [state]
     url = self._xcat_url.rpower('/' + instance_name)
     return zvmutils.xcat_request(method, url, body)