本文整理汇总了Python中nixops.backends.MachineState._check方法的典型用法代码示例。如果您正苦于以下问题:Python MachineState._check方法的具体用法?Python MachineState._check怎么用?Python MachineState._check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nixops.backends.MachineState
的用法示例。
在下文中一共展示了MachineState._check方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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;
示例2: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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
示例4: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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))
示例5: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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)
示例6: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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
示例7: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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)
示例8: _check
# 需要导入模块: from nixops.backends import MachineState [as 别名]
# 或者: from nixops.backends.MachineState import _check [as 别名]
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)