Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve (rds): modify rds instance and database #205

Merged
merged 1 commit into from
Dec 26, 2019

Conversation

lixue323
Copy link
Contributor

No description provided.

@lixue323 lixue323 changed the title improve (rds): modify rds instance improve (rds): modify rds instance and database Nov 29, 2019
@@ -0,0 +1,251 @@
#!/usr/bin/python
# Copyright (c) 2017 Alibaba Group Holding Limited. He Guimin <heguimin36@163.com.com>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

时间

DOCUMENTATION = '''
---
module: ali_rds_database
version_added: "1.5.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

版本跟其他的一样

description:
- The state of the instance after operating.
default: 'present'
choices: ['present', 'restart', 'absent']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要restart么?

choices: ['present', 'restart', 'absent']
db_instance_id:
description:
- rds instance id. Required when C(state=present).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一个alias:instance_id

---
module: ali_rds_database
version_added: "1.5.0"
short_description: Create, Restart or Terminate an Instance in RDS.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个描述跟这个module不符吧

aliases: ['target_id']
db_names:
description:
- when copy databases between instances, format: {"source instance database name": "target instance database name"}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source instance database name 不就是当前的db name么?

roles:
- vpc
- vswitch
- rds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是得又role的情况下才能这么些,不是所有的用户都有这个

'''

RETURN = '''
instance:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

合格return完全跟当前module不符啊,看下其他的return怎么写的

for db in rds.describe_databases(db_instance_id=modules.params['db_instance_id']):
if db.name == name:
match = db
return match
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要在文档中说清楚哪些字段来保证module的幂等

@@ -0,0 +1,219 @@
#!/usr/bin/python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面的modudle都先按照上面的review改,改完后在review

db_description: create for ansible test
state: present

- name: Get the existing db
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下别的module的example是怎么写的

- database name. It must be 2 to 64 characters in length.It must start with a lowercase letter and end with a
lowercase letter or digit. It can contain lowercase letters, digits, underscores (_), and hyphens (-).
The database name must be unique whithin the instance.
For more information about invalid characters, see Forbidden keywords table(https://www.alibabacloud.com/help/doc-detail/26317.htm?spm=a2c63.p38356.879954.8.617de6d58lT07x#reference-pwh-14n-12b).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

链接中问号及问号后面的那长串不要

description:
- database character name. MySQL or MariaDB (utf8 | gbk | latin1 | utf8mb4).
SQL Server (Chinese_PRC_CI_AS | Chinese_PRC_CS_AS | SQL_Latin1_General_CP1_CI_AS | SQL_Latin1_General_CP1_CS_AS | Chinese_PRC_BIN).
see more (https://www.alibabacloud.com/help/doc-detail/26258.htm?spm=a2c63.l28256.b99.795.310413c7998oJs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也一样

description:
- The ID of the destination instance, which must differ from the ID of the source instance.
aliases: ['target_instance_id']
db_names:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只有一个元素,直接写成target_db_name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

拷贝一个实例数据库到另一个实例,需要两个参数的,原数据库名字和拷贝之后的命名

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对啊,原数据库名为 db_name; 拷贝后的叫做 target_db_name

returned: always
type: string
sample: rm-uf6wjk5xxxxxxx
dbname:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥return中就连起来了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

它返回的参数叫DBName, footmark转换之后就连在一起了
changed: [localhost] => {
"changed": true,
"database": {
"accounts": {
"account_privilege_info": []
},
"character_set_name": "utf8",
"dbdescription": "create for ansible test",
"dbinstance_id": "rm-2zef503eq1vkmop04",
"dbname": "ansible_test",
"dbstatus": "Running",
"description": "create for ansible test",
"engine": "MySQL",
"id": "rm-2zef503eq1vkmop04",
"name": "ansible_test",
"status": "Running"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分开

EXAMPLES = '''
- name: Get the existing database with name prefix
ali_rds_database_info:
name_prefix: ansible_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

字符串得要引号吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试过了,不加引号也没问题

'''

RETURN = '''
database:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info 返回的是一个list

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database->databases

description:
- The ID of the destination instance, which must differ from the ID of the source instance.
aliases: ['target_instance_id']
db_names:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对啊,原数据库名为 db_name; 拷贝后的叫做 target_db_name

returned: always
type: string
sample: rm-uf6wjk5xxxxxxx
dbname:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分开

'''

RETURN = '''
database:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database->databases

options:
state:
description:
- The state of the instance after operating.
choices: ['present', 'restart', 'absent']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  state:
    description:
        - If I(state=present), instance will be created.
        - If I(state=present) and instance exists, it will be updated.
        - If I(state=absent), instance will be removed.
        - If I(state=restart), instance will be restarted.
    default: present
    choices: ['present', 'restart', 'absent']

以后所有的state都这样写,说清楚每个state分别是干什么的

