本文整理汇总了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()
示例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()
示例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)
示例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))
示例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)
示例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()
示例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)
示例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()
示例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)
示例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.")
示例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()