CMDB cloud resource synchronization method and system

By obtaining the access key of the third-party cloud computing platform API and using the Go language and the Go SDK toolkit, the timing and automatic synchronization of virtual machine resources is achieved, solving the problems of untimely updates and inaccurate information in the traditional cloud resource synchronization method. Improves the efficiency and system consistency of cloud resource synchronization.

CN119088528APending Publication Date: 2024-12-06TONGFANG YOUYUN (BEIJING) TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411272716.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The traditional cloud resource synchronization method has problems such as untimely update of cloud resource management and inaccurate information, resulting in high labor maintenance costs, low synchronization efficiency, and insufficient system reliability and consistency.

Method used

By obtaining the access key of the third-party cloud computing platform API, using the Go language and the Go SDK toolkit to obtain a list of virtual machine resources and map it to the configuration management database (CMDB), and using the timed task library to automatically perform resource discovery operations. Ensure timeliness and accuracy of resource synchronization.

Benefits of technology

It realizes efficient cloud resource synchronization, reduces labor maintenance costs, and improves system reliability, availability and consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088528A_ABST
    Figure CN119088528A_ABST
Patent Text Reader

Abstract

The invention provides a CMDB cloud resource synchronization method and system, and the method comprises the steps: obtaining an access key (Access Key) and a secret key (Secret Key) of a project to be accessed by a transportation management, and carrying out the authentication and authorization of API calling; a Go language is used for writing codes, a Go SDK toolkit is used for API calling, a virtual machine resource list is obtained through API calling, and virtual machine resource data is obtained through the Go SDK toolkit; mapping the obtained virtual machine resource data into a data model of a configuration management database (CMDB), and storing the virtual machine resource data into a database of the CMDB; performing database operation by using an ORM library of the Go language; and automatically executing virtual machine resource discovery operation at regular time by using a timed task library of the Go language. According to the invention, the resource discovery operation is automatically executed regularly, the efficient resource synchronization is realized, the manpower maintenance cost is reduced, and the reliability, availability and consistency of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud resource synchronization technology; in particular, to a CMDB cloud resource synchronization method and system. Background Art

[0002] Cloud Resource Synchronization refers to the key operation in a cloud computing environment to ensure the consistency of resources and data between different cloud environments, different regions, and different services. Cloud resource synchronization can involve a variety of resource types, including storage, databases, virtual machines, configuration files, etc. Cloud resource synchronization includes the following situations: 1. Data synchronization, maintaining data consistency between different storage locations. This usually involves copying data from one location to another and ensuring that the data in the two locations remains synchronized.

[0003] 2. Configuration synchronization, maintaining consistency of configuration files between different environments or services. This is very important to ensure consistent behavior between different environments (such as development, testing, and production).

[0004] 3. Application synchronization to maintain consistency of application state and code between different locations or service instances.

[0005] The traditional cloud resource synchronization method is mainly to synchronize the host resources and cloud region information on the cloud platform in one direction through API keys. However, the existing cloud resource synchronization method has the disadvantages of untimely cloud resource management and inaccurate information, which increases the manpower maintenance cost and low cloud resource synchronization efficiency. Summary of the invention

[0006] In view of this, the purpose of the present invention is to consider factors such as data consistency, delay, cost and security when implementing cloud resource synchronization, and to correctly obtain the list of virtual machine resources by efficiently calling the third-party cloud computing platform API, so as to realize the scheduled automatic execution of resource discovery operations and achieve efficient resource synchronization, so as to solve the problems of untimely updates and inaccurate information in traditional cloud resource management, reduce manpower maintenance costs, improve cloud resource synchronization efficiency, and improve the reliability, availability and consistency of the system.