- Type of payment. Postpaid: postpaid instance; Prepaid: prepaid instance. Required when C(state=present).
choices: [ "Postpaid", "Prepaid" ]
- The billing method of the instance.Required when C(state=present).
choices: ["Postpaid", "Prepaid"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有的计费类型统一为 PostPaidPrePaid

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也没改啊

- Port of public net work.
private_port:
- The prefix of the target connection address. Only the prefix of CurrentConnectionString can be modified.
is_readonly:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只读实例单独抽象为一个module吧

description:
- Automatic renewal period. Required when C(auto_renew='True')
choices: [1, 2, 3, 6, 12]
- Instance id, the unique identifier of the instance. Required when C(state in ["present", "absent", "restart"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 instance name来保证幂等吧

sync_user_privilege:
description:
- Indicates whether to copy users and permissions.
choices: ['YES', 'NO']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用一个bool来代替 yes和no

version_added: "2.9.2"
short_description: Create, delete or copy an database in Alibaba Cloud RDS.
description:
- Create, delete, copy or modify description for database in RDS.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以后在所有的module的description中都显示的说明当前这个module的唯一标识符有哪几个字段决定,比如这个database的增加这么一句:
- An unique ali_rds_database module is co-determined by parameters db_instance_id and db_name.

- database name. It must be 2 to 64 characters in length.It must start with a lowercase letter and end with a
lowercase letter or digit. It can contain lowercase letters, digits, underscores (_), and hyphens (-).
The database name must be unique whithin the instance. this will specify unique database in one instance.
For more information about invalid characters, see Forbidden keywords table U(https://www.alibabacloud.com/help/doc-detail/26317.htm).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个module的唯一性除了最上面说明外,在每个参数中的描述中也在再说明一次,比如db_name:
- This is used in combination with C(db_instance_id) to determine if the database already exists.
db_instance_id:
- This is used in combination with C(db_name) to determine if the database already exists.

returned: always
type: string
sample: MySQL
id:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个ID去掉吧

DOCUMENTATION = '''
---
module: ali_rds_database_info
version_added: "2.9.2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个版本号以后统一写成2.9 吧

returned: always
type: string
sample: MySQL
id:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id 去掉吧

SQL Server (2008r2 | 2012 | 2012_ent_ha | 2012_std_ha | 2012_web | 2016_ent_ha | 2016_std_ha | 2016_web | 2017_ent)
PostgreSQL (9.4 | 10.0)
PPAS (9.3 | 10.0)
MariaDB (10.3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种最好分行显示:

       -  MySQL (5.5 | 5.6 | 5.7 | 8.0)
        - SQL Server (2008r2 | 2012 | 2012_ent_ha | 2012_std_ha | 2012_web | 2016_ent_ha | 2016_std_ha | 2016_web | 2017_ent)
        - PostgreSQL (9.4 | 10.0)
        - PPAS (9.3 | 10.0)
        - MariaDB (10.3)

connection_mode:
description: The access mode of the instance
returned: always
type: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回参数中没有分配的connection string啊。这个出参至少要跟入参对齐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改用了另一个接口,返回了更全的参数,已经补充

description: The access mode of the instance
returned: always
type: string
sample: Standard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info中的出参要跟module中的出参保持一直

short_description: Create, delete or copy an database in Alibaba Cloud RDS.
description:
- Create, delete, copy or modify description for database in RDS.
An unique ali_rds_database module is co-determined by parameters db_instance_id and db_name.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面的 “-” 呢?
如果没有 “-”,会跟在上面那行,如果有,会另起一行

lowercase letter or digit. It can contain lowercase letters, digits, underscores (_), and hyphens (-).
this will specify unique database in one instance.
For more information about invalid characters, see Forbidden keywords table U(https://www.alibabacloud.com/help/doc-detail/26317.htm).
This is used in combination with C(db_instance_id) to determine if the database already exists.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也一样,加一个 “-”

- Target instance database name.
backup_id:
description:
- The ID of the backup set on the source instance. When you copy databases based on the backup set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后的句号呢

db_name: ansible_test
character_set_name: utf8
db_description: create for ansible test
state: present
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example中最好不要出现test的字眼

db_instance_id:
description:
- The ID of the instance.
aliases: ["instance_id"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该得是required的吧,没有实例id怎么查database啊

choices: ["Internet", "Intranet"]
aliases: ['db_instance_net_type']
description:
db_instance_description:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 db_instance_name, alias是 name 和 description

- Type of payment. Postpaid: postpaid instance; Prepaid: prepaid instance. Required when C(state=present).
choices: [ "Postpaid", "Prepaid" ]
- The billing method of the instance.Required when C(state=present).
choices: ["Postpaid", "Prepaid"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也没改啊

choices: [1~9,12,24,36]
default: 1
- The prepayment period of the instance.
choices: ['Year', 'Month']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一都采用 Month,如果计费周期大于9,就将其转换为年

choices: ["Performance", "Safty"]
- The access mode of the instance.
choices: ["Standard", "Safe"]
instance_network_type:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance_network_type 可以去掉,如果指定了vswitchid,就是 vpc,否则就是classic

page_size:
- The intranet IP address of the instance. It must be within the IP address range provided by the switch.
By default, the system automatically assigns an IP address based on the VPCId and VSwitchId.
db_instance_id:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db_instance_id 是用来干嘛的

description:
- Create, restart, modify or terminate rds instances.
- Create, Restart, Delete and Modify connection_string, spec for RDS Instance.
- An unique ali_rds_instance module is determined by parameters db_instance_description(instance name).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是改称 db_instance_name 了么

description:
- Type of payment. Postpaid: postpaid instance; Prepaid: prepaid instance. Required when C(state=present).
choices: [ "Postpaid", "Prepaid" ]
- The billing method of the instance.Required when C(state=present).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

句号后如果还有语句,要空一格

choices: [1~9,12,24,36]
default: 1
default: 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每一行最后不要留对于的空格

if ins.name == name:
res = ins
if res:
res = rds.describe_db_instance_attribute(DBInstanceId=res.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥还要再查一遍

db_instance_name=dict(type='str', aliases=['description', 'name'], required=True),
security_ip_list=dict(type='str', aliases=['security_ips']),
pay_type=dict(type='str', choices=["PostPaid", "PrePaid"]),
period=dict(type='str', choice=['1', '2', '3', '4', '5', '6', '7', '8', '9', '12', '24', '36'], default='1'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个period的类型应该是 int把

@xiaozhu36 xiaozhu36 merged commit 1bc8267 into alibaba:master Dec 26, 2019
@lixue323 lixue323 deleted the rds branch March 1, 2020 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants