本文整理汇总了Python中nixops.backends.MachineState类的典型用法代码示例。如果您正苦于以下问题:Python MachineState类的具体用法?Python MachineState怎么用?Python MachineState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MachineState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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;
示例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)
示例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))
示例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
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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