[0007] The present invention provides a CMDB cloud resource synchronization method, comprising the following steps: S1. Obtain the access key and secret key of the project that the operation management wants to access, and perform authentication and authorization of the API call; S2. Use the Go language to write code and use the Go SDK toolkit (preferably the Go SDK toolkit of Huawei Cloud) to make API calls. Obtain the list of virtual machine resources through API calls and obtain virtual machine resource data through the Go SDK toolkit. S3. Map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the database of the CMDB; use the ORM library of the Go language (such as "GORM") to perform database operations; S4. Use the Go language scheduled task library (such as "github.com / robfig / cron") to automatically perform virtual machine resource discovery operations at regular intervals.

[0008] Furthermore, the step S2 includes the following steps: S21. Import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; S22. Use the huaweicloud.NewClient function to pass in the configuration information including AK, SK, Region, and ProjectID to create a Huawei cloud client. S23. Use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client. If an error occurs during the creation of the ECS client, the error message is printed and the program exits; If no error occurs during the creation of the ECS client, proceed to step S24; S24. Define an instance of the ecs.ListServersDetailsOpts structure to specify query conditions (such as filter conditions, etc.); S25. Call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; If an error occurs while querying the server list, an error message is printed and the program exits; If no error occurs during the query of the server list, proceed to step S26; S26. Traverse the server list in the query result and print the unique ID identifier and name of each server (more attributes can be printed as needed).

[0009] Furthermore, the S3 step includes the following steps: S31. Import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; S32. Define a structure named VirtualMachine as the data model of the virtual machine; embed the gorm.Model function in the VirtualMachine structure, which contains the commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; in addition, other required attributes can be defined; S33, defining a main function main, the entry point of the program, in which database connection and data model migration are performed; S34. Define the database connection string dsn in the format of: username:password@tcp(host address:port) / database name?parameter; for example: "user:password@tcp(localhost:3306) / dbname?charset=utf8mb4&parseTime=True&loc=Local"; S35. Use the gorm.Open function, pass in the MySQL driver and connection string, and try to establish a connection with the database; If the connection fails, print an error message and exit the program; If the connection is successful, proceed to step S36; S36. Call the db.AutoMigrate method, pass in the VirtualMachine structure, and automatically migrate the database table structure to ensure that the database table is consistent with the data model; S37. Obtain virtual machine resource data from Huawei Cloud, and store the virtual machine resource data in a database.

[0010] Furthermore, the S4 step includes the following steps: S41. Import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; S42, defining the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; S43, calling cron.New method to create a new scheduled task scheduler instance c, wherein the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; S44. Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour (for example, the scheduling time "0 0 * * * *" means running the task at the 0th minute of every hour); in the task function, place the logic of the resource discovery operation that needs to be executed regularly; S45, calling the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts scheduling tasks according to the set time; S46. Use the defer keyword and call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup. Use the select {} statement to block the main function to keep the program running and ensure continuous execution of the scheduled task.

[0011] Through the above design method, the present invention uses the Go language to implement the CMDB cloud resource discovery function, and synchronizes the virtual machine resources on the cloud platform to the CMDB for management.

[0012] The present invention also provides a CMDB cloud resource synchronization system, which executes the CMDB cloud resource synchronization method as described above, including: Authentication and authorization module: used to obtain the access key and secret key of the project that the operation management wants to access, and perform authentication and authorization of API calls; API call module: used to write code in Go language, use Go SDK toolkit to make API calls, obtain the virtual machine resource list through API calls, and obtain virtual machine resource data through Go SDK toolkit; Data storage module: used to map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the CMDB database; use the ORM library of the Go language to perform database operations; Scheduled task module: used to use the scheduled task library of Go language to automatically perform virtual machine resource discovery operations on a scheduled basis.

[0013] Furthermore, the API calling module includes: Import package unit: used to import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; Create a Huawei Cloud client unit: Use the huaweicloud.NewClient function to pass in configuration information including AK, SK, Region, and Project ID to create a Huawei Cloud client; Create ECS client unit: used to use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client; if an error occurs during the creation of the ECS client, the error message is printed and the program exits; if no error occurs during the creation of the ECS client, the query option setting unit is entered; Set query option unit: used to define the ecs.ListServersDetailsOpts structure instance, which is used to specify the query conditions; List cloud server details unit: used to call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; if an error occurs during the query of the server list, the error message is printed and the program exits; if no error occurs during the query of the server list, the unit of traversing and printing server information is entered; Traverse and print server information unit: used to traverse the server list in the query result and print the ID unique identifier and name of each server.

