volcengine_rust_sdk/service/ecs/
service_ecs.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-28 16:45:54
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 16:59:31
6 * @Description: Service for ECS (Elastic Compute Service)
7 */
8use crate::service::ecs::api_describe_images;
9use crate::service::ecs::api_describe_instances;
10use crate::service::ecs::api_describe_regions;
11use crate::service::ecs::api_describe_zones;
12use crate::service::ecs::api_modify_instance_spec;
13use crate::service::ecs::api_run_instances;
14use crate::service::ecs::api_stop_instance;
15use crate::service::ecs::api_stop_instances;
16use crate::service::ecs::{Ecs, EcsService};
17use crate::volcengine::client::client;
18use crate::volcengine::client::client_info;
19use crate::volcengine::client::config as client_config;
20use crate::volcengine::common;
21use crate::volcengine::error::error;
22use crate::volcengine::request::handles;
23use crate::volcengine::session::session;
24
25/// EcsService implementation for Ecs
26/// Implementation of the `EcsService` trait for the `Ecs` struct.
27/// This implementation provides concrete methods for interacting with ECS services.
28impl EcsService for Ecs {
29    /// Creates a new `Ecs` instance using the provided session.
30    /// This method is the primary way to initialize the ECS client.
31    ///
32    /// # Parameters:
33    /// - `session`: A `session::Session` object containing authentication and configuration information.
34    ///
35    /// # Returns:
36    /// A `Result` containing an `Ecs` instance on success or an `error::Error` on failure.
37    fn new_ecs(session: session::Session) -> Result<Self, error::Error> {
38        // Create a new session and retrieve the client configuration
39        let client_config = session.new_client_config(client_config::ClientServiceName::Ecs);
40
41        // Set up client information
42        let client_info = client_info::ClientInfo::builder()
43            .with_service_name(client_config::ClientServiceName::Ecs)
44            .with_api_version(common::COMMON_VERSION_2020_04_01)
45            .with_signing_region(&client_config.signing_region)
46            .build()?;
47
48        // Create handles
49        let request_handles = handles::Handles {};
50
51        // Build the client with the provided information and configuration
52        let client = client::Client::builder()
53            .with_client_info(&client_info)
54            .with_config(&client_config)
55            .with_handles(&request_handles)
56            .build()?;
57
58        // Return the new Ecs instance
59        Ok(Ecs { client: client })
60    }
61
62    /// Initiates a request to run instances in ECS.
63    /// This method uses the internal `ApiRunInstance` to handle the request.
64    ///
65    /// # Parameters:
66    /// - `&self`: A reference to the current instance of `Ecs`.
67    /// - `request`: A `RunInstancesReq` object containing the parameters for running instances.
68    ///
69    /// # Returns:
70    /// A `Result` containing a `RunInstancesResp` on success or an `error::Error` on failure.
71    async fn new_run_instances(
72        &self,
73        request: volcengine_sdk_protobuf::protobuf::ecs_instance::RunInstancesReq,
74    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_instance::RunInstancesResp, error::Error>
75    {
76        api_run_instances::ApiRunInstance
77            .new_run_instances(self, request)
78            .await
79    }
80
81    /// Initiates a request to describe instances in ECS.
82    /// This method uses the internal `ApiDescribeInstances` to handle the request.
83    ///
84    /// # Parameters:
85    /// - `&self`: A reference to the current instance of `Ecs`.
86    /// - `request`: A `DescribeInstancesReq` object containing the parameters for describing instances.
87    ///
88    /// # Returns:
89    /// A `Result` containing a `DescribeInstancesResp` on success or an `error::Error` on failure.
90    async fn new_describe_instances(
91        &self,
92        request: volcengine_sdk_protobuf::protobuf::ecs_instance::DescribeInstancesReq,
93    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_instance::DescribeInstancesResp, error::Error>
94    {
95        api_describe_instances::ApiDescribeInstances
96            .new_describe_instances(self, request)
97            .await
98    }
99
100    /// Initiates a request to stop a single instance in ECS.
101    /// This method uses the internal `ApiStopInstance` to handle the request.
102    ///
103    /// # Parameters:
104    /// - `&self`: A reference to the current instance of `Ecs`.
105    /// - `request`: A `StopInstanceReq` object containing the parameters for stopping an instance.
106    ///
107    /// # Returns:
108    /// A `Result` containing a `StopInstanceResp` on success or an `error::Error` on failure.
109    async fn new_stop_instance(
110        &self,
111        request: volcengine_sdk_protobuf::protobuf::ecs_instance::StopInstanceReq,
112    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_instance::StopInstanceResp, error::Error>
113    {
114        api_stop_instance::ApiStopInstance
115            .new_stop_instance(self, request)
116            .await
117    }
118
119    /// Initiates a request to stop multiple instances in ECS.
120    /// This method uses the internal `ApiStopInstances` to handle the request.
121    ///
122    /// # Parameters:
123    /// - `&self`: A reference to the current instance of `Ecs`.
124    /// - `request`: A `StopInstancesReq` object containing the parameters for stopping multiple instances.
125    ///
126    /// # Returns:
127    /// A `Result` containing a `StopInstancesResp` on success or an `error::Error` on failure.
128    async fn new_stop_instances(
129        &self,
130        request: volcengine_sdk_protobuf::protobuf::ecs_instance::StopInstancesReq,
131    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_instance::StopInstancesResp, error::Error>
132    {
133        api_stop_instances::ApiStopInstances
134            .new_stop_instances(self, request)
135            .await
136    }
137
138    /// Initiates a request to modify the specifications of an instance in ECS.
139    /// This method uses the internal `ApiModifyInstanceSpec` to handle the request.
140    ///
141    /// # Parameters:
142    /// - `&self`: A reference to the current instance of `Ecs`.
143    /// - `request`: A `ModifyInstanceSpecReq` object containing the parameters for modifying instance specifications.
144    ///
145    /// # Returns:
146    /// A `Result` containing a `ModifyInstanceSpecResp` on success or an `error::Error` on failure.
147    async fn new_modify_instance_spec(
148        &self,
149        request: volcengine_sdk_protobuf::protobuf::ecs_instance::ModifyInstanceSpecReq,
150    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_instance::ModifyInstanceSpecResp, error::Error>
151    {
152        api_modify_instance_spec::ApiModifyInstanceSpec
153            .new_modify_instance_spec(self, request)
154            .await
155    }
156
157    /// Initiates a request to describe images in ECS.
158    /// This method uses the internal `ApiDescribeImagesEcs` to handle the request.
159    ///
160    /// # Parameters:
161    /// - `&self`: A reference to the current instance of `Ecs`.
162    /// - `request`: A `DescribeImagesReq` object containing the parameters for describing images.
163    ///
164    /// # Returns:
165    /// A `Result` containing a `DescribeImagesResp` on success or an `error::Error` on failure.
166    async fn new_describe_images(
167        &self,
168        request: volcengine_sdk_protobuf::protobuf::ecs_image::DescribeImagesReq,
169    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_image::DescribeImagesResp, error::Error>
170    {
171        api_describe_images::ApiDescribeImagesEcs
172            .new_describe_images(self, request)
173            .await
174    }
175
176    /// Initiates a request to describe regions in ECS.
177    /// This method uses the internal `ApiDescribeRegionsEcs` to handle the request.
178    ///
179    /// # Parameters:
180    /// - `&self`: A reference to the current instance of `Ecs`.
181    /// - `request`: A `DescribeRegionsReq` object containing the parameters for describing regions.
182    ///
183    /// # Returns:
184    /// A `Result` containing a `DescribeRegionsResp` on success or an `error::Error` on failure.
185    async fn new_describe_regions(
186        &self,
187        request: volcengine_sdk_protobuf::protobuf::ecs_zone::DescribeRegionsReq,
188    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_zone::DescribeRegionsResp, error::Error>
189    {
190        api_describe_regions::ApiDescribeRegionsEcs
191            .new_describe_regions(self, request)
192            .await
193    }
194
195    /// Initiates a request to describe zones in ECS.
196    /// This method uses the internal `ApiDescribeZonesEcs` to handle the request.
197    ///
198    /// # Parameters:
199    /// - `&self`: A reference to the current instance of `Ecs`.
200    /// - `request`: A `DescribeZonesReq` object containing the parameters for describing zones.
201    ///
202    /// # Returns:
203    /// A `Result` containing a `DescribeZonesResp` on success or an `error::Error` on failure.
204    async fn new_describe_zones(
205        &self,
206        request: volcengine_sdk_protobuf::protobuf::ecs_zone::DescribeZonesReq,
207    ) -> Result<volcengine_sdk_protobuf::protobuf::ecs_zone::DescribeZonesResp, error::Error> {
208        api_describe_zones::ApiDescribeZonesEcs
209            .new_describe_zones(self, request)
210            .await
211    }
212}