本文整理汇总了Python中cm.models.vm.VM.get_by_ip方法的典型用法代码示例。如果您正苦于以下问题:Python VM.get_by_ip方法的具体用法?Python VM.get_by_ip怎么用?Python VM.get_by_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cm.models.vm.VM
的用法示例。
在下文中一共展示了VM.get_by_ip方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_data
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def user_data(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
user_data = vm.long_dict['user_data']
return base64.b64decode( user_data )
示例2: get_command
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def get_command(remote_ip, **kw):
"""
@param_post{remote_ip,string}
@param_post{kw,dict} keyword params
@returns{Command} next command from the que to the asking VM
"""
vm = VM.get_by_ip(remote_ip)
log.debug(0, "Get first command for %s" % vm.id)
command = vm.command_set.filter(state=command_states['pending']).order_by('id')
if len(command) == 0:
return response('ctx_no_command')
command = command[0]
log.debug(0, "First command is %s" % command.id)
command.state = command_states['executing']
command.save()
d = command.dict()
r = response('ok', d)
if int(kw.get('version', 0)) < VERSION:
f = file(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'actions.py'), 'r')
r['actions_file'] = f.read()
f.close()
return r
示例3: reservation_id
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def reservation_id(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
reservation_id = vm.long_dict['reservation_id']
return 'r-' + str(reservation_id)
示例4: instance_id
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def instance_id(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
vm_id = 'i-' + str(vm.dict['vm_id'])
return vm_id
示例5: ami_id
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def ami_id(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
ami = 'ami-' + str(vm.dict['image_id'])
return ami
示例6: hello
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def hello(vm_ip, **args):
"""
First function which must be called by VMs ctx module. It registers VM with status 'running ctx',
also serves a special role when creating farms (tracking head, and worker nodes)
@parameter{vm_ip,string}
@parameter{args}
"""
vm = VM.get_by_ip(vm_ip)
log.debug(vm.user_id, "Hello from vm %d ip: %s" % (vm.id, vm_ip))
vm.ctx_api_version = args.get('version', None)
vm.state = vm_states['running ctx']
if vm.ssh_username and vm.ssh_key:
Command.execute('add_ssh_key', vm.user_id, vm.id, user=vm.ssh_username, ssh_key=vm.ssh_key)
if vm.is_head():
Command.register_head(vm)
elif vm.is_farm():
Command.register_node(vm)
try:
vm.save(update_fields=['state', 'ctx_api_version'])
except Exception, e:
log.error(vm.user_id, "Cannot update database for vm %d: %s" % (vm.id, e.message))
return response('ctx_error', "Cannot update database: %s" % e.message)
示例7: ami_launch_index
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def ami_launch_index(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
instance_id = vm.dict['vm_id']
reservation_id = vm.long_dict['reservation_id']
launch_index = reservation_id - instance_id + 1;
return launch_index
示例8: public_ipv4
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def public_ipv4(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
leases = vm.dict['leases']
ip = leases
for ip in leases:
if ip.get('public_ip'):
ip = ip.get('public_ip')
else:
ip = ""
return ip
示例9: hello
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def hello(remote_ip, **kw):
"""
REST stub for hello function
@parameter{kw}
@returns HTTP response
"""
vm = VM.get_by_ip(remote_ip)
log.info(vm.user_id, "vm called hello")
Command.hello(remote_ip)
r = response('ok')
if int(kw.get('version', 0)) < VERSION:
f = file(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'actions.py'), 'r')
r['actions_file'] = f.read()
f.close()
return r
示例10: public_keys
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def public_keys(request, number=None, key_type=None):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
if number == "0" and vm.long_dict.get('ssh_key'):
if key_type == "openssh-key": # HARDCODED VALUE, only one key can be assigned
return vm.long_dict.get('ssh_key')
else:
if key_type:
pass # todo error
else:
return "openssh-key"
else:
if number or key_type:
pass # todo error
if vm.long_dict.get('ssh_key'):
return '0=public-key'
示例11: finish_command
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def finish_command(remote_ip, command_id, status, returns=None, **kw):
"""
REST stub for finish_command
@param_post{remote_ip,string}
@param_post{command_id,string} hash string identyfing command
@param_post{status,string}
@param_post{returns,dict} dictionary containing VM returned values
@param_post{kw,dict} keyword params
"""
vm = VM.get_by_ip(remote_ip)
if returns:
returns = json.dumps(returns)
log.debug(0, "Select command %s %s" % (command_id, status))
try:
command = vm.command_set.get(id=command_id)
except Command.DoesNotExist:
return
log.debug(0, "Finish command %s" % command)
if command is None:
for c in Command.objects.all():
log.debug(0, 'Finish - Available cmds id:%s, state:%s, name:%s, vmid:%s' % (c.id, c.state, c.name, c.vm_id))
return
log.debug(vm.user_id, "command state %s" % command.state)
command.response = returns
command.state = command_states[status]
log.debug(vm.user_id, "Finish command %s" % command.id)
command.save()
r = response('ok')
if int(kw.get('version', 0)) < VERSION:
f = file(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'actions.py'), 'r')
r['actions_file'] = f.read()
f.close()
return r
示例12: instance_type
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import get_by_ip [as 别名]
def instance_type(request):
vm_ip = request.META.get('REMOTE_ADDR')
vm = VM.get_by_ip( vm_ip )
template_name = str(vm.dict['template_name'])
return template_name