[0014] Furthermore, the data storage module comprises: Import package unit: used to import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; Define the data model unit: used to define a structure named VirtualMachine as the data model of the virtual machine; in the VirtualMachine structure, embed the gorm.Model function, which contains commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; Define the main function unit: used to define the main function main, the entry point of the program, in which database connection and data model migration are performed; Configure the database connection string unit: used to define the database connection string dsn, the format is: user name: password@tcp (host address: port) / database name? parameter; Connect to database unit: used to use gorm.Open function, pass in MySQL driver and connection string, and try to establish connection with the database; if the connection fails, print error message and exit the program; if the connection is successful, enter the migration data model unit; Migrate data model unit: used to call the db.AutoMigrate method, pass in the VirtualMachine structure, automatically migrate the database table structure, and ensure that the database table is consistent with the data model; Get VM resource data unit: used to get VM resource data from Huawei Cloud and store the VM resource data in the database.

[0015] Furthermore, the timing task module includes: Import package unit: used to import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; Define the main function unit: used to define the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; Create a new scheduled task scheduler unit: used to call the cron.New method to create a new scheduled task scheduler instance c, and the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; Add a scheduled task unit: Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour; in the task function, place the logic of the resource discovery operation that needs to be executed regularly; Start the scheduled task scheduler unit: used to call the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts to schedule tasks according to the set time; Ensure program running and clean up resource unit: Use the defer keyword to call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup; use the select {} statement to block the main function to keep the program running and ensure the continuous execution of scheduled tasks.

[0016] The CMDB cloud resource synchronization method of the present invention can automatically discover various resources in the cloud environment, including virtual machine instances, storage volumes, etc., and obtain the basic attributes and configuration information of the resources by calling the API of the cloud service provider; it supports multiple cloud computing service platforms, and CMDB supports docking with the customer's cloud management platform. Users can add different types of accounts as needed and configure corresponding access keys or certificates for each account.

[0017] The present invention also provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the steps of the CMDB cloud resource synchronization method as described above are implemented.

[0018] The present invention also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the CMDB cloud resource synchronization method as described above when executing the program.

[0019] Compared with the prior art, the present invention has the following beneficial effects: The CMDB cloud resource synchronization method and system provided by the present invention efficiently calls the API of a third-party cloud computing platform to correctly obtain a list of virtual machine resources; realizes the scheduled automatic execution of resource discovery operations, and realizes efficient resource synchronization by using selected tools for design, thereby effectively solving the problems of untimely updates and inaccurate information in traditional cloud resource management, reducing human maintenance costs, effectively improving cloud resource synchronization efficiency, and improving system reliability, availability, and consistency. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting the invention.

[0021] In the attached picture: Figure 1 A business process diagram of CMDB cloud resource discovery according to an embodiment of the present invention; Figure 2 This is a flow chart of the CMDB cloud resource synchronization method of the present invention; Figure 3 is a method flow chart of step S2 of the present invention; Figure 4 is a method flow chart of step S3 of the present invention; Figure 5 is a method flow chart of step S4 of the present invention; Figure 6 The figure is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0022] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure. Instead, they are merely examples of systems and products consistent with some aspects of the present disclosure as detailed in the appended claims.

[0023] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0024] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0025] The embodiments of the present invention are described in further detail below.

