本文整理汇总了Python中core.models.Instance.caller方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.caller方法的具体用法?Python Instance.caller怎么用?Python Instance.caller使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Instance
的用法示例。
在下文中一共展示了Instance.caller方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_site_allocation
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import caller [as 别名]
def save_site_allocation(self, noAct = False, reset=False):
print "save_site_allocation, reset=",reset
if (not self._site_allocation):
# Must be a instance that was just created, and has not site_allocation
# field.
return
all_slice_instances = self.instances.all()
for site_name in self._site_allocation.keys():
desired_allocation = self._site_allocation[site_name]
# make a list of the instances for this site
instances = []
for instance in all_slice_instances:
if instance.node.site_deployment.site.name == site_name:
instances.append(instance)
# delete extra instances
while (reset and len(instances)>0) or (len(instances) > desired_allocation):
instance = instances.pop()
if (not noAct):
print "deleting instance", instance
instance.delete()
else:
print "would delete instance", instance
# add more instances
if (len(instances) < desired_allocation):
site = Site.objects.get(name = site_name)
nodes = self.get_node_allocation([site])
if (not nodes):
raise APIException(detail="no nodes in site %s" % site_name)
while (len(instances) < desired_allocation):
# pick the least allocated node
nodes = sorted(nodes, key=attrgetter("instanceCount"))
node = nodes[0]
instance = Instance(name=node.name,
slice=self,
node=node,
image = self.default_image,
flavor = self.default_flavor,
creator = self.creator,
deployment = node.site_deployment.deployment)
instance.caller = self.caller
instances.append(instance)
if (not noAct):
print "added instance", instance
instance.save()
else:
print "would add instance", instance
node.instanceCount = node.instanceCount + 1
示例2: create
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import caller [as 别名]
def create(self, name = None, index = None):
xos_args = self.get_xos_args(name=name, index=index)
instance = Instance(**xos_args)
instance.caller = self.user
instance.no_sync = True
instance.save()
self.deferred_sync.append(instance)
self.info("Created Instance '%s' on node '%s' using flavor '%s' and image '%s'" %
(str(instance), str(instance.node), str(instance.flavor), str(instance.image)))