Boto 和创建我的实例时出错
Error with Boto and creating my instance
当我 运行 我的代码得到这个时,我正在创建一个具有两个子网并且在 2 个实例内但在同一子网内的 VPC。当我尝试将子网附加到实例时出现问题,我收到此错误,正如您在第一个屏幕上看到的那样,为子网设置每个显示器的名称和 ID 以分配 ID
================================================================
============== creating the VPC ====================================
================================================================
Creating VPC with name: SAS1
================================================================
============== creating the IG ======================================
================================================================
Creating Internet Gateway with name: SAS1
================================================================
============== creating the Route ===================================
================================================================
Creating Route Table with name: public
================================================================
============== creating the subnets =================================
================================================================
Creating Subnet with name: sas01 in: us-west-2a
Subnet created with the name : sub-sas1 and the ID is : Subnet:subnet-2e65af4a
Creating Subnet with name: sas02 in: us-west-2a
Subnet created with the name : sub-sas2 and the ID is : Subnet:subnet-2f65af4b
Subnet:subnet-2f65af4b
Subnet:subnet-2e65af4a
================================================================
============== creating the hosts ===================================
================================================================
Creating Security Group with name: sas-sg
Creating Instance with name: sas01
Traceback (most recent call last):
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/main.py", line 732, in main
*args, **kwargs
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/tasks.py", line 345, in execute
results['<local-only>'] = task.run(*args, **new_kwargs)
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/tasks.py", line 121, in run
return self.wrapped(*args, **kwargs)
File "/Users/Guille/Documents/git/aws_vpc_py/fabfile.py", line 25, in make_vpc
bastion_hosts = aws.make_vpc(vpc_name)
File "/Users/Guille/Documents/git/aws_vpc_py/aws.py", line 71, in make_vpc
bastion = get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, Subnet[0])
File "/Users/Guille/Documents/git/aws_vpc_py/aws.py", line 127, in get_or_create_bastion_host
key_name=key_pair.name, subnet= Subnet[0])
NameError: global name 'Subnet' is not defined
这是我 运行 的部分代码:
bastion_hosts = []
for instancia in vpc_config.sections():
if (instancia != 'vpc' ) and (instancia != 'sub-sas1' ) and ( instancia != 'sub-sas2'):
cidr_block = vpc_config.get(instancia, 'cidr_block')
bastion_host_name = vpc_config.get(instancia, 'bastion_host')
instance_type = vpc_config.get(instancia,'default_instance_type')
availability_zone = vpc_config.get(instancia, 'availability_zone')
bastion = get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, Subnet[0])
bastion_hosts.append(bastion)
print bastion_hosts
return bastion_hosts
堡垒的定义为:
def get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, subnet):
image_id = vpc_config.get('vpc', 'default_image_id')
image_login_user = vpc_config.get('vpc', 'default_image_login_user')
instance_type = vpc_config.get('vpc','default_instance_type')
key_pair = get_bastion_host_key(conn, vpc_config)
security_group = get_or_create_vpc_security_group(conn, vpc_config, vpc.id)
for reservation in fetch_running_reservations(conn, bastion_host_name, vpc.id):
for instance in reservation.instances:
public_ip = associate_elastic_ip(conn, instance)
return Node(bastion_host_name, public_ip, image_login_user, BASTION_KEY_FILE)
print 'Creating Instance with name:', bastion_host_name
reservation = conn.ec2.run_instances(image_id, instance_type=instance_type,
security_group_ids=[security_group.id],
key_name=key_pair.name, subnet= Subnet[0])
for instance in reservation.instances:
print 'Waiting for', bastion_host_name, instance.id, 'to start ...'
wait_until(instance, 'running')
tag_with_name(instance, bastion_host_name)
public_ip = associate_elastic_ip(conn, instance)
print bastion_host_name, 'is associated with Elastic IP', public_ip
return Node(bastion_host_name, public_ip, image_login_user, BASTION_KEY_FILE)
有什么帮助吗??
当作用域中没有定义这样的变量时,您正试图使用 Subnet[0]
。由于您将 subnet
传递给 get_or_create_bastion_host
,因此您应该使用 subnet
而不是 Subnet[0]
。
get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, 子网)
要使其工作,请尝试将传递的 subnet
分配给参数 subnet
:
reservation = conn.ec2.run_instances(image_id, instance_type=instance_type,
security_group_ids=[security_group.id],
key_name=key_pair.name, subnet_id=subnet)
当我 运行 我的代码得到这个时,我正在创建一个具有两个子网并且在 2 个实例内但在同一子网内的 VPC。当我尝试将子网附加到实例时出现问题,我收到此错误,正如您在第一个屏幕上看到的那样,为子网设置每个显示器的名称和 ID 以分配 ID
================================================================
============== creating the VPC ====================================
================================================================
Creating VPC with name: SAS1
================================================================
============== creating the IG ======================================
================================================================
Creating Internet Gateway with name: SAS1
================================================================
============== creating the Route ===================================
================================================================
Creating Route Table with name: public
================================================================
============== creating the subnets =================================
================================================================
Creating Subnet with name: sas01 in: us-west-2a
Subnet created with the name : sub-sas1 and the ID is : Subnet:subnet-2e65af4a
Creating Subnet with name: sas02 in: us-west-2a
Subnet created with the name : sub-sas2 and the ID is : Subnet:subnet-2f65af4b
Subnet:subnet-2f65af4b
Subnet:subnet-2e65af4a
================================================================
============== creating the hosts ===================================
================================================================
Creating Security Group with name: sas-sg
Creating Instance with name: sas01
Traceback (most recent call last):
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/main.py", line 732, in main
*args, **kwargs
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/tasks.py", line 345, in execute
results['<local-only>'] = task.run(*args, **new_kwargs)
File "/Users/Guille/Documents/git/aws_vpc_py/venv/lib/python2.7/site-packages/fabric/tasks.py", line 121, in run
return self.wrapped(*args, **kwargs)
File "/Users/Guille/Documents/git/aws_vpc_py/fabfile.py", line 25, in make_vpc
bastion_hosts = aws.make_vpc(vpc_name)
File "/Users/Guille/Documents/git/aws_vpc_py/aws.py", line 71, in make_vpc
bastion = get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, Subnet[0])
File "/Users/Guille/Documents/git/aws_vpc_py/aws.py", line 127, in get_or_create_bastion_host
key_name=key_pair.name, subnet= Subnet[0])
NameError: global name 'Subnet' is not defined
这是我 运行 的部分代码:
bastion_hosts = []
for instancia in vpc_config.sections():
if (instancia != 'vpc' ) and (instancia != 'sub-sas1' ) and ( instancia != 'sub-sas2'):
cidr_block = vpc_config.get(instancia, 'cidr_block')
bastion_host_name = vpc_config.get(instancia, 'bastion_host')
instance_type = vpc_config.get(instancia,'default_instance_type')
availability_zone = vpc_config.get(instancia, 'availability_zone')
bastion = get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, Subnet[0])
bastion_hosts.append(bastion)
print bastion_hosts
return bastion_hosts
堡垒的定义为:
def get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, subnet):
image_id = vpc_config.get('vpc', 'default_image_id')
image_login_user = vpc_config.get('vpc', 'default_image_login_user')
instance_type = vpc_config.get('vpc','default_instance_type')
key_pair = get_bastion_host_key(conn, vpc_config)
security_group = get_or_create_vpc_security_group(conn, vpc_config, vpc.id)
for reservation in fetch_running_reservations(conn, bastion_host_name, vpc.id):
for instance in reservation.instances:
public_ip = associate_elastic_ip(conn, instance)
return Node(bastion_host_name, public_ip, image_login_user, BASTION_KEY_FILE)
print 'Creating Instance with name:', bastion_host_name
reservation = conn.ec2.run_instances(image_id, instance_type=instance_type,
security_group_ids=[security_group.id],
key_name=key_pair.name, subnet= Subnet[0])
for instance in reservation.instances:
print 'Waiting for', bastion_host_name, instance.id, 'to start ...'
wait_until(instance, 'running')
tag_with_name(instance, bastion_host_name)
public_ip = associate_elastic_ip(conn, instance)
print bastion_host_name, 'is associated with Elastic IP', public_ip
return Node(bastion_host_name, public_ip, image_login_user, BASTION_KEY_FILE)
有什么帮助吗??
当作用域中没有定义这样的变量时,您正试图使用 Subnet[0]
。由于您将 subnet
传递给 get_or_create_bastion_host
,因此您应该使用 subnet
而不是 Subnet[0]
。
get_or_create_bastion_host(conn, vpc_config, bastion_host_name, vpc, 子网)
要使其工作,请尝试将传递的 subnet
分配给参数 subnet
:
reservation = conn.ec2.run_instances(image_id, instance_type=instance_type,
security_group_ids=[security_group.id],
key_name=key_pair.name, subnet_id=subnet)