[0026] The embodiment of the present invention provides a CMDB cloud resource synchronization method, see Figure 2 As shown, the following steps are included: S1. Obtain the access key and secret key of the project that the operation management wants to access, and perform authentication and authorization of the API call; S2. Use Go language to write code, use Go SDK toolkit to make API calls, obtain the virtual machine resource list through API calls, and obtain virtual machine resource data through Go SDK toolkit; See also Figure 3 As shown, the S2 step includes the following steps: S21. Import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; S22. Use the huaweicloud.NewClient function to pass in the configuration information including AK, SK, Region, and ProjectID to create a Huawei cloud client. S23. Use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client. If an error occurs during the creation of the ECS client, the error message is printed and the program exits; If no error occurs during the creation of the ECS client, proceed to step S24; S24. Define an instance of the ecs.ListServersDetailsOpts structure to specify query conditions. S25. Call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; Preferably, the query conditions include: filtering conditions and the like.

[0027] If an error occurs while querying the server list, an error message is printed and the program exits; If no error occurs during the query of the server list, proceed to step S26; S26. Traverse the server list in the query result and print the ID unique identifier and name of each server.

[0028] S3. Map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the database of the CMDB; use the ORM library ("GORM") of the Go language to perform database operations; See also Figure 4 As shown, the S3 step includes the following steps: S31. Import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; S32. Define a structure named VirtualMachine as the data model of the virtual machine; embed the gorm.Model function in the VirtualMachine structure, which contains the commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; S33, defining a main function main, the entry point of the program, in which database connection and data model migration are performed; S34. Define the database connection string dsn in the format of: username:password@tcp(host address:port) / database name?parameter; This embodiment includes the following database connection string dsn: "user:password@tcp(localhost:3306) / dbname?charset=utf8mb4&parseTime=True&loc=Local"; S35. Use the gorm.Open function, pass in the MySQL driver and connection string, and try to establish a connection with the database; If the connection fails, print an error message and exit the program; If the connection is successful, proceed to step S36; S36. Call the db.AutoMigrate method, pass in the VirtualMachine structure, and automatically migrate the database table structure to ensure that the database table is consistent with the data model; S37. Obtain virtual machine resource data from Huawei Cloud, and store the virtual machine resource data in a database.

[0029] S4. Use the Go language scheduled task library ("github.com / robfig / cron") to automatically perform virtual machine resource discovery operations at regular intervals.

[0030] Figure 1 The business process of CMDB cloud resource discovery in this embodiment is shown.

[0031] See also Figure 5 As shown, the S4 step includes the following steps: S41. Import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; S42, defining the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; S43, calling cron.New method to create a new scheduled task scheduler instance c, wherein the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; S44. Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour (scheduling time "0 0 * * * *" means running the task at the 0th minute of every hour); in the task function, place the logic of the resource discovery operation that needs to be executed regularly; S45, calling the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts scheduling tasks according to the set time; S46. Use the defer keyword and call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup. Use the select {} statement to block the main function to keep the program running and ensure continuous execution of the scheduled task.

[0032] Through the above design method, this embodiment uses the Go language to implement the CMDB cloud resource discovery function for Huawei Cloud, and synchronizes the virtual machine resources on Huawei Cloud to the CMDB for management.

[0033] The embodiment of the present invention also provides a CMDB cloud resource synchronization system, which executes the CMDB cloud resource synchronization method as described above, including: Authentication and authorization module: used to obtain the access key and secret key of the project that the operation management wants to access, and perform authentication and authorization of API calls; API call module: used to write code in Go language, use Go SDK toolkit to make API calls, obtain the virtual machine resource list through API calls, and obtain virtual machine resource data through Go SDK toolkit; The API calling module includes: Import package unit: used to import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; Create a Huawei Cloud client unit: Use the huaweicloud.NewClient function to pass in configuration information including AK, SK, Region, and Project ID to create a Huawei Cloud client; Create ECS client unit: used to use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client; if an error occurs during the creation of the ECS client, the error message is printed and the program exits; if no error occurs during the creation of the ECS client, the query option setting unit is entered; Set query option unit: used to define the ecs.ListServersDetailsOpts structure instance, which is used to specify the query conditions; List cloud server details unit: used to call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; if an error occurs during the query of the server list, the error message is printed and the program exits; if no error occurs during the query of the server list, the unit of traversing and printing server information is entered; Traverse and print server information unit: used to traverse the server list in the query result and print the ID unique identifier and name of each server.

