当前位置: 首页>>代码示例>>Python>>正文


Python digitalocean.Manager方法代码示例

本文整理汇总了Python中digitalocean.Manager方法的典型用法代码示例。如果您正苦于以下问题:Python digitalocean.Manager方法的具体用法?Python digitalocean.Manager怎么用?Python digitalocean.Manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在digitalocean的用法示例。


在下文中一共展示了digitalocean.Manager方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_inventory

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def create_inventory():
    manager = digitalocean.Manager(token=token)
    my_droplets = manager.get_all_droplets()
    data = "{'ssh_user': 'root'}"

    main_inventory = open('do_inv.py', 'w')
    puppet_inventory = open('puppet/do_inv.py', 'w')

    for droplet in my_droplets:
        if droplet.name.startswith('pyinfra-'):
            ip = droplet.networks['v4'][0]['ip_address']
            parts = droplet.name.split('-')
            line = "{}_servers = [('{}', {})]\n".format(parts[1], ip, data)
            if parts[1] == 'agent' or parts[1] == 'master':
                puppet_inventory.write(line)
            main_inventory.write(line)
    main_inventory.close()
    puppet_inventory.close() 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:20,代码来源:do.py

示例2: up

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def up():
    manager = digitalocean.Manager(token=token)
    keys = manager.get_all_sshkeys()
    for name in ubuntu:
        droplet = digitalocean.Droplet(token=token,
                                       name=name,
                                       region='sfo2',
                                       image='ubuntu-18-04-x64',
                                       size_slug='s-2vcpu-2gb',
                                       ssh_keys=keys,
                                       backups=False)
        droplet.create()
    for name in centos:
        droplet = digitalocean.Droplet(token=token,
                                       name=name,
                                       region='sfo2',
                                       image='centos-7-x64',
                                       size_slug='s-2vcpu-2gb',
                                       ssh_keys=keys,
                                       backups=False)
        droplet.create() 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:23,代码来源:do.py

示例3: validate_disk_identifier

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def validate_disk_identifier(disk_id: Dict) -> DiskIdentifier:
    try:
        do_volumes = digitalocean.Manager().get_all_volumes()
        volume_name = disk_id['volumeName']
        do_volume = next((volume for volume in do_volumes
                          if volume.name == volume_name),
                         None)

        if do_volume is None:
            raise InvalidVolumeNameError(volume_name)

        return DODiskIdentifier(volume_id=do_volume.id)
    except InvalidVolumeNameError as err:
        raise err
    except:
        raise ValueError(disk_id) 
开发者ID:miracle2k,项目名称:k8s-snapshots,代码行数:18,代码来源:digitalocean.py

示例4: load_snapshots

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def load_snapshots(
    ctx: Context, label_filters: Dict[str, str]
) -> List[Snapshot]:
    snapshots = digitalocean.Manager().get_volume_snapshots()

    tag_filters = set(k+':'+v for k, v in label_filters.items())
    filtered = [snapshot
                for snapshot in snapshots
                if tag_filters.intersection(snapshot.tags)]

    _logger.debug('digitalocean.load_snaphots', label_filters=label_filters,
                  tag_filters=tag_filters, snapshots_count=len(snapshots),
                  filtered=filtered)

    return list(map(lambda snapshot: Snapshot(
        name=snapshot.id,
        created_at=pendulum.parse(snapshot.created_at),
        disk=DODiskIdentifier(volume_id=snapshot.resource_id),
    ), filtered)) 
开发者ID:miracle2k,项目名称:k8s-snapshots,代码行数:21,代码来源:digitalocean.py

示例5: list

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def list():
    manager = digitalocean.Manager(token=token)
    my_droplets = manager.get_all_droplets()
    for droplet in my_droplets:
        if droplet.name.startswith('pyinfra-'):
            # if still booting there will be no ip address yet
            ip = 'none'
            try:
                ip = droplet.networks['v4'][0]['ip_address']
            except digitalocean.NotFoundError:
                pass
            print(droplet.name, droplet.status, ip) 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:14,代码来源:do.py

示例6: down

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def down():
    manager = digitalocean.Manager(token=token)
    my_droplets = manager.get_all_droplets()
    for droplet in my_droplets:
        if droplet.name in names:
            print('destroying droplet:{}'.format(droplet.name))
            droplet.destroy() 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:9,代码来源:do.py

示例7: list

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def list():
    manager = digitalocean.Manager(token=token)
    my_droplets = manager.get_all_droplets()
    for droplet in my_droplets:
        ip = ''
        try:
            ip = droplet.networks['v4'][0]['ip_address']
        except IndexError:
            pass
        print(droplet.name, droplet.status, ip) 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:12,代码来源:do.py

示例8: drop

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def drop():
    manager = digitalocean.Manager(token=token)
    my_droplets = manager.get_all_droplets()
    for droplet in my_droplets:
        if droplet.name == 'Example':
            print('destroying droplet:{}'.format(droplet.name))
            droplet.destroy() 
开发者ID:Fizzadar,项目名称:pyinfra,代码行数:9,代码来源:do.py

示例9: get_isp_obj

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def get_isp_obj(self, **kwargs: dict):
        return digitalocean.Manager(token=self.api_token) 
开发者ID:QAX-A-Team,项目名称:LuWu,代码行数:4,代码来源:isp.py

示例10: exit_if_droplet_exists

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def exit_if_droplet_exists(my_token: str, username: str, recreate: bool) -> None:
    print(f"Checking to see if droplet for {username} already exists...")
    manager = digitalocean.Manager(token=my_token)
    my_droplets = manager.get_all_droplets()
    for droplet in my_droplets:
        if droplet.name.lower() == f"{username}.zulipdev.org":
            if not recreate:
                print("Droplet for user {} already exists. Pass --recreate if you "
                      "need to recreate the droplet.".format(username))
                sys.exit(1)
            else:
                print(f"Deleting existing droplet for {username}.")
                droplet.destroy()
                return
    print("...No droplet found...proceeding.") 
开发者ID:zulip,项目名称:zulip,代码行数:17,代码来源:create.py

示例11: delete_snapshot

# 需要导入模块: import digitalocean [as 别名]
# 或者: from digitalocean import Manager [as 别名]
def delete_snapshot(
    ctx: Context,
    snapshot: Snapshot
):
    do_snapshot = digitalocean.Manager().get_snapshot(snapshot.name)
    do_snapshot.destroy() 
开发者ID:miracle2k,项目名称:k8s-snapshots,代码行数:8,代码来源:digitalocean.py


注:本文中的digitalocean.Manager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。