1

我有以下织物任务:

@task
def deploy_west_ec2_ami(name, puppetClass, size='m1.small', region='us-west-1', basedn='joe', ldap='arch-ldap-01', secret='secret', subnet='subnet-d43b8abd', sgroup='sg-926578fe'):
    execute(deploy_ec2_ami, name='%s',puppetClass='%s',size='%s',region='%s',basedn='%s',ldap='%s',secret='%s',subnet='%s',sgroup='%s' %(name, puppetClass, size, region, basedn, ldap, secret, subnet, sgroup))

但是,当我运行命令时:

fab deploy_west_ec2_ami:test,java

我得到以下回溯:

            Traceback (most recent call last):
              File "/usr/local/lib/python2.6/dist-packages/fabric/main.py", line 710, in main
                *args, **kwargs
              File "/usr/local/lib/python2.6/dist-packages/fabric/tasks.py", line 321, in execute
                results['<local-only>'] = task.run(*args, **new_kwargs)
              File "/usr/local/lib/python2.6/dist-packages/fabric/tasks.py", line 113, in run
                return self.wrapped(*args, **kwargs)
              File "/home/bcarpio/Projects/githubenterprise/awsdeploy/fabfile.py", line 35, in deploy_west_ec2_ami
                execute(deploy_ec2_ami, name='%s',puppetClass='%s',size='%s',region='%s',basedn='%s',ldap='%s',secret='%s',subnet='%s',sgroup='%s' %(name, puppetClass, size, region, basedn, ldap, secret, subnet, sgroup))
            TypeError: not all arguments converted during string formatting

我不确定我明白为什么。我很确定我在这里定义的所有值都很好。

另外,当我这样运行执行任务 deploy_ec2_ami 时:

deploy_ec2_ami:test,java,m1.small,us-west-1,'dc\=test\,dc\=net',ldap-01,secret,subnet-d43b8abd,sg-926578fe

它工作得很好

4

3 回答 3

2

好的,问题是使用执行时必须定义一个主机=。我的其他 fab 任务不需要 host= 所以我只输入了常规 python:

deploy_ec2_ami (name, puppetClass, size, region, basedn, ldap, secret, subnet, sgroup)

这一切都很好。

于 2012-06-11T16:40:18.863 回答
0

您将一组关键字参数传递给该execute方法,并且只有最后一个值被视为字符串插值的目标:

sgroup='%s' %(name, puppetClass
        , size, region, basedn, ldap, secret, subnet, sgroup))

这里不需要使用字符串插值;只需将所有参数传递给execute方法:

execute(deploy_ec2_ami, name=name, puppetClass=puppetClass, size=size, region=region, basedn=basedn, ldap=ldap, secret=secret, subnet=subnet, sgroup=sgroup)
于 2012-06-11T16:37:09.417 回答
0

从线

sgroup='%s' %(name, puppetClass, size, region, basedn, ldap, secret, subnet, sgroup)

字符串插值适用于一个字符串,而不适用于所有参数。我是说

'%s %s' % (arg1, arg2)

但如果你尝试

'%s' % (arg1, arg2) 

arg2 没有空间

如果您想继续进行字符串插值,我建议您这样做:

execute(deploy_ec2_ami, name='%s' % name, puppetClass='%s' % puppetClass, size='%s' % size, region='%s' % region, and so on

由于您没有更改参数中的任何内容,因此我肯定会选择 Brian 解决方案

于 2012-06-13T09:48:39.253 回答