[0034] Data storage module: used to map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the CMDB database; use the ORM library of the Go language to perform database operations; The data storage module comprises: Import package unit: used to import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; Define the data model unit: used to define a structure named VirtualMachine as the data model of the virtual machine; in the VirtualMachine structure, embed the gorm.Model function, which contains commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; Define the main function unit: used to define the main function main, the entry point of the program, in which database connection and data model migration are performed; Configure the database connection string unit: used to define the database connection string dsn, the format is: user name: password@tcp (host address: port) / database name? parameter; Connect to database unit: used to use gorm.Open function, pass in MySQL driver and connection string, and try to establish connection with the database; if the connection fails, print error message and exit the program; if the connection is successful, enter the migration data model unit; Migrate data model unit: used to call the db.AutoMigrate method, pass in the VirtualMachine structure, automatically migrate the database table structure, and ensure that the database table is consistent with the data model; Get VM resource data unit: used to get VM resource data from Huawei Cloud and store the VM resource data in the database.

[0035] Scheduled task module: used to use the scheduled task library of Go language to automatically perform virtual machine resource discovery operations on a scheduled basis.

[0036] The timing task module includes: Import package unit: used to import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; Define the main function unit: used to define the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; Create a new scheduled task scheduler unit: used to call the cron.New method to create a new scheduled task scheduler instance c, and the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; Add a scheduled task unit: Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour; in the task function, place the logic of the resource discovery operation that needs to be executed regularly; Start the scheduled task scheduler unit: used to call the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts to schedule tasks according to the set time; Ensure program running and clean up resource unit: Use the defer keyword to call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup; use the select {} statement to block the main function to keep the program running and ensure the continuous execution of scheduled tasks.

[0037] The cloud configuration platform in this embodiment provides a set of basic cloud resource synchronization functions, and the specific steps are: creating a cloud account, creating a cloud resource discovery task, and allocating cloud resources. When adding a cloud management account, the user provides the corresponding account configuration information, including account name, account type, access key / certificate, access key ID, etc. This account configuration information will be used for identity authentication and access with the cloud management service provider. After adding a cloud management account, CMDB provides an account connection test function to verify the validity and connection status of the account. Users can perform a connection test to ensure that the account is configured correctly and can successfully establish a connection with the cloud management service provider.

[0038] An embodiment of the present invention further provides a computer device, Figure 6 is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention; see the accompanying drawings Figure 6 As shown, the computer device includes: an input system 23, an output system 24, a memory 22 and a processor 21; the memory 22 is used to store one or more programs; when the one or more programs are executed by the one or more processors 21, the one or more processors 21 implement the CMDB cloud resource synchronization method provided in the above embodiment; wherein the input system 23, the output system 24, the memory 22 and the processor 21 can be connected by a bus or other means, Figure 6 The example of connecting through bus is taken in the following.

[0039] The memory 22 is a readable and writable storage medium of a computing device, which can be used to store software programs and computer executable programs, such as the program instructions corresponding to the CMDB cloud resource synchronization method described in the embodiment of the present invention; the memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required for a function; the data storage area can store data created according to the use of the device, etc.; in addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device; in some instances, the memory 22 can further include a memory remotely arranged relative to the processor 21, and these remote memories can be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0040] The input system 23 may be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the device; the output system 24 may include display devices such as display screens.

[0041] The processor 21 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 22, that is, implements the above-mentioned CMDB cloud resource synchronization method.

[0042] The computer device provided above can be used to execute the CMDB cloud resource synchronization method provided in the above embodiment, and has corresponding functions and beneficial effects.

