本文整理汇总了Python中nixops.backends.MachineState类的典型用法代码示例。如果您正苦于以下问题:Python MachineState类的具体用法?Python MachineState怎么用?Python MachineState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MachineState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
state = self._get_vm_state(can_fail=True)
if state is None:
with self.depl._db:
self.vm_id = None
self.private_ipv4 = None
self.sata_controller_created = False
self.public_host_key = None
self.private_host_key = None
self.shared_folders = {}
self.disks = {}
self.state = self.MISSING
return
res.exists = True
#self.log("VM state is ‘{0}’".format(state))
if state == "poweroff" or state == "aborted":
res.is_up = False
self.state = self.STOPPED
elif state == "running":
res.is_up = True
self._update_ip()
MachineState._check(self, res)
else:
self.state = self.UNKNOWN
开发者ID:NixOS,项目名称:nixops,代码行数:28,代码来源:virtualbox.py
示例2: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
if self.state in (self.STOPPED, self.STOPPING):
res.is_up = ping_tcp_port(self.main_ipv4, 22)
if not res.is_up:
self.state = self.STOPPED
res.is_reachable = False
return
res.exists = True
avg = self.get_load_avg()
if avg is None:
if self.state in (self.UP, self.RESCUE):
self.state = self.UNREACHABLE
res.is_reachable = False
res.is_up = False
elif self.run_command("test -f /etc/NIXOS", check=False) != 0:
self.state = self.RESCUE
self.ssh_pinged = True
self._ssh_pinged_this_time = True
res.is_reachable = True
res.is_up = False
else:
res.is_up = True
MachineState._check(self, res)
开发者ID:pombredanne,项目名称:nixops,代码行数:28,代码来源:hetzner.py
示例3: _check
def _check(self, res):
try:
node = self.node()
res.exists = True
res.is_up = node.state == NodeState.RUNNING or node.state == NodeState.REBOOTING
if node.state == NodeState.REBOOTING or node.state == NodeState.PENDING: self.state = self.STARTING
if node.state == NodeState.STOPPED or node.state == NodeState.TERMINATED: self.state = self.STOPPED
if node.state == NodeState.UNKNOWN: self.state = self.UNKNOWN
if node.state == NodeState.RUNNING:
# check that all disks are attached
res.disks_ok = True
for k, v in self.block_device_mapping.iteritems():
disk_name = v['disk_name'] or v['disk']
if all(d.get("deviceName", None) != disk_name for d in node.extra['disks']):
res.disks_ok = False
res.messages.append("disk {0} is detached".format(disk_name))
try:
disk = self.connect().ex_get_volume(disk_name, v.get('region', None))
except libcloud.common.google.ResourceNotFoundError:
res.messages.append("disk {0} is destroyed".format(disk_name))
self.handle_changed_property('public_ipv4',
node.public_ips[0] if node.public_ips else None,
property_name = 'IP address')
if self.public_ipv4:
known_hosts.add(self.public_ipv4, self.public_host_key)
MachineState._check(self, res)
except libcloud.common.google.ResourceNotFoundError:
res.exists = False
res.is_up = False
self.state = self.MISSING;
开发者ID:andrewlmurray,项目名称:nixops,代码行数:32,代码来源:gce.py
示例4: reboot
def reboot(self, hard=False):
if hard:
self.log("sending hard reset to GCE machine...")
self.node().reboot()
self.state = self.STARTING
else:
MachineState.reboot(self, hard=hard)
开发者ID:AmineChikhaoui,项目名称:nixops,代码行数:7,代码来源:gce.py
示例5: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
self.connect()
instance = self._get_instance_by_id(self.vm_id, allow_missing=True)
old_state = self.state
#self.log("instance state is ‘{0}’".format(instance.state if instance else "gone"))
if instance is None or instance.state in {"shutting-down", "terminated"}:
self.state = self.MISSING
return
res.exists = True
if instance.state == "pending":
res.is_up = False
self.state = self.STARTING
elif instance.state == "running":
res.is_up = True
res.disks_ok = True
for k, v in self.block_device_mapping.items():
if k not in instance.block_device_mapping.keys() and v.get('volumeId', None):
res.disks_ok = False
res.messages.append("volume ‘{0}’ not attached to ‘{1}’".format(v['volumeId'], _sd_to_xvd(k)))
volume = self._get_volume_by_id(v['volumeId'], allow_missing=True)
if not volume:
res.messages.append("volume ‘{0}’ no longer exists".format(v['volumeId']))
if k in instance.block_device_mapping.keys() and instance.block_device_mapping[k].status != 'attached' :
res.disks_ok = False
res.messages.append("volume ‘{0}’ on device ‘{1}’ has unexpected state: ‘{2}’".format(v['volumeId'], _sd_to_xvd(k), instance.block_device_mapping[k].status))
if self.private_ipv4 != instance.private_ip_address or self.public_ipv4 != instance.ip_address:
self.warn("IP address has changed, you may need to run ‘nixops deploy’")
self.private_ipv4 = instance.private_ip_address
self.public_ipv4 = instance.ip_address
MachineState._check(self, res)
elif instance.state == "stopping":
res.is_up = False
self.state = self.STOPPING
elif instance.state == "stopped":
res.is_up = False
self.state = self.STOPPED
# check for scheduled events
instance_status = self._conn.get_all_instance_status(instance_ids=[instance.id])
for ist in instance_status:
if ist.events:
for e in ist.events:
res.messages.append("Event ‘{0}’:".format(e.code))
res.messages.append(" * {0}".format(e.description))
res.messages.append(" * {0} - {1}".format(e.not_before, e.not_after))
开发者ID:wizeman,项目名称:nixops,代码行数:59,代码来源:ec2.py
示例6: __init__
def __init__(self, depl, name, id):
MachineState.__init__(self, depl, name, id)
self.conn = libvirt.open('qemu:///system')
if self.conn is None:
self.log('Failed to open connection to the hypervisor')
sys.exit(1)
self._dom = None
开发者ID:thpham,项目名称:nixops,代码行数:8,代码来源:libvirtd.py
示例7: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
res.exists = True
res.is_up = nixops.util.ping_tcp_port(self.target_host, self.ssh_port)
if res.is_up:
MachineState._check(self, res)
开发者ID:Acidburn0zzz,项目名称:nixops,代码行数:8,代码来源:none.py
示例8: reboot
def reboot(self, hard=False):
if hard:
self.log("sending hard reset to droplet...")
droplet = digitalocean.Droplet(id=self.droplet_id, token=self.get_auth_token())
droplet.reboot()
self.wait_for_ssh()
self.state = self.STARTING
else:
MachineState.reboot(self, hard=hard)
开发者ID:AmineChikhaoui,项目名称:nixops,代码行数:9,代码来源:digital_ocean.py
示例9: reboot
def reboot(self, hard=False):
if hard:
self.log_start("sending hard reset to robot...")
server = self._get_server_by_ip(self.main_ipv4)
server.reboot('hard')
self.log_end("done.")
self.state = self.STARTING
self.ssh.reset()
else:
MachineState.reboot(self, hard=hard)
开发者ID:pombredanne,项目名称:nixops,代码行数:10,代码来源:hetzner.py
示例10: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
state = self._get_vm_state()
res.exists = True
#self.log("VM state is ‘{0}’".format(state))
if state == "poweroff" or state == "aborted":
res.is_up = False
self.state = self.STOPPED
elif state == "running":
res.is_up = True
self._update_ip()
MachineState._check(self, res)
else:
self.state = self.UNKNOWN
开发者ID:MostAwesomeDude,项目名称:nixops,代码行数:16,代码来源:virtualbox.py
示例11: get_keys
def get_keys(self):
keys = MachineState.get_keys(self)
# Ugly: we have to add the generated keys because they're not
# there in the first evaluation (though they are present in
# the final nix-build).
for k, v in self.block_device_mapping.items():
if v.get('encrypt', False) and v.get('passphrase', "") == "" and v.get('generatedKey', "") != "":
keys["luks-" + (v['disk_name'] or v['disk'])] = { 'text': v['generatedKey'], 'group': 'root', 'permissions': '0600', 'user': 'root'}
return keys
开发者ID:andrewlmurray,项目名称:nixops,代码行数:9,代码来源:gce.py
示例12: get_keys
def get_keys(self):
keys = MachineState.get_keys(self)
# Ugly: we have to add the generated keys because they're not
# there in the first evaluation (though they are present in
# the final nix-build).
for k, v in self.block_device_mapping.items():
if v.get('encrypt', False) and v.get('passphrase', "") == "" and v.get('generatedKey', "") != "":
keys["luks-" + _sd_to_xvd(k).replace('/dev/', '')] = v['generatedKey']
return keys
开发者ID:wizeman,项目名称:nixops,代码行数:9,代码来源:ec2.py
示例13: get_ssh_flags
def get_ssh_flags(self):
# When using a remote container host, we have to proxy the ssh
# connection to the container via the host.
flags = ["-i", self.get_ssh_private_key_file()]
if self.host == "localhost":
flags.extend(MachineState.get_ssh_flags(self))
else:
cmd = "ssh -x -a [email protected]{0} {1} nc -c {2} {3}".format(self.get_host_ssh(), " ".join(self.get_host_ssh_flags()), self.private_ipv4, self.ssh_port)
flags.extend(["-o", "ProxyCommand=" + cmd])
return flags
开发者ID:Phreedom,项目名称:nixops,代码行数:10,代码来源:container.py
示例14: _check
def _check(self, res):
if not self.vm_id:
res.exists = False
return
status = self.host_ssh.run_command("nixos-container status {0}".format(self.vm_id), capture_stdout=True).rstrip()
if status == "gone":
res.exists = False
self.state = self.MISSING
return
res.exists = True
if status == "down":
res.is_up = False
self.state = self.STOPPED
return
res.is_up = True
MachineState._check(self, res)
开发者ID:coreyoconnor,项目名称:nixops,代码行数:21,代码来源:container.py
示例15: get_keys
def get_keys(self):
keys = MachineState.get_keys(self)
# Ugly: we have to add the generated keys because they're not
# there in the first evaluation (though they are present in
# the final nix-build).
for k, v in self.block_device_mapping.items():
if v.get("encrypt", False) and v.get("passphrase", "") == "" and v.get("generatedKey", "") != "":
keys["luks-" + (v["disk_name"] or v["disk"])] = {
"text": v["generatedKey"],
"group": "root",
"permissions": "0600",
"user": "root",
}
return keys
开发者ID:thedebugger,项目名称:nixops,代码行数:14,代码来源:gce.py
示例16: switch_to_configuration
def switch_to_configuration(self, method, sync, command=None):
if self.state == self.RESCUE:
# We cannot use the mountpoint command here, because it's unable to
# detect bind mounts on files, so we just go ahead and try to
# unmount.
umount = 'if umount "{0}" 2> /dev/null; then rm -f "{0}"; fi'
cmd = '; '.join([umount.format(os.path.join("/mnt/etc", mnt))
for mnt in ("resolv.conf", "passwd", "group")])
self.run_command(cmd)
command = "chroot /mnt /nix/var/nix/profiles/system/bin/"
command += "switch-to-configuration"
res = MachineState.switch_to_configuration(self, method, sync, command)
if res not in (0, 100):
return res
if self.state == self.RESCUE and self.just_installed:
self.reboot_sync()
self.just_installed = False
return res
开发者ID:pombredanne,项目名称:nixops,代码行数:20,代码来源:hetzner.py
示例17: __init__
def __init__(self, depl, name, id):
MachineState.__init__(self, depl, name, id)
self.host_ssh = nixops.ssh_util.SSH(self.logger)
self.host_ssh.register_host_fun(self.get_host_ssh)
self.host_ssh.register_flag_fun(self.get_host_ssh_flags)
开发者ID:coreyoconnor,项目名称:nixops,代码行数:5,代码来源:container.py
示例18: address_to
def address_to(self, m):
if isinstance(m, EC2State): # FIXME: only if we're in the same region
return m.private_ipv4
return MachineState.address_to(self, m)
开发者ID:wizeman,项目名称:nixops,代码行数:4,代码来源:ec2.py
示例19: _check
def _check(self, res):
res.exists = True # can't really check
res.is_up = nixops.util.ping_tcp_port(self.target_host, self.ssh_port)
if res.is_up:
MachineState._check(self, res)
开发者ID:mbbx6spp,项目名称:nixops,代码行数:5,代码来源:none.py
示例20: __init__
def __init__(self, depl, name, id):
MachineState.__init__(self, depl, name, id)
self._conn = None
self._conn_route53 = None
开发者ID:wizeman,项目名称:nixops,代码行数:4,代码来源:ec2.py
注:本文中的nixops.backends.MachineState类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论