Ejemplo n.º 1
0
def main(interactive):
    config = Config()
    config.obtain_secret('access_key_id')
    config.obtain_secret('access_key_secret')
    if interactive:
        config.config_via_prompt()
    else:
        config.load()
    config.save()
    should_create_new = True
    if config.get('InstanceId'):
        answer = click.prompt(
            "在配置文件中找到一个已存在的实例, 是使用这个实例(y), 还是创建一个新的实例(n)? [y/n]")
        if answer.lower() == 'y':
            should_create_new = False
    if should_create_new:
        create_instance(config)
    wait_for_instance_status(config, "Stopped")
    allocate_public_ip(config)
    if config.get('DiskId'):
        # Do nothing, if DiskId and SnapshotId both found, we prefer Disk
        pass
    elif config.get('SnapshotId'):
        create_disk_from_snapshot(config)
    attach_disk(config)

    start_instance(config)
    save_instance_info(config)
def main(silent):
    config = Config()
    config.obtain_secret('access_key_id')
    config.obtain_secret('access_key_secret')
    if silent:
        config.load()
    else:
        config.config_via_prompt()
    config.save()
    should_create_new = True
    if config.get('InstanceId'):
        answer = click.prompt(
            "Detected a config file, use this for setting up ecs instance (y), or create a new one(n)? [y/n]"
        )
        if answer.lower() == 'y':
            should_create_new = False
    if should_create_new:
        create_instance(config)
    wait_for_instance_status(config, "Stopped")
    allocate_public_ip(config)
    if config.get('DiskId'):
        # Do nothing, if DiskId and SnapshotId both found, we prefer Disk
        pass
    elif config.get('SnapshotId'):
        create_disk_from_snapshot(config)
    attach_disk(config)

    save_instance_info(config)
    time.sleep(10)
    start_instance(config)
    save_instance_info(config)
Ejemplo n.º 3
0
def main():
    config = Config()
    config.obtain_secret('access_key_id')
    config.obtain_secret('access_key_secret')
    config.load()

    stop_instance(config)
    wait_for_instance_status(config, "Stopped")
    delete_instance(config)
    answer = click.prompt("是否要为当前的数据盘创建一个快照, 然后删除数据盘, 以节约费用? [y/n]")
    if answer == 'y':
        OldSnapshotId = config.get('SnapshotId')
        create_snapshot(config)
        delete_disk(config)
        if OldSnapshotId:
            delete_snapshot(config, OldSnapshotId)

    cleanup(config)
Ejemplo n.º 4
0
def main():
    config = Config()
    config.obtain_secret('access_key_id')
    config.obtain_secret('access_key_secret')
    config.load()

    stop_instance(config)
    wait_for_instance_status(config, "Stopped")
    delete_instance(config)
    answer = click.prompt("Do you want to make a snapshot, then delete disk for reducing cost? [y/n]")
    if answer == 'y':
        OldSnapshotId = config.get('SnapshotId')
        time.sleep(20)
        create_snapshot(config)
        time.sleep(20)
        delete_disk(config)
        if OldSnapshotId:
            delete_snapshot(config, OldSnapshotId)

    cleanup(config)