CN115963990A - Terraform-based cloud host disk capacity expansion method and system - Google Patents

Terraform-based cloud host disk capacity expansion method and system Download PDF

Info

Publication number
CN115963990A
CN115963990A CN202211614815.XA CN202211614815A CN115963990A CN 115963990 A CN115963990 A CN 115963990A CN 202211614815 A CN202211614815 A CN 202211614815A CN 115963990 A CN115963990 A CN 115963990A
Authority
CN
China
Prior art keywords
volume
cloud host
capacity expansion
expansion
disk
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211614815.XA
Other languages
Chinese (zh)
Inventor
李承林
徐士强
王禹博
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Cloud Information Technology Co Ltd
Original Assignee
Inspur Cloud Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Cloud Information Technology Co Ltd filed Critical Inspur Cloud Information Technology Co Ltd
Priority to CN202211614815.XA priority Critical patent/CN115963990A/en
Publication of CN115963990A publication Critical patent/CN115963990A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and a system for expanding a disk of a cloud host based on Terraform, belongs to the technical field of cloud computing and virtual machines, and aims to solve the technical problem of meeting the requirement of disk space expansion on the premise of reducing operation and maintenance cost, wherein the technical scheme is as follows: the method comprises the steps that a Terraform is used for calling an API of an OpenStack through a provider plug-in to conveniently manage a cloud host, the Terraform related plug-ins and the API calls of various OpenStack are packaged into a factory method, and the expansion of a disk of the cloud host including a system disk is completed; the method comprises the following specific steps: s1, starting capacity expansion of a cloud host, and executing the step S2; s2, judging whether the disk supports the LVM: (1) if yes, executing step S3; (2) if not, executing the step S4; s3, executing longitudinal expansion, and executing the step S5; s4, performing transverse capacity expansion, and performing the step S5; s5, judging whether the capacity expansion is successful: (1) if yes, ending the capacity expansion; (2) and if not, rolling back.

Description