[0043] The embodiment of the present invention also provides a storage medium containing computer executable instructions, which are used to execute the CMDB cloud resource synchronization method provided in the above embodiment when executed by a computer processor. The storage medium is any of various types of memory devices or storage devices, and the storage medium includes: installation media, such as CD-ROM, floppy disk or tape system; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements, etc.; the storage medium may also include other types of memory or combinations thereof; in addition, the storage medium may be located in a first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet); the second computer system may provide program instructions to the first computer for execution. The storage medium includes two or more storage media that can reside in different locations (for example, in different computer systems connected via a network). The storage medium can store program instructions (for example, specifically implemented as a computer program) that can be executed by one or more processors.

[0044] Of course, the storage medium containing computer executable instructions provided in an embodiment of the present invention is not limited to the CMDB cloud resource synchronization method described in the above embodiment, and can also execute related operations in the CMDB cloud resource synchronization method provided in any embodiment of the present invention.

[0045] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

[0046] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A CMDB cloud resource synchronization method, characterized in that: The following steps are involved: S1. Obtain the access key and secret key of the project that the operation management wants to access, and perform authentication and authorization of the API call; S2. Use Go language to write code, use Go SDK toolkit to make API calls, obtain the virtual machine resource list through API calls, and obtain virtual machine resource data through Go SDK toolkit; S3. Map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the CMDB database; use the ORM library of the Go language to perform database operations; S4. Use the Go language's scheduled task library to automatically perform virtual machine resource discovery operations on a scheduled basis.

2. The CMDB cloud resource synchronization method according to claim 1, characterized in that: The S2 step includes the following steps: S21. Import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; S22. Use the huaweicloud.NewClient function to pass in the configuration information including AK, SK, Region, and Project ID to create a Huawei cloud client. S23. Use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client. If an error occurs during the creation of the ECS client, the error message is printed and the program exits; If no error occurs during the creation of the ECS client, proceed to step S24; S24. Define an instance of the ecs.ListServersDetailsOpts structure to specify query conditions. S25. Call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; If an error occurs while querying the server list, an error message is printed and the program exits; If no error occurs during the query of the server list, proceed to step S26; S26. Traverse the server list in the query result and print the ID unique identifier and name of each server.

3. The CMDB cloud resource synchronization method according to claim 2, characterized in that: The S3 step includes the following steps: S31. Import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; S32. Define a structure named VirtualMachine as the data model of the virtual machine; embed the gorm.Model function in the VirtualMachine structure, which contains the commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; S33, defining a main function main, the entry point of the program, in which database connection and data model migration are performed; S34. Define the database connection string dsn in the format of: username:password@tcp(host address:port) / database name?parameter; S35. Use the gorm.Open function, pass in the MySQL driver and connection string, and try to establish a connection with the database; If the connection fails, print an error message and exit the program; If the connection is successful, proceed to step S36; S36. Call the db.AutoMigrate method, pass in the VirtualMachine structure, and automatically migrate the database table structure to ensure that the database table is consistent with the data model; S37. Obtain virtual machine resource data from Huawei Cloud, and store the virtual machine resource data in a database.

4. The CMDB cloud resource synchronization method according to claim 3, characterized in that: The S4 step includes the following steps: S41. Import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; S42, defining the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; S43, calling cron.New method to create a new scheduled task scheduler instance c, wherein the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; S44. Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour; in the task function, place the logic of the resource discovery operation that needs to be executed regularly; S45, calling the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts scheduling tasks according to the set time; S46. Use the defer keyword and call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup. Use the select {} statement to block the main function to keep the program running and ensure continuous execution of the scheduled task.

5. A CMDB cloud resource synchronization system, executing the CMDB cloud resource synchronization method according to any one of claims 1 to 4, characterized in that: include: Authentication and authorization module: used to obtain the access key Access Key and secret key SecretKey of the project that the operation management wants to access, and perform authentication and authorization of API calls; API call module: used to write code in Go language, use Go SDK toolkit to make API calls, obtain the virtual machine resource list through API calls, and obtain virtual machine resource data through Go SDK toolkit; Data storage module: used to map the acquired virtual machine resource data to the data model of the configuration management database CMDB and store it in the CMDB database; use the ORM library of the Go language to perform database operations; Scheduled task module: used to use the scheduled task library of Go language to automatically perform virtual machine resource discovery operations on a scheduled basis.

