def create_config(conn): flavor_id = "" image_id = "" key_name = "" _config = { "flavor_id": flavor_id, "image_id": image_id, "disk": [{ "size": 40, "volume_type": "SATA", "disk_type": "SYS" }], "personality": [{ "path": "/etc/p1.txt", "content": utils.b64encode("p1") }, { "path": "/etc/p2.txt", "content": utils.b64encode("p2") }], "metadata": { "tag": "app", "node": "node2" }, "key_name": key_name } config = conn.auto_scaling.create_config("some-config-name", **_config) logging.info(config)
def create_server_with_user_data(): user_date_org = "#!/bin/bash \r\n echo 'root:xxxxx' | chpasswd ;" user_data = utils.b64encode(user_date_org) data = { "availability_zone": "kvmxen.dc1", "name": "test-sdk-for-userdata", "imageRef": "c71b64e7-4767-4406-afde-2c7c7ac2242c", "flavorRef": "s1.medium", "security_groups": [{ "name": "3cd0dc61-3a84-43de-9741-394fce012f38" }], "networks": [{ "uuid": "939924e4-48c3-4091-bbb5-1bf097fcdbf5" }], "user_data": user_data, "os:scheduler_hints": { "group": "ae089094-087b-4c39-ba98-f1862d5e45b1" } } ff = conn.compute.create_server(**data) print(ff) server_create = conn.compute.wait_for_server(ff, status="ACTIVE", wait=300) print(server_create) return server_create
def create_two_servers_one_time(): user_date_org = "#!/bin/bash \r\n echo 'root:xxxxx' | chpasswd ;" user_data = utils.b64encode(user_date_org) data = { "server": { "availability_zone": "az1.dc1", "name": "test-sdk-for-Linux-userdata", "imageRef": "af60e0d5-6952-4f3d-b0ed-31bb19d4a692", "flavorRef": "c2.large", "vpcid": "0f22416a-53aa-4f45-b351-7807118c680b", "user_data": user_data, "nics": [{ "subnet_id": "d090d69f-2109-4228-a941-a6067723744a" }], "root_volume": { "volumetype": "SATA" }, "count": 2 } } ff = conn.ecs.create_server(**data) print(ff) wait_time(TIMES, INTERVAL, ff.job_id)
def create_config(conn, name, flavor_id, image_id, key_name): _config = { "flavor_id": flavor_id, "image_id": image_id, "disk": [{ "size": 40, "volume_type": "SATA", "disk_type": "SYS" }], "personality": [{ "path": "/etc/p1.txt", "content": utils.b64encode("p1") }, { "path": "/etc/p2.txt", "content": utils.b64encode("p2") }], "metadata": { "tag": "app", "node": "node2" }, "key_name": key_name } return conn.auto_scaling.create_config(name, **_config)