Terraform-based cloud host disk capacity expansion method and system
Technical Field
The invention relates to the technical field of cloud computing and virtualization, in particular to a method and a system for expanding a cloud host disk based on Terraform.
Background
In a cloud environment, most products such as a cloud host are virtual machine images, and virtual machines are created through Openstack to provide corresponding services. With the lapse of time, the situation that the virtual machine space is full is inevitable, if the virtual machine has a data disk, the requirement can be met by expanding the data disk form, but if the virtual machine has only one system disk, the capacity expansion of the system disk may need manual intervention, and the operation and maintenance cost is increased. The Terraform can manage the cloud host, so that the virtual machine can be created and maintained more conveniently and freely, but the capacity expansion requirement of a system disk cannot be met well by the function of the existing Terraform.
Therefore, how to satisfy the requirement of disk space expansion on the premise of reducing the operation and maintenance cost is a technical problem to be urgently solved.
Disclosure of Invention
The technical task of the invention is to provide a method and a system for expanding the disk of a cloud host based on Terraform, so as to solve the problem of meeting the requirement of disk space expansion on the premise of reducing operation and maintenance cost.
The technical task of the invention is realized according to the following mode, the method for expanding the disk of the cloud host based on the Terraform is characterized in that the Terraform is utilized to call the API of the OpenStack through a provider plug-in to conveniently manage the cloud host, and the relevant plug-ins of the Terraform and the API calls of various OpenStack are packaged into a factory method, including virtual machine creation, startup and shutdown, deletion, restart, volume expansion and ansile execution, so that the disk expansion of the cloud host including a system disk is completed; the method comprises the following specific steps:
s1, starting capacity expansion of a cloud host, and executing the step S2;
s2, judging whether the disk supports the LVM:
(1) if yes, executing step S3;
(2) if not, executing the step S4;
s3, executing longitudinal expansion, and executing the step S5;
s4, performing transverse capacity expansion, and performing the step S5;
s5, judging whether the capacity expansion is successful:
(1) if yes, finishing the capacity expansion;
(2) if not, rolling back.
Preferably, the longitudinal expansion in step S3 is specifically as follows:
s301, creating a new volume with a specified size through volume _ extend operation of a factory, and judging whether a volume is created and the volume size is consistent with the size to be expanded:
(1) if the new volume is successfully created, and the step S2 is executed next;
(2) if the failure occurs, returning corresponding error information, deleting the established abnormal resources and simultaneously stopping the service;
s302, after the new volume is successfully created, mounting the new volume to the target cloud host through the volume _ attributes operation of the factory, and judging whether the mounting of the volume by the target cloud host is successful:
(1) if the volume is successfully mounted, the expansion is basically completed, and the step S3 is executed next;
(2) if the mount of the volume fails, the volume is directly deleted because the volume has no invasion to the original cloud host, so that the rollback of the service is realized, and meanwhile, corresponding error information is returned and the service is stopped;
s303, after the volume is mounted, the factory executes an infrastructure script through remote-exec, performs LVM partition operation on the new mounted volume, and judges whether the execution of the infrastructure script is successful:
(1) if the Ansible script is successfully executed, the longitudinal expansion is successful, and at the moment, the cloud host executes the lsblk instruction and the df-h instruction to find that the expansion of the disk of the cloud host is successful;
(2) if the execution of the Ansible script fails, executing the step S4;
s304, judging whether to delete the new volume:
(1) if yes, deleting the volume and performing rollback service;
(2) and if not, reserving the created volume, and performing the corresponding script in the cloud host offline.
Preferably, the LVM partition operations include creating a physical volume, joining a volume group, expanding a logical volume, and refreshing a file system.
Preferably, during the longitudinal capacity expansion operation, when the user name and the password of the cloud host for performing the LVM operation cannot be acquired, the LVM execution script and the monitoring program are built in the cloud host in advance, and when the built-in LVM execution script and the monitoring program find that a new volume is mounted, the corresponding LVM instruction is automatically executed, and finally the capacity expansion operation of the system disk is completed.
As the preselection, the lateral expansion in step S4 is specifically as follows:
s401, performing shutdown operation on the cloud host through a factory, wherein the cloud host needs to be in a shutdown state due to subsequent operations such as data backup and volume state resetting, and therefore polling operation is needed to determine whether the state of the cloud host is SHUTOFF:
(1) if the shutdown is successful, executing step S402;
(2) if the cloud host is shut down, capacity expansion fails, namely the state of the cloud host is abnormal, automatic recovery may not be achieved, alarm information needs to be sent to a certain degree, meanwhile, business is stopped, manual intervention is carried out, the reason for abnormal state of the cloud host is checked, and capacity expansion operation is carried out after the state of the virtual host is recovered;
s402, the factory makes mirror image snapshots on the cloud host to perform data backup, data loss after capacity expansion failure caused by other factors in subsequent operations is avoided, and whether backup is successful is judged:
(1) if the backup fails, the capacity expansion fails;
(2) if the backup is successful, executing step S403;
s403, the factory has operation for disk capacity expansion, but if the capacity expansion target is a system disk, direct capacity expansion fails because the volume state is in-use, and therefore before capacity expansion, the volume state is reset through the factory, and the volume state is polled:
(1) when the volume state is available, executing step S404;
(2) when the volume state is abnormal, indicating that the capacity expansion fails, stopping the service, alarming and manually intervening;
s404, updating the volume size, namely expanding the target volume through a factory, and judging whether the expansion is successful:
(1) if the capacity expansion is successful, executing step S405;
(2) if the capacity expansion fails, the service is stopped; if the volume state is abnormal and cannot be recovered, reconstructing the volume according to the data which is backed up in the step S2 and executing mounting operation;
s405, after capacity expansion is successful, starting up the cloud host through a factory, automatically changing the volume state into in-use at the moment, and finishing the capacity expansion of the transverse system disk after the cloud host state is changed into operation; at the moment, the entering of the cloud host computer can find that the disk expansion of the cloud host computer is successful by executing the lsblk instruction and the df-h instruction.
A cloud host disk capacity expansion system based on Terraform combines the APIs of Terraform and Openstack, and the automatic cloud configuration is improved to a new height through terrform init, terrform plan and terrform application; the Terraform calls an Openstack Api through a provider plug-in to conveniently manage the cloud host, and the Terraform related plug-in and various Openstack apis are called and packaged into a factory method to complete expansion of a cloud host system disk; the system comprises a first judging unit, a longitudinal capacity expansion unit, a transverse capacity expansion unit and a second judging unit;
the first judging unit is used for judging whether the disk supports the LVM:
the longitudinal capacity expansion unit is used for executing longitudinal capacity expansion;
the transverse capacity expansion unit is used for executing transverse capacity expansion;
the second judging unit is used for judging whether the capacity expansion is successful.
Preferably, the longitudinal expansion unit comprises,
the volume creating and judging module is used for creating a new volume with a specified size through the volume _ extend operation of a factory and judging whether a volume is created or not and the volume size is consistent with the volume to be expanded;
the volume mounting and judging module is used for mounting the new volume to the target cloud host through the volume _ attributes operation of the factory and judging whether the target cloud host successfully mounts the volume;
the partition and judgment module is used for executing the Ansine script through remote-exec, performing LVM partition operation on the new mount volume and judging whether the Ansine script is executed successfully;
and the judging module is used for judging whether to delete the new volume.
Preferably, the lateral expansion unit includes,
the shutdown and judgment module is used for performing shutdown operation on the cloud host through a factory, and whether the state of the cloud host is SHUTOFF or not is determined by polling operation because subsequent operations such as data backup and volume resetting need to be performed when the cloud host is in a shutdown state;
the backup and judgment module is used for carrying out mirror image snapshot on the cloud host through a factory to carry out data backup, avoiding data loss after capacity expansion failure caused by other factors in subsequent operation and judging whether the backup is successful or not;
the resetting and polling module is used for resetting the volume state through a factory and polling the volume state;
the volume updating and capacity expanding judging module is used for updating the volume size, namely, expanding the capacity of the target volume through a factory and judging whether the capacity expansion is successful or not;
the system comprises a starting module, a volume module and a volume expansion module, wherein the starting module is used for starting the cloud host through a factory, the volume state can be automatically changed into in-use at the moment, and after the state of the cloud host is changed into operation, the volume expansion of a transverse system disk is completed; at this time, the cloud host executes the lsblk instruction and the df-h instruction to find that the disk expansion of the cloud host is successful.
An electronic device, comprising: a memory and at least one processor;
wherein the memory stores computer execution instructions;
the at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the Terraform-based cloud host disk expansion method as described above.
A computer-readable storage medium, in which computer execution instructions are stored, and when a processor executes the computer, the method for expanding the disk capacity of the cloud host based on terrafrorm is implemented.
The LVM is a logical volume management, which is a mechanism for managing a disk partition in a Linux environment, and is a logical layer established above a hard disk and a partition and below a file system, so that the flexibility of disk partition management can be improved. The LVM partition can expand the storage space without unloading the original hard disk. Therefore, if the disk supports the LVM partition, the capacity expansion is very convenient, but if the disk does not support the LVM partition, the capacity expansion needs to be carried out on the basis of the original disk.
The cloud host disk capacity expansion method and system based on Terraform have the following advantages:
the method combines Terraform and Openstack api, and can improve automatic cloud configuration to a new height through three steps of Terraform init, terraform plan and Terraform application;
all operations of the cloud host computer are based on Terraform and Openstack api. The Terraform can call the Api of the Openstack through the provider plug-in to conveniently manage the cloud host, so that the Terraform related plug-in and various Openstack Api calls can be packaged into a factory method, such as virtual machine creation, startup and shutdown, deletion, restart, volume creation, volume expansion, ansile execution and the like, and subsequent use is facilitated.
Thirdly, because the Terraform cannot feed back the state of the resource in real time, the state of the target resource is acquired in an interface polling mode in the process of executing various operations, so that whether the next operation needs to be executed or not is determined;
the method has the advantages that the capacity of all the disks including the system disk can be expanded without entering the cloud host to execute any script and command during the transverse capacity expansion, and an account and a password of the cloud host with certain operation authority do not need to be acquired; when the cloud host disk supports the LVM, a transverse capacity expansion mode can be adopted, the two modes can be used alternately, the system disk can be used in a longitudinal capacity expansion mode, the data disk can be used in a transverse capacity expansion mode, the specific mode can be distinguished according to different service scenes, and in order to avoid abnormal probability, capacity expansion operation on one disk by using the two modes is avoided as much as possible;
the invention provides two expansion flows aiming at whether the disk supports the LVM, and can realize disk expansion of various scenes including a system disk. In the two modes, manual intervention is only needed when abnormal scenes such as incapability of automatic recovery, incapability of normal starting of a cloud host, failure of hanging a volume and the like occur.
The method for expanding the OpenStack virtual machine disk based on Terraform can adapt to the development of cloud computing, and has good popularization and application values;
the invention improves the automation degree of expansion: all operations can be operated on line without much manual intervention;
the invention improves the flexibility of capacity expansion: the two expansion modes of transverse expansion and longitudinal expansion can be used independently or alternatively, and are suitable for various expansion scenes;
the invention improves the safety of capacity expansion: the two expansion modes of horizontal expansion and longitudinal expansion can ensure that data is not lost in the expansion process;
the invention simplifies the operation process, reduces the operation and maintenance cost and reduces the manual intervention by combining Terraform with Openstack api to expand the cloud host.
Drawings
The invention is further described below with reference to the accompanying drawings.
Fig. 1 is a flow chart of a cloud host disk capacity expansion method based on Terraform;
FIG. 2 is a block diagram of a process for longitudinal expansion;
FIG. 3 is a block diagram of a process for lateral expansion.
Detailed Description
The method and system for cloud host disk capacity expansion based on terrafrorm according to the present invention are described in detail below with reference to the drawings and specific embodiments of the specification.
Example 1:
as shown in fig. 1, this embodiment provides a method for expanding a disk of a cloud host based on terrafrorm, where the method is to utilize terrafrorm to call an API of an OpenStack through a provider plug-in to conveniently manage the cloud host, and package a related plug-in of terraflorm and various API calls of OpenStack into a factory method, including creating a virtual machine, turning on and off a machine, deleting, restarting, creating a volume, expanding the volume, executing an encrypted, and completing disk expansion of the cloud host including a system disk; the method comprises the following specific steps:
s1, starting capacity expansion of a cloud host, and executing the step S2;
s2, judging whether the disk supports the LVM:
(1) if yes, executing step S3;
(2) if not, executing the step S4;
s3, executing longitudinal expansion, and executing the step S5;
s4, executing transverse expansion, and executing the step S5;
s5, judging whether the capacity expansion is successful:
(1) if yes, ending the capacity expansion;
(2) and if not, rolling back.
As shown in fig. 2, the longitudinal expansion in step S3 of the present embodiment is specifically as follows:
s301, creating a new volume with a specified size through volume _ extend operation of a factory, and judging whether a volume is created and the volume size is consistent with the size to be expanded:
(1) if the new volume is successfully created, and the step S2 is executed next;
(2) if the failure occurs, returning corresponding error information, deleting the established abnormal resources and simultaneously stopping the service;
s302, after the new volume is successfully created, mounting the new volume to the target cloud host through the volume _ attributes operation of the factory, and judging whether the mounting of the volume by the target cloud host is successful:
(1) if the volume is successfully mounted, the expansion is basically completed, and the step S3 is executed next;
(2) if the mount of the volume fails, the volume is directly deleted because the volume has no invasion to the original cloud host, so that the rollback of the service is realized, and meanwhile, corresponding error information is returned and the service is stopped;
s303, after the volume is mounted, the factory executes an infrastructure script through remote-exec, performs LVM partition operation on the new mounted volume, and judges whether the execution of the infrastructure script is successful:
(1) if the Ansible script is successfully executed, the longitudinal expansion is successful, and at the moment, the cloud host executes the lsblk instruction and the df-h instruction to find that the expansion of the disk of the cloud host is successful;
(2) if the execution of the Ansible script fails, executing the step S4;
s304, judging whether to delete the new volume:
(1) if yes, deleting the volume and performing rollback service;
(2) and if not, reserving the created volume, and performing corresponding script in the cloud host offline.
The LVM partition operation in this embodiment includes creating a physical volume, joining a volume group, expanding a logical volume, and refreshing a file system.
In this embodiment, during the longitudinal capacity expansion operation, when the user name and the password for performing the LVM operation cannot be obtained from the authority of the cloud host, the LVM execution script and the monitoring program are built in the cloud host in advance, and when the built-in LVM execution script and the monitoring program find that a new volume is mounted, the corresponding LVM instruction is automatically executed, and finally the capacity expansion operation of the system disk is completed.
As shown in fig. 3, the horizontal expansion in step S4 of this embodiment is specifically as follows:
s401, performing shutdown operation on the cloud host through a factory, wherein the cloud host needs to be in a shutdown state due to subsequent operations such as data backup and volume state resetting, and therefore polling operation is needed to determine whether the state of the cloud host is SHUTOFF:
(1) if the shutdown is successful, executing step S402;
(2) if the cloud host is shut down, capacity expansion fails, namely the state of the cloud host is abnormal, automatic recovery may not be achieved, alarm information needs to be sent to a certain degree, meanwhile, business is stopped, manual intervention is carried out, the reason for abnormal state of the cloud host is checked, and capacity expansion operation is carried out after the state of the virtual host is recovered;
s402, the factory makes mirror image snapshots on the cloud host to perform data backup, data loss after capacity expansion failure caused by other factors in subsequent operations is avoided, and whether backup is successful is judged:
(1) if the backup fails, the capacity expansion fails;
(2) if the backup is successful, executing step S403;
s403, the factory has operation for disk capacity expansion, but if the capacity expansion target is a system disk, direct capacity expansion fails because the volume state is in-use, and therefore before capacity expansion, the volume state is reset through the factory, and the volume state is polled:
(1) when the volume state is available, executing step S404;
(2) when the volume state is abnormal, indicating that the capacity expansion fails, stopping the service, alarming and manually intervening;
s404, updating the volume size, namely expanding the target volume through the factory, and judging whether the expansion is successful:
(1) if the capacity expansion is successful, executing step S405;
(2) if the capacity expansion fails, the service is stopped; if the volume state is abnormal and cannot be recovered, reconstructing the volume according to the data which is backed up in the step S2 and executing mounting operation;
s405, after capacity expansion is successful, starting up the cloud host through a factory, automatically changing the volume state into in-use at the moment, and finishing the capacity expansion of the transverse system disk after the cloud host state is changed into operation; at this time, the cloud host executes the lsblk instruction and the df-h instruction to find that the disk expansion of the cloud host is successful.
In this embodiment, two modes of longitudinal expansion and transverse expansion are supported according to whether the cloud host supports LVM logical volume management.
The longitudinal capacity expansion essence is that a new volume is added, the Openstack api interface is called through Terraform to create the new volume, the new volume is mounted after the new volume is successfully created, and finally the LVM instruction script is executed in the cloud host, so that the disk capacity expansion of the cloud host supporting the LVM partition mode is realized, the original volume of the cloud host is not invaded, and the data safety is ensured.
The transverse capacity expansion is essentially to expand the original volume, the Openstack api interface is called by Terraform to carry out shutdown, data backup, volume state resetting, volume size updating and startup processes on the cloud host to realize the disk capacity expansion of the cloud host in a non-support LVM partition mode, and the cloud host does not need to enter to execute any operation.
The two expansion modes of longitudinal expansion and transverse expansion can be combined for use, the expansion of a system disk is supported, and the requirements of various expansion service scenes are met.
Example 2:
the embodiment provides a cloud host disk capacity expansion system based on Terraform, which combines APIs of Terraform and Openstack, and promotes automatic cloud configuration to a new height through terrform init, terrform plan and terrform application; the Terraform calls an Openstack Api through a provider plug-in to conveniently manage the cloud host, and the Terraform related plug-in and various Openstack apis are called and packaged into a factory method to complete expansion of a cloud host system disk; the system comprises a first judging unit, a longitudinal capacity expansion unit, a transverse capacity expansion unit and a second judging unit;
the first judging unit is used for judging whether the disk supports the LVM:
the longitudinal capacity expansion unit is used for executing longitudinal capacity expansion;
the transverse capacity expansion unit is used for executing transverse capacity expansion;
the second judging unit is used for judging whether the capacity expansion is successful.
The longitudinal capacity expansion unit in this embodiment comprises,
the volume creating and judging module is used for creating a new volume with a specified size through the volume _ extend operation of a factory and judging whether a volume is created or not and the volume size is consistent with the volume to be expanded;
the volume mounting and judging module is used for mounting the new volume to the target cloud host through the volume _ attributes operation of the factory and judging whether the target cloud host successfully mounts the volume;
the partitioning and judging module is used for executing the Ansine script through remote-exec, performing LVM partitioning operation on the new mounted volume and judging whether the Ansine script is executed successfully;
and the judging module is used for judging whether to delete the new volume.
The lateral capacity expansion unit in this embodiment includes,
the shutdown and judgment module is used for performing shutdown operation on the cloud host through a factory, and whether the state of the cloud host is SHUTOFF or not is determined by polling operation because subsequent operations such as data backup and volume resetting need to be performed when the cloud host is in a shutdown state;
the backup and judgment module is used for carrying out mirror image snapshot on the cloud host through a factory to carry out data backup, avoiding data loss after capacity expansion failure caused by other factors in subsequent operation and judging whether the backup is successful or not;
the resetting and polling module is used for resetting the volume state through a factory and polling the volume state;
the volume updating and capacity expanding judging module is used for updating the volume size, namely, expanding the capacity of the target volume through a factory and judging whether the capacity expansion is successful or not;
the system comprises a starting module, a volume module and a volume expansion module, wherein the starting module is used for starting the cloud host through a factory, the volume state can be automatically changed into in-use at the moment, and after the state of the cloud host is changed into operation, the volume expansion of a transverse system disk is completed; at the moment, the entering of the cloud host computer can find that the disk expansion of the cloud host computer is successful by executing the lsblk instruction and the df-h instruction.
Example 3:
the present embodiment also provides an electronic device, including: a memory and at least one processor;
wherein the memory stores computer execution instructions;
the at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes any of the Terraform-based cloud host disk capacity expansion methods of the present invention.
The processor may be a Central Processing Unit (CPU), but may also be other general purpose processors, digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. The processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory may be used to store computer programs and/or modules, and the processor may implement various functions of the electronic device by executing or executing the computer programs and/or modules stored in the memory and invoking data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the terminal, and the like. In addition, the memory may include high speed random access memory, and may include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a memory card only (SMC), a Secure Digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid state memory device.
Example 4:
the embodiment also provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are loaded by the processor, so that the processor executes the method for expanding the disk capacity of the cloud host based on terrafrorm in any embodiment of the present invention. Specifically, a system or an apparatus equipped with a storage medium on which software program codes that realize the functions of any of the above-described embodiments are stored may be provided, and a computer (or a CPU or MPU) of the system or the apparatus is caused to read out and execute the program codes stored in the storage medium.
In this case, the program code itself read from the storage medium can realize the functions of any of the above-described embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
Examples of the storage medium for supplying the program code include a flexible disk, hard disk, magneto-optical disk, optical disk (e.g., CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD + RW), magnetic tape, nonvolatile memory card, and ROM. Alternatively, the program code may be downloaded from a server computer by a communications network.
Further, it should be clear that the functions of any one of the above-described embodiments may be implemented not only by executing the program code read out by the computer, but also by causing an operating system or the like operating on the computer to perform a part or all of the actual operations based on instructions of the program code.
Further, it is to be understood that the program code read out from the storage medium is written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then a CPU or the like mounted on the expansion board or the expansion unit is caused to perform part or all of the actual operations based on instructions of the program code, thereby realizing the functions of any of the embodiments described above.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A cloud host disk capacity expansion method based on Terraform is characterized in that the method is used for utilizing the Terraform to call APIs of OpenStack through a provider plug-in to conveniently manage a cloud host, and the Terraform related plug-in and the API calls of various OpenStack are packaged into a factory method to complete disk capacity expansion of the cloud host including a system disk; the method comprises the following specific steps:
s1, starting capacity expansion of a cloud host, and executing the step S2;
s2, judging whether the disk supports the LVM:
(1) if yes, executing step S3;
(2) if not, executing the step S4;
s3, executing longitudinal expansion, and executing the step S5;
s4, performing transverse capacity expansion, and performing the step S5;
s5, judging whether the capacity expansion is successful:
(1) if yes, ending the capacity expansion;
(2) and if not, rolling back.
2. The cloud host disk capacity expansion method based on Terraform according to claim 1, wherein the longitudinal capacity expansion in step S3 is specifically as follows:
s301, creating a new volume with a specified size through volume _ extend operation of a factory, and judging whether a volume is created and the volume size is consistent with the size to be expanded:
(1) if the new volume is successfully created, and the step S2 is executed next;
(2) if the failure occurs, returning corresponding error information, deleting the established abnormal resources and simultaneously stopping the service;
s302, after the new volume is successfully created, mounting the new volume on the target cloud host through the volume _ attributes operation of the factory, and judging whether the mounting of the volume by the target cloud host is successful:
(1) if the volume is successfully mounted, the expansion is basically completed, and the step S3 is executed next;
(2) if the mount of the volume fails, the volume is directly deleted, the rollback of the service is realized, and meanwhile, corresponding error information is returned and the service is stopped;
s303, after the volumes are mounted, the factory executes an interrupt script through remote-exec, performs LVM partition operation on the new mounted volumes, and judges whether the interrupt script is executed successfully:
(1) if the Ansine script is successfully executed, longitudinal capacity expansion is successful, and at the moment, the lsblk instruction and the df-h instruction which enter the cloud host computer and are executed can find that the capacity expansion of the disk of the cloud host computer is successful;
(2) if the execution of the Ansible script fails, executing the step S4;
s304, judging whether to delete the new volume:
(1) if yes, deleting the volume and performing rollback service;
(2) and if not, reserving the created volume, and performing the corresponding script in the cloud host offline.
3. The cloud host disk capacity expansion method and system based on Terraform according to claim 2, wherein the LVM partitioning operation includes creating a physical volume, joining a volume group, expanding a logical volume, and refreshing a file system.
4. The method for cloud host disk capacity expansion based on Terraform according to claim 2 or 3, characterized in that during a longitudinal capacity expansion operation, when a user name and a password of the cloud host for performing the LVM operation cannot be obtained, an LVM execution script and a monitoring program are built in the cloud host in advance, and when the built-in LVM execution script and the monitoring program find that a new volume is mounted, a corresponding LVM instruction is automatically executed, and finally the capacity expansion operation of the system disk is completed.
5. The cloud host disk capacity expansion method based on Terraform according to claim 1, wherein the horizontal capacity expansion in step S4 is specifically as follows:
s401, performing shutdown operation on the cloud host through a factory, and determining whether the state of the cloud host is SHUTOFF by polling operation:
(1) if the shutdown is successful, executing step S402;
(2) if shutdown fails, capacity expansion fails, namely the abnormal state of the cloud host is described, automatic recovery cannot be realized, alarm information needs to be sent, meanwhile, the service is stopped, manual intervention is carried out, the abnormal reason of the state of the cloud host is checked, and capacity expansion operation is carried out after the virtual machine state is recovered;
s402, the factory makes a mirror image snapshot on the cloud host, performs data backup, and judges whether the backup is successful:
(1) if the backup fails, the capacity expansion fails;
(2) if the backup is successful, executing step S403;
s403, before capacity expansion, resetting the volume state through a factory, and polling the volume state:
(1) when the volume state is available, executing step S404;
(2) when the volume state is abnormal, indicating that the capacity expansion fails, stopping the service, alarming and manually intervening;
s404, updating the volume size, namely expanding the target volume through the factory, and judging whether the expansion is successful:
(1) if the capacity expansion is successful, executing step S405;
(2) if the capacity expansion fails, the service is stopped; if the volume state is abnormal and cannot be recovered, reconstructing the volume according to the data which is backed up in the step S2 and executing mounting operation;
s405, after capacity expansion is successful, starting up the cloud host through a factory, automatically changing the volume state to in-use, and finishing the capacity expansion of the transverse system disk after the cloud host state is changed to be in operation; at the moment, the entering of the cloud host computer can find that the disk expansion of the cloud host computer is successful by executing the lsblk instruction and the df-h instruction.
6. A cloud host disk capacity expansion system based on Terraform is characterized in that the system combines APIs of Terraform and Openstack, and automatic cloud configuration is improved to a new height through terroformint, terroform plan and terroform application; the Terraform calls the Api of Openstack through the provider plug-in to conveniently manage the cloud host, and the Terraform related plug-in and various Openstack Api calls are packaged into a factory method to complete the capacity expansion of the cloud host system disk; the system comprises a first judging unit, a longitudinal capacity expansion unit, a transverse capacity expansion unit and a second judging unit;
the first judging unit is used for judging whether the disk supports the LVM:
the longitudinal capacity expansion unit is used for executing longitudinal capacity expansion;
the transverse capacity expansion unit is used for executing transverse capacity expansion;
the second judging unit is used for judging whether the capacity expansion is successful.
7. The Terraform-based cloud host disk capacity expansion system according to claim 6, wherein the vertical capacity expansion unit comprises,
the volume creation and judgment module is used for creating a new volume with a specified size through the volume _ extend operation of a factory and judging whether a volume is created and the volume size is consistent with the volume to be expanded;
the volume mounting and judging module is used for mounting the new volume to the target cloud host through the volume _ attributes operation of the factory and judging whether the target cloud host successfully mounts the volume;
the partitioning and judging module is used for executing the Ansine script through remote-exec, performing LVM partitioning operation on the new mounted volume and judging whether the Ansine script is executed successfully;
and the judging module is used for judging whether to delete the new volume.
8. The cloud host disk expansion system based on Terraform of claim 6, wherein the horizontal expansion unit comprises,
the shutdown and judgment module is used for performing shutdown operation on the cloud host through a factory, and polling operation is performed to determine whether the state of the cloud host is SHUTOFF;
the backup and judgment module is used for carrying out mirror image snapshot on the cloud host through a factory, carrying out data backup and judging whether the backup is successful or not;
the resetting and polling module is used for resetting the volume state through a factory and polling the volume state;
the volume updating and capacity expanding judging module is used for updating the volume size, namely, expanding the capacity of the target volume through a factory and judging whether the capacity expansion is successful or not;
the system comprises a starting module, a volume module and a volume expansion module, wherein the starting module is used for starting the cloud host through a factory, the volume state can be automatically changed into in-use at the moment, and after the state of the cloud host is changed into operation, the volume expansion of a transverse system disk is completed; at the moment, the entering of the cloud host computer can find that the disk expansion of the cloud host computer is successful by executing the lsblk instruction and the df-h instruction.
9. An electronic device, comprising: a memory and at least one processor;
wherein the memory stores computer execution instructions;
the at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the Terraform-based cloud host disk capacity expansion method according to any one of claims 1 to 5.
10. A computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when a processor executes the computer, the method for cloud host disk expansion based on terrafrorm according to any one of claims 1 to 5 is implemented.
CN202211614815.XA 2022-12-15 2022-12-15 Terraform-based cloud host disk capacity expansion method and system Pending CN115963990A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211614815.XA CN115963990A (en) 2022-12-15 2022-12-15 Terraform-based cloud host disk capacity expansion method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211614815.XA CN115963990A (en) 2022-12-15 2022-12-15 Terraform-based cloud host disk capacity expansion method and system

Publications (1)

Publication Number Publication Date
CN115963990A true CN115963990A (en) 2023-04-14

Family

ID=87358092

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211614815.XA Pending CN115963990A (en) 2022-12-15 2022-12-15 Terraform-based cloud host disk capacity expansion method and system

Country Status (1)

Country Link
CN (1) CN115963990A (en)

Similar Documents

Publication Publication Date Title
US11397648B2 (en) Virtual machine recovery method and virtual machine management device
CN102238093B (en) Service interruption prevention method and device
CN112003917B (en) File storage management method, system, device and medium
CN109086079B (en) Mounting management method and device for storage equipment
CN103176831A (en) Virtual machine system and management method thereof
CN112783444A (en) Cluster disk sharing method, system and storage medium
CN104918114A (en) Method and device for upgrading operation system
CN110196749B (en) Virtual machine recovery method and device, storage medium and electronic device
TW202109336A (en) Method and apparatus for upgrading system in internet of things device, device, and storage medium
CN111090546A (en) Method, device and equipment for restarting operating system and readable storage medium
CN111475335B (en) Method, system, terminal and storage medium for quickly recovering database
CN112783603A (en) Cluster shutdown control method and system and storage medium
CN115963990A (en) Terraform-based cloud host disk capacity expansion method and system
CN108595292B (en) System optimization method, mobile terminal and computer storage medium
CN111930707B (en) Method and system for correcting drive letter of windows cloud migration
CN115391106A (en) Method, system and device for pooling backup resources
CN114153503A (en) BIOS control method, device and medium
CN110795155B (en) System starting method and device, electronic equipment and storage medium
CN110262875B (en) Communication method and system of Windows virtual machine and KVM host based on patch mechanism
CN109101253B (en) Management method and device for host in cloud computing system
CN113190244A (en) Method and device for upgrading wireless module, computer equipment and storage medium
CN110806917A (en) Anti-split virtual machine high-availability management device and method
US20240118975A1 (en) Iinformation processing system, management apparatus, management method, and program
CN117290164B (en) Information recording method at restarting, electronic device and readable storage medium
CN111176886A (en) Database mode switching method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination