diff options
author | Stuart Mackie <wsmackie@juniper.net> | 2016-01-21 12:36:48 -0500 |
---|---|---|
committer | Stuart Mackie <wsmackie@juniper.net> | 2016-01-21 12:36:48 -0500 |
commit | 04b52e3d980846288da476e40ef1cae26ae2d1f0 (patch) | |
tree | f5c1b505da330707e8e72d535ecfdc1a42dfe455 /Testcases | |
parent | e8244c89ecf6e79d5178a195bc52f8f6756ac7fb (diff) |
Add python helper scripts
Change-Id: I83b378941082d8f9aeae88f6cf9e586d8eb7458d
Signed-off-by: Stuart Mackie <wsmackie@juniper.net>
Diffstat (limited to 'Testcases')
-rwxr-xr-x | Testcases/RunTests.sh | 31 | ||||
-rw-r--r-- | Testcases/config_obj.py | 1737 | ||||
-rw-r--r-- | Testcases/config_shell.py | 379 | ||||
-rw-r--r-- | Testcases/configuration.md | 666 |
4 files changed, 2813 insertions, 0 deletions
diff --git a/Testcases/RunTests.sh b/Testcases/RunTests.sh index 7a916c7..8a915b9 100755 --- a/Testcases/RunTests.sh +++ b/Testcases/RunTests.sh @@ -1,6 +1,37 @@ #!/bin/bash PATH=${OVNO_COMMIT}/Testcases:$PATH +cd ${OVNO_COMMIT}/Testcases + +# Create the config wrapper +OCL_IP=`echo $OS_AUTH_URL | cut -d "/" -f3 | cut -d ":" -f1` + +cat <<EOF >config +#!/usr/bin/python + +import sys +import os +from config_shell import * +default_client_args = [ + ('--username', 'admin'), + ('--password', os.environ["OS_PASSWORD"]), + ('--region', 'RegionOne'), + ('--tenant', 'admin'), + ('--api-server', os.environ["OCL_IP"])] + + +if __name__ == '__main__': + for arg in default_client_args: + if not arg[0] in sys.argv: + sys.argv.insert(1, arg[0]) + sys.argv.insert(2, arg[1]) + ConfigShell().main() +EOF + +chmod 777 config + + + echo "Starting OpenContrail test suite" # Tests go here diff --git a/Testcases/config_obj.py b/Testcases/config_obj.py new file mode 100644 index 0000000..9470588 --- /dev/null +++ b/Testcases/config_obj.py @@ -0,0 +1,1737 @@ + +import os +import sys +import time +import uuid +from vnc_api import vnc_api +try: + import novaclient.v1_1.client + config_nova = True +except: + config_nova = False + + +class ConfigVirtualDns(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.virtual_DNSs_list()['virtual-DNSs'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == name): + return self.vnc.virtual_DNS_read(id = item['uuid']) + + def obj_show(self, obj): + print 'Virtual DNS' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + dns = obj.get_virtual_DNS_data() + print 'Domain name: %s' %(dns.domain_name) + print 'Record order: %s' %(dns.record_order) + print 'Default TTL: %s seconds' %(dns.default_ttl_seconds) + print 'Next DNS: %s' %(dns.next_virtual_DNS) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + print ' %s' %(item['fq_name'][1]) + + def add(self, name, domain_name, record_order, next_dns): + data = vnc_api.VirtualDnsType(domain_name = domain_name, + dynamic_records_from_client = True, + record_order = record_order, + default_ttl_seconds = 86400, + next_virtual_DNS = 'default-domain:' + next_dns) + obj = vnc_api.VirtualDns(name = name, virtual_DNS_data = data) + try: + self.vnc.virtual_DNS_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def delete(self, name): + try: + self.vnc.virtual_DNS_delete( + fq_name = ['default-domain', name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigIpam(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.network_ipams_list()['network-ipams'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.network_ipam_read(id = item['uuid']) + + def dns_show(self, mgmt): + print ' DNS Type: %s' %(mgmt.ipam_dns_method) + if (mgmt.ipam_dns_method == 'virtual-dns-server'): + print ' Virtual DNS Server: %s' %( + mgmt.get_ipam_dns_server().virtual_dns_server_name) + elif (mgmt.ipam_dns_method == 'tenant-dns-server'): + list = mgmt.get_ipam_dns_server().get_tenant_dns_server_address().get_ip_address() + print ' Tenant DNS Server:' + for item in list: + print ' %s' %(item) + + def dhcp_show(self, mgmt): + dhcp_opt = {'4':'NTP Server', '15':'Domain Name'} + print ' DHCP Options:' + dhcp = mgmt.get_dhcp_option_list() + if not dhcp: + return + for item in dhcp.get_dhcp_option(): + print ' %s: %s' %(dhcp_opt[item.dhcp_option_name], + item.dhcp_option_value) + + def obj_show(self, obj): + print 'IPAM' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + print 'Management:' + mgmt = obj.get_network_ipam_mgmt() + if not mgmt: + return + self.dns_show(mgmt) + self.dhcp_show(mgmt) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def dns_add(self, mgmt, dns_type, virtual_dns = None, tenant_dns = None): + type = {'none':'none', + 'default':'default-dns-server', + 'virtual':'virtual-dns-server', + 'tenant':'tenant-dns-server'} + if not dns_type: + return + mgmt.set_ipam_dns_method(type[dns_type]) + if virtual_dns: + mgmt.set_ipam_dns_server(vnc_api.IpamDnsAddressType( + virtual_dns_server_name = virtual_dns)) + if tenant_dns: + mgmt.set_ipam_dns_server(vnc_api.IpamDnsAddressType( + tenant_dns_server_address = vnc_api.IpAddressesType( + ip_address = tenant_dns))) + + def dhcp_add(self, mgmt, domain_name = None, ntp_server = None): + if domain_name: + list = mgmt.get_dhcp_option_list() + if not list: + list = vnc_api.DhcpOptionsListType() + mgmt.set_dhcp_option_list(list) + list.add_dhcp_option(vnc_api.DhcpOptionType( + dhcp_option_name = '15', + dhcp_option_value = domain_name)) + if ntp_server: + list = mgmt.get_dhcp_option_list() + if not list: + list = vnc_api.DhcpOptionsListType() + mgmt.set_dhcp_option_list() + list.add_dhcp_option(vnc_api.DhcpOptionType( + dhcp_option_name = '4', + dhcp_option_value = ntp_server)) + + def add(self, name, dns_type, virtual_dns = None, tenant_dns = None, + domain_name = None, ntp_server = None): + create = False + obj = self.obj_get(name) + if not obj: + obj = vnc_api.NetworkIpam(name = name, + parent_obj = self.tenant) + create = True + mgmt = obj.get_network_ipam_mgmt() + if not mgmt: + mgmt = vnc_api.IpamType() + obj.set_network_ipam_mgmt(mgmt) + self.dns_add(mgmt, dns_type, virtual_dns, tenant_dns) + self.dhcp_add(mgmt, domain_name, ntp_server) + if create: + try: + self.vnc.network_ipam_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + self.vnc.network_ipam_update(obj) + + def delete(self, name, domain_name = None): + update = False + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + if domain_name: + mgmt = obj.get_network_ipam_mgmt() + list = mgmt.get_dhcp_option_list() + for item in list.get_dhcp_option(): + if (item.dhcp_option_name == '15') and \ + (item.dhcp_option_value == domain_name): + list.delete_dhcp_option(item) + break + update = True + if update: + self.vnc.network_ipam_update(obj) + else: + try: + self.vnc.network_ipam_delete( + fq_name = ['default-domain', self.tenant.name, + name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigPolicy(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.network_policys_list()['network-policys'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.network_policy_read(id = item['uuid']) + + def addr_show(self, addr_list): + for item in addr_list: + print ' Virtual Network: %s' %(item.get_virtual_network()) + + def port_show(self, port_list): + for item in port_list: + print ' %d:%d' %(item.get_start_port(), item.get_end_port()) + + def action_show(self, rule): + list = rule.get_action_list() + if not list: + return + action = list.get_simple_action() + if action: + print ' %s' %(action) + else: + for item in rule.get_action_list().get_apply_service(): + print ' %s' %(item) + + def rule_show(self, obj): + rules_obj = obj.get_network_policy_entries() + if (rules_obj == None): + return + list = rules_obj.get_policy_rule() + count = 1 + for rule in list: + print 'Rule #%d' %(count) + print ' Direction: %s' %(rule.get_direction()) + print ' Protocol: %s' %(rule.get_protocol()) + print ' Source Addresses:' + self.addr_show(rule.get_src_addresses()) + print ' Source Ports:' + self.port_show(rule.get_src_ports()) + print ' Destination Addresses:' + self.addr_show(rule.get_dst_addresses()) + print ' Destination Ports:' + self.port_show(rule.get_dst_ports()) + print ' Action:' + self.action_show(rule) + count += 1 + + def obj_show(self, obj): + print 'Policy' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + self.rule_show(obj) + list = obj.get_virtual_network_back_refs() + if (list != None): + print '[BR] network:' + for item in list: + print ' %s' %(item['to'][2]) + + def show(self, name): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def rule_add(self, arg_list): + direction = None + protocol = None + src_net_list = [] + dst_net_list = [] + src_port_list = [] + dst_port_list = [] + action = None + service_list = [] + for arg in arg_list: + arg_name = arg.split('=')[0] + arg_val = arg.split('=')[1] + if (arg_name == 'direction'): + direction = arg_val + elif (arg_name == 'protocol'): + protocol = arg_val + elif (arg_name == 'src-net'): + net = 'default-domain:%s:%s' %(self.tenant.name, arg_val) + src_net_list.append(vnc_api.AddressType(virtual_network = net)) + elif (arg_name == 'dst-net'): + net = 'default-domain:%s:%s' %(self.tenant.name, arg_val) + dst_net_list.append(vnc_api.AddressType(virtual_network = net)) + elif (arg_name == 'src-port'): + if (arg_val == 'any'): + src_port_list.append(vnc_api.PortType( + start_port = -1, end_port = -1)) + else: + s_e = arg_val.split(':') + src_port_list.append(vnc_api.PortType( + start_port = int(s_e[0]), end_port = int(s_e[1]))) + elif (arg_name == 'dst-port'): + if (arg_val == 'any'): + src_port_list.append(vnc_api.PortType( + start_port = -1, end_port = -1)) + else: + s_e = arg_val.split(':') + src_port_list.append(vnc_api.PortType( + start_port = int(s_e[0]), end_port = int(s_e[1]))) + elif (arg_name == 'action'): + action = arg_val + elif (arg_name == 'service'): + service_list.append('default-domain:%s:%s' \ + %(self.tenant.name, arg_val)) + + rule = vnc_api.PolicyRuleType() + if not direction: + direction = '<>' + rule.set_direction(direction) + if not protocol: + protocol = 'any' + rule.set_protocol(protocol) + if not src_net_list: + src_net_list.append(vnc_api.AddressType(virtual_network = 'any')) + rule.set_src_addresses(src_net_list) + if not dst_net_list: + dst_net_list.append(vnc_api.AddressType(virtual_network = 'any')) + rule.set_dst_addresses(dst_net_list) + if not src_port_list: + src_port_list.append(vnc_api.PortType( + start_port = -1, end_port = -1)) + rule.set_src_ports(src_port_list) + if not dst_port_list: + dst_port_list.append(vnc_api.PortType( + start_port = -1, end_port = -1)) + rule.set_dst_ports(dst_port_list) + if not action: + action_list = vnc_api.ActionListType(simple_action = 'pass') + elif (action == 'service'): + action_list = vnc_api.ActionListType(apply_service = service_list) + else: + action_list = vnc_api.ActionListType(simple_action = action) + rule.set_action_list(action_list) + return rule + + def add(self, name, rule_arg_list): + rule_list = [] + if not rule_arg_list: + rule = self.rule_add([]) + rule_list.append(rule) + else: + for rule_arg in rule_arg_list: + rule = self.rule_add(rule_arg.split(',')) + rule_list.append(rule) + + obj = self.obj_get(name = name) + if obj: + rules = obj.get_network_policy_entries() + if not rules: + rules = vnc_api.PolicyEntriesType(policy_rule = rule_list) + else: + for item in rule_list: + rules.add_policy_rule(item) + obj.set_network_policy_entries(rules) + try: + self.vnc.network_policy_update(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + rules = vnc_api.PolicyEntriesType(policy_rule = rule_list) + obj = vnc_api.NetworkPolicy(name = name, + parent_obj = self.tenant, + network_policy_entries = rules) + try: + self.vnc.network_policy_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def delete(self, name, rule_arg_list): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + if rule_arg_list: + rules = obj.get_network_policy_entries() + if not rules: + return + for rule_arg in rule_arg_list: + for arg in rule_arg.split(','): + arg_name = arg.split('=')[0] + arg_val = arg.split('=')[1] + if (arg_name == 'index'): + rule = rules.get_policy_rule()[int(arg_val) - 1] + rules.delete_policy_rule(rule) + obj.set_network_policy_entries(rules) + self.vnc.network_policy_update(obj) + else: + try: + self.vnc.network_policy_delete(fq_name = ['default-domain', + self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigSecurityGroup(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.security_groups_list()['security-groups'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.security_group_read(id = item['uuid']) + + def addr_show(self, addr_list): + for item in addr_list: + print ' Security Group: %s' %(item.get_security_group()) + subnet = item.get_subnet() + if subnet: + print ' Subnet: %s/%d' %(subnet.get_ip_prefix(), \ + subnet.get_ip_prefix_len()) + else: + print ' Subnet: None' + + def port_show(self, port_list): + for item in port_list: + print ' %d:%d' %(item.get_start_port(), item.get_end_port()) + + def rule_show(self, obj): + rules_obj = obj.get_security_group_entries() + if (rules_obj == None): + return + list = rules_obj.get_policy_rule() + count = 1 + for rule in list: + print 'Rule #%d' %(count) + print ' Direction: %s' %(rule.get_direction()) + print ' Protocol: %s' %(rule.get_protocol()) + print ' Source Addresses:' + self.addr_show(rule.get_src_addresses()) + print ' Source Ports:' + self.port_show(rule.get_src_ports()) + print ' Destination Addresses:' + self.addr_show(rule.get_dst_addresses()) + print ' Destination Ports:' + self.port_show(rule.get_dst_ports()) + count += 1 + + def obj_show(self, obj): + print 'Security Group' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + self.rule_show(obj) + + def show(self, name): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def add(self, name, protocol = None, address = None, port = None, + direction = None): + rule = vnc_api.PolicyRuleType() + rule.set_direction('>') + if protocol: + rule.set_protocol(protocol) + else: + rule.set_protocol('any') + + addr_list = [] + if address: + for item in address: + prefix = item.split('/')[0] + len = item.split('/')[1] + addr_list.append(vnc_api.AddressType( + subnet = vnc_api.SubnetType( + ip_prefix = prefix, ip_prefix_len = int(len)))) + else: + addr_list.append(vnc_api.AddressType( + subnet = vnc_api.SubnetType( + ip_prefix = '0.0.0.0', ip_prefix_len = 0))) + + local_addr_list = [vnc_api.AddressType(security_group = 'local')] + + port_list = [] + if port: + for item in port: + if (item == 'any'): + port_list.append(vnc_api.PortType( + start_port = -1, end_port = -1)) + else: + s_e = item.split(':') + port_list.append(vnc_api.PortType( + start_port = int(s_e[0]), end_port = int(s_e[1]))) + else: + port_list.append(vnc_api.PortType(start_port = -1, end_port = -1)) + + local_port_list = [vnc_api.PortType(start_port = -1, end_port = -1)] + + if (direction == 'ingress'): + rule.set_src_addresses(addr_list) + rule.set_src_ports(port_list) + rule.set_dst_addresses(local_addr_list) + rule.set_dst_ports(local_port_list) + else: + rule.set_src_addresses(local_addr_list) + rule.set_src_ports(local_port_list) + rule.set_dst_addresses(addr_list) + rule.set_dst_ports(port_list) + + obj = self.obj_get(name = name) + if obj: + rules = obj.get_security_group_entries() + if not rules: + rules = vnc_api.PolicyEntriesType(policy_rule = [rule]) + else: + rules.add_policy_rule(rule) + try: + self.vnc.security_group_update(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + rules = vnc_api.PolicyEntriesType(policy_rule = [rule]) + obj = vnc_api.SecurityGroup(name = name, + parent_obj = self.tenant, + security_group_entries = rules) + try: + self.vnc.security_group_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def rule_del(self, obj, index): + rules = obj.get_security_group_entries() + if not rules: + return + rule = rules.get_policy_rule()[index - 1] + rules.delete_policy_rule(rule) + self.vnc.security_group_update(obj) + + def delete(self, name, rule = None): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + if rule: + self.rule_del(obj, int(rule)) + else: + try: + self.vnc.security_group_delete(fq_name = ['default-domain', + self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigNetwork(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.virtual_networks_list()['virtual-networks'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.virtual_network_read(id = item['uuid']) + + def prop_route_target_show(self, obj): + print '[P] Route targets:' + rt_list = obj.get_route_target_list() + if not rt_list: + return + for rt in rt_list.get_route_target(): + print ' %s' %(rt) + + def child_floating_ip_pool_show(self, obj): + print '[C] Floating IP pools:' + pool_list = obj.get_floating_ip_pools() + if not pool_list: + return + for pool in pool_list: + print ' %s' %(pool['to'][3]) + pool_obj = self.vnc.floating_ip_pool_read(id = pool['uuid']) + ip_list = pool_obj.get_floating_ips() + if (ip_list != None): + for ip in ip_list: + ip_obj = self.vnc.floating_ip_read(id = ip['uuid']) + print ' %s' %(ip_obj.get_floating_ip_address()) + + def ref_ipam_show(self, obj): + print '[R] IPAMs:' + ipam_list = obj.get_network_ipam_refs() + if not ipam_list: + return + for item in ipam_list: + print ' %s' %(item['to'][2]) + subnet_list = item['attr'].get_ipam_subnets() + for subnet in subnet_list: + print ' subnet: %s/%d, gateway: %s' %( + subnet.get_subnet().get_ip_prefix(), + subnet.get_subnet().get_ip_prefix_len(), + subnet.get_default_gateway()) + + def ref_policy_show(self, obj): + print '[R] Policies:' + policy_list = obj.get_network_policy_refs() + if not policy_list: + return + for item in policy_list: + print ' %s (%d.%d)' %(item['to'][2], + item['attr'].get_sequence().get_major(), + item['attr'].get_sequence().get_minor()) + + def ref_route_table_show(self, obj): + print '[R] Route Tables:' + rt_list = obj.get_route_table_refs() + if not rt_list: + return + for item in rt_list: + print ' %s' %(item['to'][2]) + + def obj_show(self, obj): + print 'Virtual Network' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + self.prop_route_target_show(obj) + self.child_floating_ip_pool_show(obj) + self.ref_ipam_show(obj) + self.ref_policy_show(obj) + self.ref_route_table_show(obj) + + def show(self, name): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def ipam_add(self, obj, name, subnet, gateway = None): + try: + ipam_obj = self.vnc.network_ipam_read(fq_name = ['default-domain', + self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + cidr = subnet.split('/') + subnet = vnc_api.SubnetType(ip_prefix = cidr[0], + ip_prefix_len = int(cidr[1])) + ipam_subnet = vnc_api.IpamSubnetType(subnet = subnet, + default_gateway = gateway) + obj.add_network_ipam(ref_obj = ipam_obj, + ref_data = vnc_api.VnSubnetsType([ipam_subnet])) + + def ipam_del(self, obj, name): + try: + ipam_obj = self.vnc.network_ipam_read(fq_name = ['default-domain', + self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.del_network_ipam(ref_obj = ipam_obj) + + def policy_add(self, obj, name): + try: + policy_obj = self.vnc.network_policy_read( + fq_name = ['default-domain', self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + seq = vnc_api.SequenceType(major = 0, minor = 0) + obj.add_network_policy(ref_obj = policy_obj, + ref_data = vnc_api.VirtualNetworkPolicyType(sequence = seq)) + + def policy_del(self, obj, name): + try: + policy_obj = self.vnc.network_policy_read( + fq_name = ['default-domain', self.tenant.name, name]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.del_network_policy(ref_obj = policy_obj) + + def route_target_add(self, obj, rt): + rt_list = obj.get_route_target_list() + if not rt_list: + rt_list = vnc_api.RouteTargetList() + obj.set_route_target_list(rt_list) + rt_list.add_route_target('target:%s' %(rt)) + + def route_target_del(self, obj, rt): + rt_list = obj.get_route_target_list() + if not rt_list: + return + rt_list.delete_route_target('target:%s' %(rt)) + + def route_table_add(self, obj, rt): + try: + rt_obj = self.vnc.route_table_read(fq_name = ['default-domain', + self.tenant.name, rt]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.add_route_table(ref_obj = rt_obj) + + def route_table_del(self, obj, rt): + try: + rt_obj = self.vnc.route_table_read(fq_name = ['default-domain', + self.tenant.name, rt]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.del_route_table(ref_obj = rt_obj) + + def add(self, name, ipam = None, subnet = None, policy = None, + route_target = None, route_table = None, shared = None, + external = None, l2 = None): + create = False + obj = self.obj_get(name) + if not obj: + obj = vnc_api.VirtualNetwork(name = name, + parent_obj = self.tenant) + if l2: + prop = vnc_api.VirtualNetworkType(forwarding_mode = 'l2') + obj.set_virtual_network_properties(prop) + if shared: + obj.set_is_shared(shared) + if external: + obj.set_router_external(external) + create = True + if ipam and subnet: + self.ipam_add(obj, ipam, subnet) + if policy: + self.policy_add(obj, policy) + if route_target: + self.route_target_add(obj, route_target) + if route_table: + self.route_table_add(obj, route_table) + if create: + try: + self.vnc.virtual_network_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + self.vnc.virtual_network_update(obj) + + def delete(self, name, ipam = None, policy = None, route_target = None, + route_table = None): + update = False + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + if ipam: + self.ipam_del(obj, ipam) + update = True + if policy: + self.policy_del(obj, policy) + update = True + if route_target: + self.route_target_del(obj, route_target) + update = True + if route_table: + self.route_table_del(obj, route_table) + update = True + if update: + self.vnc.virtual_network_update(obj) + else: + try: + self.vnc.virtual_network_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigFloatingIpPool(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.floating_ip_pools_list()['floating-ip-pools'] + return list + + def obj_get(self, name, network = None): + for item in self.obj_list(): + if network: + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == network) and \ + (item['fq_name'][3] == name): + return self.vnc.floating_ip_pool_read(id = item['uuid']) + else: + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][3] == name): + return self.vnc.floating_ip_pool_read(id = item['uuid']) + + def prop_subnet_show(self, obj): + print '[P] Subnet:' + prefixes = obj.get_floating_ip_pool_prefixes() + if not prefixes: + return + for item in prefixes.get_subnet(): + print ' %s/%s' %(item.get_ip_prefix(), item.get_ip_prefix_len()) + + def child_ip_show(self, obj): + print '[C] Floating IPs:' + list = obj.get_floating_ips() + if not list: + return + for ip in list: + ip_obj = self.vnc.floating_ip_read(id = ip['uuid']) + print ' %s' %(ip_obj.get_floating_ip_address()) + + def back_ref_tenant_show(self, obj): + print '[BR] Tenants:' + list = obj.get_project_back_refs() + if not list: + return + for item in list: + print ' %s' %(item['to'][1]) + + def obj_show(self, obj): + print 'Floating IP Pool' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + self.prop_subnet_show(obj) + self.child_ip_show(obj) + self.back_ref_tenant_show(obj) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s in network %s' \ + %(item['fq_name'][2], item['fq_name'][3]) + + def add(self, name, network): + if not name: + print 'ERROR: The name of floating IP pool is not specified!' + return + if not network: + print 'ERROR: Network is not specified!' + return + try: + net_obj = self.vnc.virtual_network_read( + fq_name = ['default-domain', self.tenant.name, network]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj = vnc_api.FloatingIpPool(name = name, parent_obj = net_obj) + try: + self.vnc.floating_ip_pool_create(obj) + self.tenant.add_floating_ip_pool(obj) + self.vnc.project_update(self.tenant) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def fip_delete(self, pool_obj): + pass + + def delete(self, name, network): + if not name: + print 'ERROR: The name of floating IP pool is not specified!' + return + obj = self.obj_get(name, network) + if not obj: + print 'ERROR: Floating IP pool %s in network %s is not found!' \ + %(name, network) + return + if obj.get_floating_ips(): + print 'ERROR: There are allocated floating IPs!' + return + for tenant_ref in obj.get_project_back_refs(): + tenant = self.vnc.project_read(fq_name = tenant_ref['to']) + tenant.del_floating_ip_pool(obj) + self.vnc.project_update(tenant) + try: + self.vnc.floating_ip_pool_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigServiceTemplate(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.service_templates_list()['service-templates'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == name): + return self.vnc.service_template_read(id = item['uuid']) + + def obj_show(self, obj): + print 'Service Template' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + properties = obj.get_service_template_properties() + print 'Service Mode: %s' %(properties.get_service_mode()) + print 'Service Type: %s' %(properties.get_service_type()) + print 'Service Image: %s' %(properties.get_image_name()) + print 'Service Flavor: %s' %(properties.get_flavor()) + print 'Service Interfaces:' + for item in properties.get_interface_type(): + print ' %s' %(item.get_service_interface_type()) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + print ' %s' %(item['fq_name'][1]) + + def add(self, name, mode, type, image, flavor, interface_type, + scale = None): + obj = vnc_api.ServiceTemplate(name = name) + properties = vnc_api.ServiceTemplateType(service_mode = mode, + service_type = type, image_name = image, flavor = flavor, + ordered_interfaces = True, availability_zone_enable = True) + if scale: + properties.set_service_scaling(scale) + for item in interface_type: + if (mode == 'transparent') and \ + ((item == 'left') or (item == 'right')): + shared_ip = True + elif (mode == 'in-network') and (item == 'left'): + shared_ip = True + else: + shared_ip = False + type = vnc_api.ServiceTemplateInterfaceType( + service_interface_type = item, + shared_ip = shared_ip, + static_route_enable = True) + properties.add_interface_type(type) + else: + for item in interface_type: + type = vnc_api.ServiceTemplateInterfaceType( + service_interface_type = item, + static_route_enable = True) + properties.add_interface_type(type) + obj.set_service_template_properties(properties) + try: + self.vnc.service_template_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def delete(self, name): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + try: + self.vnc.service_template_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigServiceInstance(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.service_instances_list()['service-instances'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.service_instance_read(id = item['uuid']) + + def obj_show(self, obj): + print 'Service Instance' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + + def show(self, name): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def add(self, name, template, network_list, + auto_policy = None, scale_max = None): + obj = vnc_api.ServiceInstance(name = name, parent_obj = self.tenant) + properties = vnc_api.ServiceInstanceType(auto_policy = auto_policy) + for net in network_list: + net_name = None + net_route = None + net_auto = False + tenant_name = self.tenant.name + for arg in net.split(','): + arg_name = arg.split('=')[0] + arg_val = arg.split('=')[1] + if (arg_name == 'tenant'): + tenant_name = arg_val + elif (arg_name == 'network'): + if (arg_val == 'auto'): + net_auto = True + else: + net_name = arg_val + elif (arg_name == 'route'): + net_route = arg_val + if net_auto: + net_fq_name = None + else: + net_fq_name = 'default-domain:%s:%s' %(tenant_name, net_name) + interface = vnc_api.ServiceInstanceInterfaceType( + virtual_network = net_fq_name) + if net_route: + route = vnc_api.RouteType(prefix = net_route) + route_table = vnc_api.RouteTableType() + route_table.add_route(route) + interface.set_static_routes(route_table) + properties.add_interface_list(interface) + + if scale_max: + scale = vnc_api.ServiceScaleOutType( + max_instances = int(scale_max), + auto_scale = True) + else: + scale = vnc_api.ServiceScaleOutType() + properties.set_scale_out(scale) + + obj.set_service_instance_properties(properties) + try: + template = self.vnc.service_template_read( + fq_name = ['default-domain', template]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + obj.set_service_template(template) + try: + self.vnc.service_instance_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + def delete(self, name): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + try: + self.vnc.service_instance_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigImage(): + def __init__(self, client): + self.nova = client.nova + + def obj_list(self): + list = self.nova.images.list() + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item.name == name): + return item + + def obj_show(self, obj): + print 'Image' + print 'Name: %s' %(obj.name) + print 'UUID: %s' %(obj.id) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + print ' %s' %(item.name) + + def add(self, name): + pass + def delete(self, name): + pass + + +class ConfigFlavor(): + def __init__(self, client): + self.nova = client.nova + + def obj_list(self): + list = self.nova.flavors.list() + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item.name == name): + return item + + def obj_show(self, obj): + print 'Flavor' + print 'Name: %s' %(obj.name) + print 'UUID: %s' %(obj.id) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + print ' %s' %(item.name) + + def add(self, name): + pass + def delete(self, name): + pass + + +class ConfigVirtualMachine(): + def __init__(self, client): + self.vnc = client.vnc + self.nova = client.nova + self.tenant = client.tenant + + def obj_list(self): + list = self.nova.servers.list() + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item.name == name): + return item + + def obj_show(self, obj): + print 'Virtual Machine' + print 'Name: %s' %(obj.name) + print 'UUID: %s' %(obj.id) + print 'Status: %s' %(obj.status) + print 'Addresses:' + for item in obj.addresses.keys(): + print ' %s %s' %(obj.addresses[item][0]['addr'], item) + + def show(self, name): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + print ' %s' %(item.name) + + def add(self, name, image, flavor, network, node = None, user_data = None, + wait = None): + try: + image_obj = self.nova.images.find(name = image) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + try: + flavor_obj = self.nova.flavors.find(name = flavor) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + + networks = [] + net_list = self.vnc.virtual_networks_list()['virtual-networks'] + for item in network: + for vn in net_list: + if (vn['fq_name'][1] == self.tenant.name) and \ + (vn['fq_name'][2] == item): + networks.append({'net-id': vn['uuid']}) + break + else: + print 'ERROR: Network %s is not found!' %(item) + return + + #if node: + # zone = self.nova.availability_zones.list()[1] + # for item in zone.hosts.keys(): + # if (item == node): + # break + # else: + # print 'ERROR: Node %s is not found!' %(name) + # return + + try: + vm = self.nova.servers.create(name = name, image = image_obj, + flavor = flavor_obj, availability_zone = node, + nics = networks, userdata = user_data) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + + if wait: + timeout = 12 + while timeout: + time.sleep(3) + vm = self.nova.servers.get(vm.id) + if vm.status != 'BUILD': + print 'VM %s is %s' %(vm.name, vm.status) + break + timeout -= 1 + + def delete(self, name): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + self.nova.servers.delete(obj.id) + + +class ConfigRouteTable(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.route_tables_list()['route-tables'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.route_table_read(id = item['uuid']) + + def obj_show(self, obj): + print 'Route Table' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + routes = obj.get_routes() + if not routes: + return + for item in routes.get_route(): + print ' %s next-hop %s' %(item.get_prefix(), item.get_next_hop()) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def route_add(self, obj, route): + routes = obj.get_routes() + if not routes: + routes = vnc_api.RouteTableType() + obj.set_routes(routes) + prefix = route.split(':')[0] + nh = 'default-domain:%s:%s' %(self.tenant.name, route.split(':')[1]) + routes.add_route(vnc_api.RouteType(prefix = prefix, next_hop = nh)) + + def route_del(self, obj, prefix): + routes = obj.get_routes() + if not routes: + return + for item in routes.get_route(): + if (item.get_prefix() == prefix): + routes.delete_route(item) + + def add(self, name, route = None): + create = False + obj = self.obj_get(name) + if not obj: + obj = vnc_api.RouteTable(name = name, parent_obj = self.tenant) + create = True + if route: + for item in route: + self.route_add(obj, item) + if create: + try: + self.vnc.route_table_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + self.vnc.route_table_update(obj) + + def delete(self, name, route = None): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + if route: + for item in route: + self.route_del(obj, item) + self.vnc.route_table_update(obj) + else: + try: + self.vnc.route_table_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigInterfaceRouteTable(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.interface_route_tables_list()['interface-route-tables'] + return list + + def obj_get(self, name): + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name) and \ + (item['fq_name'][2] == name): + return self.vnc.interface_route_table_read(id = item['uuid']) + + def obj_show(self, obj): + print 'Interface Route Table' + print 'Name: %s' %(obj.get_fq_name()) + print 'UUID: %s' %(obj.uuid) + routes = obj.get_interface_route_table_routes() + if not routes: + return + for item in routes.get_route(): + print ' %s' %(item.get_prefix()) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj) + else: + for item in self.obj_list(): + if (item['fq_name'][1] == self.tenant.name): + print ' %s' %(item['fq_name'][2]) + + def route_add(self, obj, prefix): + routes = obj.get_interface_route_table_routes() + if not routes: + routes = vnc_api.RouteTableType() + routes.add_route(vnc_api.RouteType(prefix = prefix)) + obj.set_interface_route_table_routes(routes) + + def route_del(self, obj, prefix): + routes = obj.get_interface_route_table_routes() + if not routes: + return + for item in routes.get_route(): + if (item.get_prefix() == prefix): + routes.delete_route(item) + obj.set_interface_route_table_routes(routes) + + def add(self, name, route = None): + create = False + obj = self.obj_get(name) + if not obj: + obj = vnc_api.InterfaceRouteTable(name = name, + parent_obj = self.tenant) + create = True + if route: + for item in route: + self.route_add(obj, item) + if create: + try: + self.vnc.interface_route_table_create(obj) + except Exception as e: + print 'ERROR: %s' %(str(e)) + else: + self.vnc.interface_route_table_update(obj) + + def delete(self, name, route = None): + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + if route: + for item in route: + self.route_del(obj, item) + self.vnc.interface_route_table_update(obj) + else: + try: + self.vnc.interface_route_table_delete(id = obj.uuid) + except Exception as e: + print 'ERROR: %s' %(str(e)) + + +class ConfigVmInterface(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + self.nova = client.nova + + def obj_list(self, vm_id = None): + list = [] + if vm_id: + vm = self.vnc.virtual_machine_read(id = vm_id) + if_ref_list = vm.get_virtual_machine_interface_back_refs() + for if_ref in if_ref_list: + if_obj = self.vnc.virtual_machine_interface_read( + id = if_ref['uuid']) + vn_name = if_obj.get_virtual_network_refs()[0]['to'][2] + list.append({'name':vn_name, 'uuid':if_ref['uuid'], + 'obj':if_obj}) + else: + for vm_nova in self.nova.servers.list(): + try: + vm = self.vnc.virtual_machine_read(id = vm_nova.id) + except Exception as e: + print 'ERROR: %s' %(str(e)) + continue + if_ref_list = vm.get_virtual_machine_interface_back_refs() + for if_ref in if_ref_list: + if_obj = self.vnc.virtual_machine_interface_read( + id = if_ref['uuid']) + vn_name = if_obj.get_virtual_network_refs()[0]['to'][2] + list.append({'name':'%s:%s' %(vm_nova.name, vn_name), + 'uuid':if_ref['uuid'], 'obj':if_obj}) + return list + + def obj_get(self, name, vm_id = None): + list = self.obj_list(vm_id) + for item in list: + if (item['name'] == name): + return item['obj'] + + def prop_mac_show(self, obj): + print '[P] MAC addresses:' + mac = obj.get_virtual_machine_interface_mac_addresses() + if not mac: + return + for item in mac.get_mac_address(): + print ' %s' %(item) + + def prop_prop_show(self, obj): + prop = obj.get_virtual_machine_interface_properties() + if not prop: + return + print '[P] Service interface type: %s' \ + %(prop.get_service_interface_type()) + print '[P] Interface mirror: %s' %(prop.get_interface_mirror()) + + def ref_sg_show(self, obj): + print '[R] Security groups:' + refs = obj.get_security_group_refs() + if refs: + for item in obj.get_security_group_refs(): + print ' %s' %(item['to'][2]) + + def ref_net_show(self, obj): + print '[R] Virtual networks:' + for item in obj.get_virtual_network_refs(): + print ' %s' %(item['to'][2]) + + def ref_irt_show(self, obj): + print '[R] Interface route tables:' + list = obj.get_interface_route_table_refs() + if list: + for item in list: + print ' %s' %(item['to'][2]) + + def back_ref_ip_show(self, obj): + print '[BR] Instance IPs:' + list = obj.get_instance_ip_back_refs() + if not list: + return + for item in list: + ip = self.vnc.instance_ip_read(id = item['uuid']) + print ' %s' %(ip.get_instance_ip_address()) + + def back_ref_fip_show(self, obj): + print '[BR] Floating IPs:' + list = obj.get_floating_ip_back_refs() + if not list: + return + for item in list: + ip = self.vnc.floating_ip_read(id = item['uuid']) + print ' %s' %(ip.get_floating_ip_address()) + + def obj_show(self, obj, name): + print 'Virtual Machine Interface' + print 'Name: %s' %(name) + print 'UUID: %s' %(obj.uuid) + self.prop_mac_show(obj) + self.prop_prop_show(obj) + self.ref_sg_show(obj) + self.ref_net_show(obj) + self.ref_irt_show(obj) + self.back_ref_ip_show(obj) + self.back_ref_fip_show(obj) + + def show(self, name = None): + if name: + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + self.obj_show(obj, name) + else: + for item in self.obj_list(): + print ' %s' %(item['name']) + + def sg_add(self, obj, sg): + try: + sg_obj = self.vnc.security_group_read( + fq_name = ['default-domain', self.tenant.name, sg]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.add_security_group(sg_obj) + + def addr_add(self, obj, addr): + id = str(uuid.uuid4()) + ip_obj = vnc_api.InstanceIp(name = id, instance_ip_address = addr) + ip_obj.uuid = id + ip_obj.add_virtual_machine_interface(obj) + vn_id = obj.get_virtual_network_refs()[0]['uuid'] + vn_obj = self.vnc.virtual_network_read(id = vn_id) + ip_obj.add_virtual_network(vn_obj) + self.vnc.instance_ip_create(ip_obj) + + def irt_add(self, obj, irt): + try: + table_obj = self.vnc.interface_route_table_read( + fq_name = ['default-domain', self.tenant.name, irt]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.add_interface_route_table(table_obj) + + def fip_add(self, obj, fip_pool, fip): + pool_name = fip_pool.split(':') + pool_name.insert(0, 'default-domain') + try: + pool_obj = self.vnc.floating_ip_pool_read(fq_name = pool_name) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + id = str(uuid.uuid4()) + fip_obj = vnc_api.FloatingIp(name = id, parent_obj = pool_obj) + fip_obj.uuid = id + if (fip != 'any'): + fip_obj.set_floating_ip_address(fip) + fip_obj.add_project(self.tenant) + fip_obj.add_virtual_machine_interface(obj) + self.vnc.floating_ip_create(fip_obj) + self.tenant.add_floating_ip_pool(pool_obj) + self.vnc.project_update(self.tenant) + + def add(self, name, sg = None, irt = None, addr = None, + fip_pool = None, fip = None): + update = False + obj = self.obj_get(name) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + if sg: + self.sg_add(obj, sg) + update = True + if irt: + self.irt_add(obj, irt) + update = True + if addr: + self.addr_add(obj, addr) + update = True + if fip and fip_pool: + self.fip_add(obj, fip_pool, fip) + update = True + if update: + self.vnc.virtual_machine_interface_update(obj) + + def sg_del(self, obj, sg): + try: + sg_obj = self.vnc.security_group_read( + fq_name = ['default-domain', self.tenant.name, sg]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.del_security_group(sg_obj) + + def irt_del(self, obj, irt): + try: + table_obj = self.vnc.interface_route_table_read( + fq_name = ['default-domain', self.tenant.name, irt]) + except Exception as e: + print 'ERROR: %s' %(str(e)) + return + obj.del_interface_route_table(table_obj) + + def addr_del(self, obj, addr): + ip_list = obj.get_instance_ip_back_refs() + for ip in ip_list: + ip_obj = self.vnc.instance_ip_read(id = ip['uuid']) + if (ip_obj.get_instance_ip_address() == addr): + self.vnc.instance_ip_delete(id = ip_obj.uuid) + break + else: + print 'ERROR: IP address %s is not found!' %(addr) + + def fip_del(self, obj): + list = obj.get_floating_ip_back_refs() + if not list: + return + for item in list: + ip = self.vnc.floating_ip_delete(id = item['uuid']) + + def delete(self, name, sg = None, irt = None, addr = None, + fip = None, vm_id = None): + update = False + obj = self.obj_get(name, vm_id) + if not obj: + print 'ERROR: Object %s is not found!' %(name) + return + if sg: + self.sg_del(obj, sg) + update = True + if irt: + self.irt_del(obj, irt) + update = True + if addr: + self.addr_del(obj, addr) + update = True + if fip: + self.fip_del(obj) + update = True + if update: + self.vnc.virtual_machine_interface_update(obj) + + +class ConfigGlobalVrouter(): + def __init__(self, client): + self.vnc = client.vnc + self.tenant = client.tenant + + def obj_list(self): + list = self.vnc.interface_route_tables_list()['interface-route-tables'] + return list + + def obj_get(self, name): + obj = self.vnc.global_vrouter_config_read( + fq_name = ['default-global-system-config', + 'default-global-vrouter-config']) + return obj + + def obj_show(self, obj): + pass + + def show(self, name = None): + obj = self.obj_get('dummy') + print 'Link Local Service' + for item in obj.get_linklocal_services().get_linklocal_service_entry(): + print ' %s %s:%s %s:%s' %(item.get_linklocal_service_name(), + item.get_linklocal_service_ip(), + item.get_linklocal_service_port(), + item.get_ip_fabric_service_ip()[0], + item.get_ip_fabric_service_port()) + + def add(self, name, link_local_addr, fabric_addr): + obj = self.obj_get('dummy') + list = obj.get_linklocal_services().get_linklocal_service_entry() + list.append(vnc_api.LinklocalServiceEntryType( + linklocal_service_name = name, + linklocal_service_ip = link_local_addr.split(':')[0], + linklocal_service_port = int(link_local_addr.split(':')[1]), + ip_fabric_service_ip = [fabric_addr.split(':')[0]], + ip_fabric_service_port = int(fabric_addr.split(':')[1]))) + self.vnc.global_vrouter_config_update(obj) + + def delete(self, name): + obj = self.obj_get('dummy') + list = obj.get_linklocal_services().get_linklocal_service_entry() + for item in list: + if (item.get_linklocal_service_name() == name): + list.remove(item) + break + self.vnc.global_vrouter_config_update(obj) + +class ConfigClient(): + def __init__(self, username, password, tenant, region, api_server): + self.vnc = vnc_api.VncApi(username = username, password = password, + tenant_name = tenant, api_server_host = api_server) + if config_nova: + self.nova = novaclient.v1_1.client.Client(username = username, + api_key = password, project_id = tenant, + region_name = region, + auth_url = 'http://%s:35357/v2.0' %(api_server)) + else: + self.nova = None + self.tenant = self.vnc.project_read( + fq_name = ['default-domain', tenant]) + diff --git a/Testcases/config_shell.py b/Testcases/config_shell.py new file mode 100644 index 0000000..2fe5ad1 --- /dev/null +++ b/Testcases/config_shell.py @@ -0,0 +1,379 @@ + +from config_obj import * +import argparse + +class ConfigShell(): + + def __init__(self): + self.parser_init() + + def env(self, *args, **kwargs): + for arg in args: + value = os.environ.get(arg, None) + if value: + return value + return kwargs.get('default', '') + + def do_help(self, args): + if args.obj_parser: + args.obj_parser.print_help() + else: + self.parser.print_help() + + def parser_init(self): + parser = argparse.ArgumentParser() + parser.add_argument('--username', help = 'User name') + parser.add_argument('--password', help = 'Password') + parser.add_argument('--tenant', help = 'Tenant name') + parser.add_argument('--region', help = 'Region name') + parser.add_argument('--api-server', help = 'API server address') + + parser.add_argument('cmd', choices = ['add', 'show', 'delete', 'help'], + metavar = '<command>', help = '[ add | show | delete | help ]') + + subparsers = parser.add_subparsers(metavar = '<object>') + self.sub_cmd_dict = {} + + sub_parser = subparsers.add_parser('vdns', help = 'Virtual DNS') + sub_parser.set_defaults(obj_class = ConfigVirtualDns, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of virtual DNS') + sub_parser.add_argument('--domain-name', metavar = '<name>', + help = 'The name of DNS domain') + sub_parser.add_argument('--record-order', + choices = ['fixed', 'random', 'round-robin'], + default = 'random', metavar = '<order>', + help = 'The order of DNS records ' \ + '[ random | fixed | round-robin ]') + sub_parser.add_argument('--next-dns', metavar = '<name>', + help = 'The name of next virtual DNS service or ' \ + 'the IP address of DNS server reachable by fabric.') + + sub_parser = subparsers.add_parser('ipam', help = 'Network IPAM') + sub_parser.set_defaults(obj_class = ConfigIpam, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of IPAM') + sub_parser.add_argument('--dns-type', + choices = ['none', 'default', 'tenant', 'virtual'], + metavar = '<type>', + help = 'The type of DNS service ' \ + '[ none | default | virtual | tenant ]') + sub_parser.add_argument('--virtual-dns', metavar = '<name>', + help = 'The name of virtual DNS service') + sub_parser.add_argument('--tenant-dns', metavar = '<address>', + action = 'append', + help = 'The address of tenant DNS') + sub_parser.add_argument('--domain-name', metavar = '<name>', + help = 'The name of DNS domain') + sub_parser.add_argument('--ntp-server', metavar = '<address>', + help = 'The address of NTP server') + + sub_parser = subparsers.add_parser('policy', help = 'Network Policy') + sub_parser.set_defaults(obj_class = ConfigPolicy, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of policy') + sub_parser.add_argument('--rule', action = 'append', + metavar = '<arguments>', + help = 'Policy rule ' \ + 'direction=[ "<>" | ">" ],' \ + 'protocol=[ any | tcp | udp | icmp ],' \ + 'src-net=[ <name> | any ],' \ + 'dst-net=[ <name> | any ],' \ + 'src-port=[ <start>:<end> | any ],' \ + 'dst-port=[ <start>:<end> | any ],' \ + 'action=[ pass | deny | drop | reject | alert | ' \ + 'log | service ],' \ + 'service=<name>,' \ + 'index=<index>') + + sub_parser = subparsers.add_parser('security-group', + help = 'Security Group') + sub_parser.set_defaults(obj_class = ConfigSecurityGroup, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of security group') + sub_parser.add_argument('--rule', metavar = '<index>', + help = 'Rule index') + sub_parser.add_argument('--direction', + choices = ['ingress', 'egress'], + metavar = '<direction>', + help = 'Direction [ ingress | egress ]') + sub_parser.add_argument('--protocol', + choices = ['any', 'tcp', 'udp', 'icmp'], + metavar = '<protocol>', + help = 'Protocol [ any | tcp | udp | icmp ]') + sub_parser.add_argument('--address', action = 'append', + metavar = '<prefix>/<length>', help = 'Remote IP address') + sub_parser.add_argument('--port', action = 'append', type = str, + metavar = '<start>:<end>', help = 'The range of remote port') + + sub_parser = subparsers.add_parser('network', + help = 'Virtual Network') + sub_parser.set_defaults(obj_class = ConfigNetwork, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of virtual network') + sub_parser.add_argument('--ipam', metavar = '<name>', + help = 'The name of IPAM') + sub_parser.add_argument('--subnet', metavar = '<prefix>/<length>', + help = 'Subnet prefix and length') + sub_parser.add_argument('--gateway', metavar = '<address>', + help = 'The gateway address of subnet') + sub_parser.add_argument('--policy', metavar = '<name>', + help = 'The name of network policy') + sub_parser.add_argument('--route-target', metavar = '<AS>:<RT>', + help = 'Route target') + sub_parser.add_argument('--route-table', metavar = '<name>', + help = 'The name of route table') + sub_parser.add_argument('--l2', action = 'store_true', + help = 'Layer 2 network, layer 2&3 by default') + sub_parser.add_argument('--shared', action = 'store_true', + help = 'Enable sharing with other tenants') + sub_parser.add_argument('--external', action = 'store_true', + help = 'Enable external access') + + sub_parser = subparsers.add_parser('floating-ip-pool', + help = 'Floating IP Pool') + sub_parser.set_defaults(obj_class = ConfigFloatingIpPool, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of floating IP pool') + sub_parser.add_argument('--network', metavar = '<name>', + help = 'The name of virtual network holding floating IP pool') + #sub_parser.add_argument('--floating-ip', action = 'store_true', + # help = 'Floating IP') + + sub_parser = subparsers.add_parser('vm', + help = 'Virtual Machine') + sub_parser.set_defaults(obj_class = ConfigVirtualMachine, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of virtual machine') + sub_parser.add_argument('--image', metavar = '<name>', + help = 'The name of image') + sub_parser.add_argument('--flavor', metavar = '<name>', + help = 'The name of flavor') + sub_parser.add_argument('--network', action = 'append', + metavar = '<name>', + help = 'The name of network') + sub_parser.add_argument('--user-data', metavar = '<name>', + help = 'Full file name containing user data') + sub_parser.add_argument('--node', metavar = '<name>', + help = 'The name of compute node') + sub_parser.add_argument('--wait', action = 'store_true', + help = 'Wait till VM is active') + + sub_parser = subparsers.add_parser('interface-route-table', + help = 'Interface Route Table') + sub_parser.set_defaults(obj_class = ConfigInterfaceRouteTable, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of interface route table') + sub_parser.add_argument('--route', action = 'append', + metavar = '<prefix>/<length>', help = 'Route') + + sub_parser = subparsers.add_parser('route-table', + help = 'Network Route Table') + sub_parser.set_defaults(obj_class = ConfigRouteTable, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of route table') + sub_parser.add_argument('--route', action = 'append', + metavar = '<prefix>/<length>:<next-hop>', + help = 'The route and next-hop') + + sub_parser = subparsers.add_parser('vm-interface', + help = 'Virtual Machine Interface') + sub_parser.set_defaults(obj_class = ConfigVmInterface, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<VM>:<network>', + help = 'The name of virtual machine interface') + sub_parser.add_argument('--interface-route-table', metavar = '<name>', + help = 'The name of interface route table') + sub_parser.add_argument('--security-group', metavar = '<name>', + help = 'The name of security group') + sub_parser.add_argument('--address', + metavar = '<address>', + help = 'IP address') + sub_parser.add_argument('--floating-ip', + metavar = '<address>', + help = 'Floating IP address [ any | <address> ]') + sub_parser.add_argument('--floating-ip-pool', + metavar = '<pool>', + help = 'The floating IP pool to allocate a floating IP from ' \ + '<tenant>:<network>:<floating IP pool>') + + sub_parser = subparsers.add_parser('image', + help = 'Virtual Machine Image') + self.sub_cmd_dict['image'] = sub_parser + sub_parser.set_defaults(obj_class = ConfigImage) + sub_parser.add_argument('name', nargs = '?', default = None) + + sub_parser = subparsers.add_parser('flavor', + help = 'Virtual Machine Flavor') + self.sub_cmd_dict['flavor'] = sub_parser + sub_parser.set_defaults(obj_class = ConfigFlavor) + sub_parser.add_argument('name', nargs = '?', default = None) + + sub_parser = subparsers.add_parser('service-template', + help = 'Service Template') + sub_parser.set_defaults(obj_class = ConfigServiceTemplate, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of service template') + sub_parser.add_argument('--mode', + choices = ['transparent', 'in-network', 'in-network-nat'], + metavar = '<mode>', + help = 'Service mode ' \ + '[ transparent | in-network | in-network-nat ]') + sub_parser.add_argument('--type', + choices = ['firewall', 'analyzer'], + metavar = '<type>', + help = 'Service type [ firewall | analyzer ]') + sub_parser.add_argument('--image', metavar = '<name>', + help = 'The name of image') + sub_parser.add_argument('--flavor', metavar = '<name>', + help = 'The name of flavor') + sub_parser.add_argument('--scale', action = 'store_true', + help = 'Enable service scaling') + sub_parser.add_argument('--interface', + choices = ['management', 'left', 'right', 'other'], + metavar = '<type>', + action = 'append', + help = 'Service interface ' \ + '[ management | left | right | other ]') + + sub_parser = subparsers.add_parser('service-instance', + help = 'Service Instance') + sub_parser.set_defaults(obj_class = ConfigServiceInstance, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of service instance') + sub_parser.add_argument('--template', + metavar = '<template>', + help = 'Service template') + sub_parser.add_argument('--network', action = 'append', + metavar = '<arguments>', + help = 'network=[ <name> | auto ],tenant=<name>,' \ + 'route=<prefix>/<length> ' \ + 'The network order must be the same as interface ' \ + 'order defined in service template.') + sub_parser.add_argument('--scale-max', + metavar = '<number>', + help = 'The maximum number of instances') + sub_parser.add_argument('--auto-policy', action = 'store_true', + help = 'Enable automatic policy') + + sub_parser = subparsers.add_parser('link-local', + help = 'Link Local Service') + sub_parser.set_defaults(obj_class = ConfigGlobalVrouter, + obj_parser = sub_parser) + sub_parser.add_argument('name', nargs = '?', default = None, + metavar = '<name>', help = 'The name of link local service') + sub_parser.add_argument('--link-local-address', + metavar = '<address>', + help = 'Link Local service address and port ' \ + '<link local address>:<link local port>') + sub_parser.add_argument('--fabric-address', + metavar = '<address>', + help = 'Fabric address and port ' \ + '<fabric address>:<fabric port>') + self.parser = parser + + def parse(self, argv = None): + args = self.parser.parse_args(args = argv) + return args + + def run(self, args, client): + obj = args.obj_class(client = client) + if args.cmd == 'help': + self.do_help(args) + elif args.cmd == 'show': + obj.show(args.name) + elif args.cmd == 'add': + if (args.obj_class == ConfigVirtualDns): + obj.add(args.name, args.record_order, args.next_dns) + elif (args.obj_class == ConfigIpam): + obj.add(args.name, args.dns_type, args.virtual_dns, + args.tenant_dns, args.domain_name, args.ntp_server) + elif (args.obj_class == ConfigPolicy): + obj.add(args.name, args.rule) + elif (args.obj_class == ConfigSecurityGroup): + obj.add(args.name, args.protocol, args.address, args.port, + args.direction) + elif (args.obj_class == ConfigNetwork): + obj.add(args.name, args.ipam, args.subnet, args.policy, + args.route_target, args.route_table, args.shared, + args.external, args.l2) + elif (args.obj_class == ConfigFloatingIpPool): + obj.add(args.name, args.network) + elif (args.obj_class == ConfigServiceTemplate): + obj.add(args.name, args.mode, args.type, args.image, + args.flavor, args.interface) + elif (args.obj_class == ConfigServiceInstance): + obj.add(args.name, args.template, args.network, + args.auto_policy, args.scale_max) + elif (args.obj_class == ConfigVirtualMachine): + obj.add(args.name, args.image, args.flavor, args.network, + args.node, args.user_data, args.wait) + elif (args.obj_class == ConfigRouteTable): + obj.add(args.name, args.route) + elif (args.obj_class == ConfigInterfaceRouteTable): + obj.add(args.name, args.route) + elif (args.obj_class == ConfigVmInterface): + obj.add(args.name, args.security_group, + args.interface_route_table, args.address, + args.floating_ip_pool, args.floating_ip) + elif (args.obj_class == ConfigGlobalVrouter): + obj.add(args.name, args.link_local_address, + args.fabric_address) + elif args.cmd == 'delete': + if (args.obj_class == ConfigVirtualDns): + obj.delete(args.name) + elif (args.obj_class == ConfigIpam): + obj.delete(args.name, args.domain_name) + elif (args.obj_class == ConfigPolicy): + obj.delete(args.name, args.rule) + elif (args.obj_class == ConfigSecurityGroup): + obj.delete(args.name, args.rule) + elif (args.obj_class == ConfigNetwork): + obj.delete(args.name, args.ipam, args.policy, + args.route_target) + elif (args.obj_class == ConfigFloatingIpPool): + obj.delete(args.name, args.network) + elif (args.obj_class == ConfigServiceTemplate): + obj.delete(args.name) + elif (args.obj_class == ConfigServiceInstance): + obj.delete(args.name) + elif (args.obj_class == ConfigVirtualMachine): + obj.delete(args.name) + elif (args.obj_class == ConfigRouteTable): + obj.delete(args.name, args.route) + elif (args.obj_class == ConfigInterfaceRouteTable): + obj.delete(args.name, args.route) + elif (args.obj_class == ConfigVmInterface): + obj.delete(args.name, args.security_group, + args.interface_route_table, args.address, + args.floating_ip) + elif (args.obj_class == ConfigGlobalVrouter): + obj.delete(args.name) + else: + print 'Unknown action %s' %(args.cmd) + return + + def main(self): + args = self.parse() + #print args + #return + client = ConfigClient(args.username, args.password, args.tenant, + args.region, args.api_server) + self.run(args, client) + + +if __name__ == '__main__': + ConfigShell().main() + diff --git a/Testcases/configuration.md b/Testcases/configuration.md new file mode 100644 index 0000000..7ca3af2 --- /dev/null +++ b/Testcases/configuration.md @@ -0,0 +1,666 @@ + + + + +<!DOCTYPE html> +<html lang="en" class=""> + <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object# article: http://ogp.me/ns/article# profile: http://ogp.me/ns/profile#"> + <meta charset='utf-8'> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta http-equiv="Content-Language" content="en"> + <meta name="viewport" content="width=1020"> + + + <title>orch/configuration.md at master · tonyliu0592/orch · GitHub</title> + <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub"> + <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub"> + <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-114.png"> + <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114.png"> + <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-144.png"> + <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144.png"> + <meta property="fb:app_id" content="1401488693436528"> + + <meta content="@github" name="twitter:site" /><meta content="summary" name="twitter:card" /><meta content="tonyliu0592/orch" name="twitter:title" /><meta content="Contribute to orch development by creating an account on GitHub." name="twitter:description" /><meta content="https://avatars2.githubusercontent.com/u/5355193?v=3&s=400" name="twitter:image:src" /> + <meta content="GitHub" property="og:site_name" /><meta content="object" property="og:type" /><meta content="https://avatars2.githubusercontent.com/u/5355193?v=3&s=400" property="og:image" /><meta content="tonyliu0592/orch" property="og:title" /><meta content="https://github.com/tonyliu0592/orch" property="og:url" /><meta content="Contribute to orch development by creating an account on GitHub." property="og:description" /> + <meta name="browser-stats-url" content="https://api.github.com/_private/browser/stats"> + <meta name="browser-errors-url" content="https://api.github.com/_private/browser/errors"> + <link rel="assets" href="https://assets-cdn.github.com/"> + + <meta name="pjax-timeout" content="1000"> + + + <meta name="msapplication-TileImage" content="/windows-tile.png"> + <meta name="msapplication-TileColor" content="#ffffff"> + <meta name="selected-link" value="repo_source" data-pjax-transient> + + <meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU"> + <meta name="google-analytics" content="UA-3769691-2"> + +<meta content="collector.githubapp.com" name="octolytics-host" /><meta content="github" name="octolytics-app-id" /><meta content="4281F10B:71AA:2871CE6:56A1141C" name="octolytics-dimension-request_id" /> +<meta content="/<user-name>/<repo-name>/blob/show" data-pjax-transient="true" name="analytics-location" /> +<meta content="Rails, view, blob#show" data-pjax-transient="true" name="analytics-event" /> + + + <meta class="js-ga-set" name="dimension1" content="Logged Out"> + + + + <meta name="hostname" content="github.com"> + <meta name="user-login" content=""> + + <meta name="expected-hostname" content="github.com"> + + <link rel="mask-icon" href="https://assets-cdn.github.com/pinned-octocat.svg" color="#4078c0"> + <link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favicon.ico"> + + <meta content="57675af6296bdef5a5d3e30ee127f2b790b35ea2" name="form-nonce" /> + + <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/github-e64d783fc73cc815bb639b1ee740d83c08b1a72e2955dbd871b5971946f6f73d.css" media="all" rel="stylesheet" /> + <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/github2-1c37ca748821e6e6c34a8627476defabae0bedd9629ef3720c56ca5cc2fa93bb.css" media="all" rel="stylesheet" /> + + + + + <meta http-equiv="x-pjax-version" content="415d0d3a23070d855ffb28c07c6e43c4"> + + + <meta name="description" content="Contribute to orch development by creating an account on GitHub."> + <meta name="go-import" content="github.com/tonyliu0592/orch git https://github.com/tonyliu0592/orch.git"> + + <meta content="5355193" name="octolytics-dimension-user_id" /><meta content="tonyliu0592" name="octolytics-dimension-user_login" /><meta content="21293312" name="octolytics-dimension-repository_id" /><meta content="tonyliu0592/orch" name="octolytics-dimension-repository_nwo" /><meta content="true" name="octolytics-dimension-repository_public" /><meta content="false" name="octolytics-dimension-repository_is_fork" /><meta content="21293312" name="octolytics-dimension-repository_network_root_id" /><meta content="tonyliu0592/orch" name="octolytics-dimension-repository_network_root_nwo" /> + <link href="https://github.com/tonyliu0592/orch/commits/master.atom" rel="alternate" title="Recent Commits to orch:master" type="application/atom+xml"> + + + <link rel="canonical" href="https://github.com/tonyliu0592/orch/blob/master/doc/configuration.md" data-pjax-transient> + </head> + + + <body class="logged_out env-production vis-public page-blob"> + <a href="#start-of-content" tabindex="1" class="accessibility-aid js-skip-to-content">Skip to content</a> + + + + + + + + + <div class="header header-logged-out" role="banner"> + <div class="container clearfix"> + + <a class="header-logo-wordmark" href="https://github.com/" data-ga-click="(Logged out) Header, go to homepage, icon:logo-wordmark"> + <span aria-hidden="true" class="mega-octicon octicon-logo-github"></span> + </a> + + <div class="header-actions" role="navigation"> + <a class="btn btn-primary" href="/join" data-ga-click="(Logged out) Header, clicked Sign up, text:sign-up">Sign up</a> + <a class="btn" href="/login?return_to=%2Ftonyliu0592%2Forch%2Fblob%2Fmaster%2Fdoc%2Fconfiguration.md" data-ga-click="(Logged out) Header, clicked Sign in, text:sign-in">Sign in</a> + </div> + + <div class="site-search repo-scope js-site-search" role="search"> + <!-- </textarea> --><!-- '"` --><form accept-charset="UTF-8" action="/tonyliu0592/orch/search" class="js-site-search-form" data-global-search-url="/search" data-repo-search-url="/tonyliu0592/orch/search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div> + <label class="js-chromeless-input-container form-control"> + <div class="scope-badge">This repository</div> + <input type="text" + class="js-site-search-focus js-site-search-field is-clearable chromeless-input" + data-hotkey="s" + name="q" + placeholder="Search" + aria-label="Search this repository" + data-global-scope-placeholder="Search GitHub" + data-repo-scope-placeholder="Search" + tabindex="1" + autocapitalize="off"> + </label> +</form> + </div> + + <ul class="header-nav left" role="navigation"> + <li class="header-nav-item"> + <a class="header-nav-link" href="/explore" data-ga-click="(Logged out) Header, go to explore, text:explore">Explore</a> + </li> + <li class="header-nav-item"> + <a class="header-nav-link" href="/features" data-ga-click="(Logged out) Header, go to features, text:features">Features</a> + </li> + <li class="header-nav-item"> + <a class="header-nav-link" href="https://enterprise.github.com/" data-ga-click="(Logged out) Header, go to enterprise, text:enterprise">Enterprise</a> + </li> + <li class="header-nav-item"> + <a class="header-nav-link" href="/pricing" data-ga-click="(Logged out) Header, go to pricing, text:pricing">Pricing</a> + </li> + </ul> + + </div> +</div> + + + + <div id="start-of-content" class="accessibility-aid"></div> + + <div id="js-flash-container"> +</div> + + + <div role="main" class="main-content"> + <div itemscope itemtype="http://schema.org/WebPage"> + <div id="js-repo-pjax-container" class="context-loader-container js-repo-nav-next" data-pjax-container> + +<div class="pagehead repohead instapaper_ignore readability-menu experiment-repo-nav"> + <div class="container repohead-details-container"> + + + +<ul class="pagehead-actions"> + + <li> + <a href="/login?return_to=%2Ftonyliu0592%2Forch" + class="btn btn-sm btn-with-count tooltipped tooltipped-n" + aria-label="You must be signed in to watch a repository" rel="nofollow"> + <span aria-hidden="true" class="octicon octicon-eye"></span> + Watch + </a> + <a class="social-count" href="/tonyliu0592/orch/watchers"> + 6 + </a> + + </li> + + <li> + <a href="/login?return_to=%2Ftonyliu0592%2Forch" + class="btn btn-sm btn-with-count tooltipped tooltipped-n" + aria-label="You must be signed in to star a repository" rel="nofollow"> + <span aria-hidden="true" class="octicon octicon-star"></span> + Star + </a> + + <a class="social-count js-social-count" href="/tonyliu0592/orch/stargazers"> + 9 + </a> + + </li> + + <li> + <a href="/login?return_to=%2Ftonyliu0592%2Forch" + class="btn btn-sm btn-with-count tooltipped tooltipped-n" + aria-label="You must be signed in to fork a repository" rel="nofollow"> + <span aria-hidden="true" class="octicon octicon-repo-forked"></span> + Fork + </a> + + <a href="/tonyliu0592/orch/network" class="social-count"> + 5 + </a> + </li> +</ul> + + <h1 itemscope itemtype="http://data-vocabulary.org/Breadcrumb" class="entry-title public "> + <span aria-hidden="true" class="octicon octicon-repo"></span> + <span class="author"><a href="/tonyliu0592" class="url fn" itemprop="url" rel="author"><span itemprop="title">tonyliu0592</span></a></span><!-- +--><span class="path-divider">/</span><!-- +--><strong><a href="/tonyliu0592/orch" data-pjax="#js-repo-pjax-container">orch</a></strong> + + <span class="page-context-loader"> + <img alt="" height="16" src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif" width="16" /> + </span> + +</h1> + + </div> + <div class="container"> + +<nav class="reponav js-repo-nav js-sidenav-container-pjax js-octicon-loaders" + role="navigation" + data-pjax="#js-repo-pjax-container"> + + <a href="/tonyliu0592/orch" aria-label="Code" aria-selected="true" class="js-selected-navigation-item selected reponav-item" data-hotkey="g c" data-selected-links="repo_source repo_downloads repo_commits repo_releases repo_tags repo_branches /tonyliu0592/orch"> + <span aria-hidden="true" class="octicon octicon-code"></span> + Code +</a> + <a href="/tonyliu0592/orch/issues" class="js-selected-navigation-item reponav-item" data-hotkey="g i" data-selected-links="repo_issues repo_labels repo_milestones /tonyliu0592/orch/issues"> + <span aria-hidden="true" class="octicon octicon-issue-opened"></span> + Issues + <span class="counter">1</span> +</a> + <a href="/tonyliu0592/orch/pulls" class="js-selected-navigation-item reponav-item" data-hotkey="g p" data-selected-links="repo_pulls /tonyliu0592/orch/pulls"> + <span aria-hidden="true" class="octicon octicon-git-pull-request"></span> + Pull requests + <span class="counter">0</span> +</a> + <a href="/tonyliu0592/orch/wiki" class="js-selected-navigation-item reponav-item" data-hotkey="g w" data-selected-links="repo_wiki /tonyliu0592/orch/wiki"> + <span aria-hidden="true" class="octicon octicon-book"></span> + Wiki +</a> + <a href="/tonyliu0592/orch/pulse" class="js-selected-navigation-item reponav-item" data-selected-links="pulse /tonyliu0592/orch/pulse"> + <span aria-hidden="true" class="octicon octicon-pulse"></span> + Pulse +</a> + <a href="/tonyliu0592/orch/graphs" class="js-selected-navigation-item reponav-item" data-selected-links="repo_graphs repo_contributors /tonyliu0592/orch/graphs"> + <span aria-hidden="true" class="octicon octicon-graph"></span> + Graphs +</a> + +</nav> + + </div> +</div> + +<div class="container new-discussion-timeline experiment-repo-nav"> + <div class="repository-content"> + + + +<a href="/tonyliu0592/orch/blob/6cfa26b93dfefdd661a64dd7e9dc295c652dfb61/doc/configuration.md" class="hidden js-permalink-shortcut" data-hotkey="y">Permalink</a> + +<!-- blob contrib key: blob_contributors:v21:85a62aa7de00e6c17c4fabaa95e47968 --> + +<div class="file-navigation js-zeroclipboard-container"> + +<div class="select-menu js-menu-container js-select-menu left"> + <button class="btn btn-sm select-menu-button js-menu-target css-truncate" data-hotkey="w" + title="master" + type="button" aria-label="Switch branches or tags" tabindex="0" aria-haspopup="true"> + <i>Branch:</i> + <span class="js-select-button css-truncate-target">master</span> + </button> + + <div class="select-menu-modal-holder js-menu-content js-navigation-container" data-pjax aria-hidden="true"> + + <div class="select-menu-modal"> + <div class="select-menu-header"> + <span aria-label="Close" class="octicon octicon-x js-menu-close" role="button"></span> + <span class="select-menu-title">Switch branches/tags</span> + </div> + + <div class="select-menu-filters"> + <div class="select-menu-text-filter"> + <input type="text" aria-label="Filter branches/tags" id="context-commitish-filter-field" class="js-filterable-field js-navigation-enable" placeholder="Filter branches/tags"> + </div> + <div class="select-menu-tabs"> + <ul> + <li class="select-menu-tab"> + <a href="#" data-tab-filter="branches" data-filter-placeholder="Filter branches/tags" class="js-select-menu-tab" role="tab">Branches</a> + </li> + <li class="select-menu-tab"> + <a href="#" data-tab-filter="tags" data-filter-placeholder="Find a tag…" class="js-select-menu-tab" role="tab">Tags</a> + </li> + </ul> + </div> + </div> + + <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="branches" role="menu"> + + <div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring"> + + + <a class="select-menu-item js-navigation-item js-navigation-open selected" + href="/tonyliu0592/orch/blob/master/doc/configuration.md" + data-name="master" + data-skip-pjax="true" + rel="nofollow"> + <span aria-hidden="true" class="octicon octicon-check select-menu-item-icon"></span> + <span class="select-menu-item-text css-truncate-target" title="master"> + master + </span> + </a> + </div> + + <div class="select-menu-no-results">Nothing to show</div> + </div> + + <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="tags"> + <div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring"> + + + </div> + + <div class="select-menu-no-results">Nothing to show</div> + </div> + + </div> + </div> +</div> + + <div class="btn-group right"> + <a href="/tonyliu0592/orch/find/master" + class="js-show-file-finder btn btn-sm" + data-pjax + data-hotkey="t"> + Find file + </a> + <button aria-label="Copy file path to clipboard" class="js-zeroclipboard btn btn-sm zeroclipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="button">Copy path</button> + </div> + <div class="breadcrumb js-zeroclipboard-target"> + <span class="repo-root js-repo-root"><span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/tonyliu0592/orch" class="" data-branch="master" data-pjax="true" itemscope="url"><span itemprop="title">orch</span></a></span></span><span class="separator">/</span><span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/tonyliu0592/orch/tree/master/doc" class="" data-branch="master" data-pjax="true" itemscope="url"><span itemprop="title">doc</span></a></span><span class="separator">/</span><strong class="final-path">configuration.md</strong> + </div> +</div> + +<include-fragment class="commit-tease" src="/tonyliu0592/orch/contributors/master/doc/configuration.md"> + <div> + Fetching contributors… + </div> + + <div class="commit-tease-contributors"> + <img alt="" class="loader-loading left" height="16" src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32-EAF2F5.gif" width="16" /> + <span class="loader-error">Cannot retrieve contributors at this time</span> + </div> +</include-fragment> +<div class="file"> + <div class="file-header"> + <div class="file-actions"> + + <div class="btn-group"> + <a href="/tonyliu0592/orch/raw/master/doc/configuration.md" class="btn btn-sm " id="raw-url">Raw</a> + <a href="/tonyliu0592/orch/blame/master/doc/configuration.md" class="btn btn-sm js-update-url-with-hash">Blame</a> + <a href="/tonyliu0592/orch/commits/master/doc/configuration.md" class="btn btn-sm " rel="nofollow">History</a> + </div> + + + <button type="button" class="btn-octicon disabled tooltipped tooltipped-nw" + aria-label="You must be signed in to make or propose changes"> + <span aria-hidden="true" class="octicon octicon-pencil"></span> + </button> + <button type="button" class="btn-octicon btn-octicon-danger disabled tooltipped tooltipped-nw" + aria-label="You must be signed in to make or propose changes"> + <span aria-hidden="true" class="octicon octicon-trashcan"></span> + </button> + </div> + + <div class="file-info"> + 201 lines (153 sloc) + <span class="file-info-divider"></span> + 5.46 KB + </div> +</div> + + + <div id="readme" class="blob instapaper_body"> + <article class="markdown-body entry-content" itemprop="mainContentOfPage"><h1><a id="user-content-command-line-utility-to-configure-contrail" class="anchor" href="#command-line-utility-to-configure-contrail" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Command line utility to configure Contrail</h1> + +<h2><a id="user-content-files" class="anchor" href="#files" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Files</h2> + +<pre><code>config +config_shell.py +config_obj.py +</code></pre> + +<h2><a id="user-content-syntax" class="anchor" href="#syntax" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Syntax</h2> + +<pre><code>config [access options] <command> <object> [name] [options] + + access options: + Options to access API server of OpenStack and OpenContrail. + --username <user name> + --password <user password> + --region <region name> + --tenant <tenant name> + --api-server <API server IP address> + + <command> <object> [name] [options]: + + add vdns <name> + --domain-name <name> + --record-order [ random | fixed | round-robin ] + --next-dns <name> + + show vdns [name] + + delete vdns <name> + + add ipam <name> + --dns-type [ none | default | virtual | tenant ] + --virtual-dns <virtual DNS> + --tenant-dns <tenant DNS> + --domain-name <domain name> + --ntp-server <NTP server> + + show ipam [name] + + delete ipam <name> + + add policy <name> + --direction [ <> | > ] + --protocol [any | tcp | udp | icmp] + --src-net <source network> + --dst-net <destination network> + --src-port <start:end> + --dst-port <start:end> + --action [ pass | deny | drop | reject | alert | log | service ] + --service <service> + + show policy <name> + + delete policy <name> + --rule <rule index> + + add security-group <name> + --rule <rule index> + --direction [ ingress | egress ] + --protocol [any | tcp | udp | icmp] + --address <prefix/length> + --port <start:end> + + show security-group [name] + + delete security-group <name> + + add network <name> + --ipam <IPAM> + --subnet <prefix/length> + --gateway <gateway> + --policy <policy> + --route-target <route target> + --route-table <route table> + --l2 + + show network [name] + + delete network <name> + --policy <policy> + --route-target <route target> + --route-table <route table> + + add floating-ip-pool <network>:<pool> + + show floating-ip-pool [<network>:<pool>] + + delete floating-ip-pool <network>:<pool> + + add vm <name> + --image <image> + --flavor <flavor> + --network <network> + --node <node name> + --user-data <file name> + --wait + + show vm [name] + + delete vm <name> + + add interface-route-table <name> + --route <prefix/length> + + show interface-route-table [name] + + delete interface-route-table <name> + + add vm-interface <VM>:<network> + --interface-route-table <name> + --security-group <name> + --floating-ip-pool <tenant>:<network>:<pool> + --floating-ip any | <IP> + + show vm-interface <VM>:<network> + + delete vm-interface <VM>:<network> + --interface-route-table <name> + --security-group <name> + --floating-ip + + add route-table <name> + --route <prefix/length:next-hop> + + show route-table [name] + + delete route-table <name> + --route <prefix/length:next-hop> + + add service-template <name> + --mode [ transparent | in-network | in-network-nat ] + --type [ firewall | analyzer ] + --image <name> + --flavor <name> + --scale + --interface-type [ management | left | right | other ] + + show service-template [name] + + delete service-template <name> + + add service-instance <name> + --template <name> + --management-network <name> + --left-network <name> + --left-route <prefix/length> + --right-network <name> + --right-route <prefix/length> + --scale-max <number> + --auto-policy + + show service-instance [name] + + delete service-instance <name> + + add link-local <name> + --link-local-address <link local address>:<link local port> + --fabric-address '<fabric address>:<fabric port>' + + show link-local [name] + + delete link-local <name> + + show image + + show flavor +</code></pre> + +<h2><a id="user-content-examples" class="anchor" href="#examples" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Examples</h2> + +<h3><a id="user-content-allocate-floating-ip-to-vm-interface" class="anchor" href="#allocate-floating-ip-to-vm-interface" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Allocate floating IP to VM interface.</h3> + +<pre><code># config add ipam ipam-default +# config add policy policy-default +# config add network front-end --ipam ipam-default --subnet 192.168.1.0/24 --policy policy-default +# config add network back-end --ipam ipam-default --subnet 192.168.1.0/24 --policy policy-default +# config add vm server --image "CentOS 6.4 1-6" --flavor m1.small --network front-end +# config add vm database --image "CentOS 6.4 1-6" --flavor m1.small --network back-end +</code></pre> + +<h3><a id="user-content-allocate-floating-ip-to-vm-interface-1" class="anchor" href="#allocate-floating-ip-to-vm-interface-1" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Allocate floating IP to VM interface.</h3> + +<pre><code># config add network public --ipam ipam-default --sbunet 10.8.10.0/24 --route-target 64512:10000 +# config add floating-ip-pool public-pool --network public +# config add vm-interface server:front-end --floating-ip --floating-ip-pool public-pool +</code></pre> + +<h3><a id="user-content-create-layer-3-service-template-and-service-instance" class="anchor" href="#create-layer-3-service-template-and-service-instance" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Create layer-3 service template and service instance.</h3> + +<pre><code># config add service template vsrx-l3 --mode in-network --type firewall --image vsrx-12.1x47 --flavor m1.medium --interface-type management --interface-type left --interface-type right +# config add service-instance vsrx-l3 --template vsrx-l2 --management-network management --left-network front-end --right-network backend +# config add policy vsrx-l3 --src-net front-end --dst-net back-end --action service --service vsrx-l3 +# config add network front-end --policy vsrx-l3 +# config add network back-end --policy vsrx-l3 +</code></pre> + +<h3><a id="user-content-create-layer-2-service-template-and-service-instance" class="anchor" href="#create-layer-2-service-template-and-service-instance" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Create layer-2 service template and service instance.</h3> + +<pre><code># config add service template vsrx-l2 --mode transparent --type firewall --image vsrx-12.1x47 --flavor m1.medium --interface-type management --interface-type left --interface-type right +# config add service-instance vsrx-l2 --template vsrx-l2 --management-network management +</code></pre> +</article> + </div> + +</div> + +<a href="#jump-to-line" rel="facebox[.linejump]" data-hotkey="l" style="display:none">Jump to Line</a> +<div id="jump-to-line" style="display:none"> + <!-- </textarea> --><!-- '"` --><form accept-charset="UTF-8" action="" class="js-jump-to-line-form" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div> + <input class="linejump-input js-jump-to-line-field" type="text" placeholder="Jump to line…" aria-label="Jump to line" autofocus> + <button type="submit" class="btn">Go</button> +</form></div> + + </div> + <div class="modal-backdrop"></div> +</div> + + </div> + </div> + + </div> + + <div class="container"> + <div class="site-footer" role="contentinfo"> + <ul class="site-footer-links right"> + <li><a href="https://status.github.com/" data-ga-click="Footer, go to status, text:status">Status</a></li> + <li><a href="https://developer.github.com" data-ga-click="Footer, go to api, text:api">API</a></li> + <li><a href="https://training.github.com" data-ga-click="Footer, go to training, text:training">Training</a></li> + <li><a href="https://shop.github.com" data-ga-click="Footer, go to shop, text:shop">Shop</a></li> + <li><a href="https://github.com/blog" data-ga-click="Footer, go to blog, text:blog">Blog</a></li> + <li><a href="https://github.com/about" data-ga-click="Footer, go to about, text:about">About</a></li> + <li><a href="https://github.com/pricing" data-ga-click="Footer, go to pricing, text:pricing">Pricing</a></li> + + </ul> + + <a href="https://github.com" aria-label="Homepage"> + <span aria-hidden="true" class="mega-octicon octicon-mark-github" title="GitHub "></span> +</a> + <ul class="site-footer-links"> + <li>© 2016 <span title="0.04909s from github-fe122-cp1-prd.iad.github.net">GitHub</span>, Inc.</li> + <li><a href="https://github.com/site/terms" data-ga-click="Footer, go to terms, text:terms">Terms</a></li> + <li><a href="https://github.com/site/privacy" data-ga-click="Footer, go to privacy, text:privacy">Privacy</a></li> + <li><a href="https://github.com/security" data-ga-click="Footer, go to security, text:security">Security</a></li> + <li><a href="https://github.com/contact" data-ga-click="Footer, go to contact, text:contact">Contact</a></li> + <li><a href="https://help.github.com" data-ga-click="Footer, go to help, text:help">Help</a></li> + </ul> + </div> +</div> + + + + + + + + <div id="ajax-error-message" class="flash flash-error"> + <span aria-hidden="true" class="octicon octicon-alert"></span> + <button type="button" class="flash-close js-flash-close js-ajax-error-dismiss" aria-label="Dismiss error"> + <span aria-hidden="true" class="octicon octicon-x"></span> + </button> + Something went wrong with that request. Please try again. + </div> + + + <script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/compat-a0cee5d8d4fb535c0f41971d037b32e852a56ddca5bf67bb2124e426a2d813a5.js"></script> + <script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/frameworks-9ee55ceaf87fc34dc86334249fef6cbece88e815478e0fbe81642d57ed0fff89.js"></script> + <script async="async" crossorigin="anonymous" src="https://assets-cdn.github.com/assets/github-dd514695678bb0ae0bcd4387cff3b88a0c2e8def9cb3cdf8b1a888fb19979467.js"></script> + + + + <div class="js-stale-session-flash stale-session-flash flash flash-warn flash-banner hidden"> + <span aria-hidden="true" class="octicon octicon-alert"></span> + <span class="signed-in-tab-flash">You signed in with another tab or window. <a href="">Reload</a> to refresh your session.</span> + <span class="signed-out-tab-flash">You signed out in another tab or window. <a href="">Reload</a> to refresh your session.</span> + </div> + <div class="facebox" id="facebox" style="display:none;"> + <div class="facebox-popup"> + <div class="facebox-content" role="dialog" aria-labelledby="facebox-header" aria-describedby="facebox-description"> + </div> + <button type="button" class="facebox-close js-facebox-close" aria-label="Close modal"> + <span aria-hidden="true" class="octicon octicon-x"></span> + </button> + </div> +</div> + + </body> +</html> + |