6. The CMDB cloud resource synchronization system according to claim 5, characterized in that: The API calling module includes: Import package unit: used to import the fmt package in the Go language standard library, the core package of the Huawei Cloud SDK, and the SDK package of the Elastic Cloud Server ECS service; Create a Huawei Cloud client unit: Use the huaweicloud.NewClient function to pass in configuration information including AK, SK, Region, and Project ID to create a Huawei Cloud client; Create ECS client unit: used to use the created Huawei Cloud client to call the ecs.NewEcsClient function to create an ECS client; if an error occurs during the creation of the ECS client, the error message is printed and the program exits; if no error occurs during the creation of the ECS client, the query option setting unit is entered; Set query option unit: used to define the ecs.ListServersDetailsOpts structure instance, which is used to specify the query conditions; List cloud server details unit: used to call the ecs.ListServersDetails function, pass in the ECS client and query options, and obtain the server list; if an error occurs during the query of the server list, the error message is printed and the program exits; if no error occurs during the query of the server list, the unit of traversing and printing server information is entered; Traverse and print server information unit: used to traverse the server list in the query result and print the ID unique identifier and name of each server.

7. The CMDB cloud resource synchronization system according to claim 5, characterized in that: The data storage module comprises: Import package unit: used to import the gorm.io / driver / mysql package to use the MySQL database driver; import the gorm.io / gorm package to use the object-relational mapping (ORM) function of the GORM library; Define the data model unit: used to define a structure named VirtualMachine as the data model of the virtual machine; in the VirtualMachine structure, embed the gorm.Model function, which contains commonly used fields: ID, creation time, update time, and deletion time; define the ID and Name fields as the unique identifier and name of the virtual machine respectively; Define the main function unit: used to define the main function main, the entry point of the program, in which database connection and data model migration are performed; Configure the database connection string unit: used to define the database connection string dsn, the format is: user name: password@tcp (host address: port) / database name? parameter; Connect to database unit: used to use gorm.Open function, pass in MySQL driver and connection string, and try to establish connection with the database; if the connection fails, print error message and exit the program; if the connection is successful, enter the migration data model unit; Migrate data model unit: used to call the db.AutoMigrate method, pass in the VirtualMachine structure, automatically migrate the database table structure, and ensure that the database table is consistent with the data model; Get VM resource data unit: used to get VM resource data from Huawei Cloud and store the VM resource data in the database.

8. The CMDB cloud resource synchronization system according to claim 5, characterized in that: The timing task module includes: Import package unit: used to import the github.com / robfig / cron package and use the scheduled task scheduling function provided by the github.com / robfig / cron package; Define the main function unit: used to define the main function main, the entry point of the program, in which the scheduled tasks are set and scheduled; Create a new scheduled task scheduler unit: used to call the cron.New method to create a new scheduled task scheduler instance c, and the scheduled task scheduler instance c is used to manage and schedule scheduled tasks; Add a scheduled task unit: Use the c.AddFunc method to add a scheduled task, configure its scheduling time and task function, and execute the task once every hour; in the task function, place the logic of the resource discovery operation that needs to be executed regularly; Start the scheduled task scheduler unit: used to call the c.Start method to start the scheduled task scheduler, so that the scheduled task scheduler starts to schedule tasks according to the set time; Ensure program running and clean up resource unit: Use the defer keyword to call the c.Stop() method before the program exits to stop the scheduled task scheduler and perform necessary resource cleanup; use the select {} statement to block the main function to keep the program running and ensure the continuous execution of scheduled tasks.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the CMDB cloud resource synchronization method according to any one of claims 1 to 4 are implemented.

10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the CMDB cloud resource synchronization method according to any one of claims 1 to 4 are implemented.

Citation Information

Cited By

  • Multi-node CMDB block refined data synchronization method and system

    CN120030086A